<commit_before>require 'securerandom'
class TeamController < ApplicationController

    def new

    end

    def create
        #Expand to allow more than 1 user being invited
        user = User.where(email: params[:email])
        course = Course.find_by_id(params[:course_id])
        if !user.first.nil? && !course.nil?
            user = user.first
            #Add a notification to the user
            makeNotification(user.id,"You have been invited by #{current_user.name} to join the team #{params[:tname]} for #{course.name} course!")
            #create a new Team
            team = Team.new
            team.name = params[:tname]
            team.status = 0.00
            team.course_id = course.id
            team.acceptedInvites = 1
            team.save
            current_user.team_ids << team.id
            current_user.save
            user.team_ids << team.id
            user.save
            team.save
            flash[:notice] = "#{user.name} has been invited to join the team. The course will begin when he accepts!"
        else
            flash[:notice] = "The user you want to add doesn't exist. Please ask him to join the site first!"
        end
        redirect_to(controller: "home",action: "index")
    end

    def acceptInvite

        course = Course.find(params[:course_id])

        if course
            team = current_user.teams.find_by_course_id(course.id)
            if team
                team.acceptedInvites+=1
                if team.acceptedInvites == course.mcount<commit_msg>Cleaned up a bit and made couses and teams dynamic<commit_after>require 'securerandom'
class TeamController < ApplicationController

    def new

    end

    def create
        #Expand to allow more than 1 user being invited
        user = User.where(email: params[:email])
        course = Course.find_by_id(params[:course_id])
        if !user.first.nil? && !course.nil?
            user = user.first
            #Add a notification to the user
            makeNotification(user.id,"You have been invited by #{current_user.name} to join the team #{params[:tname]} for #{course.name} course!","Tinvite","/acceptInvite?course_id=#{course.id}")
            #create a new Team
            team = Team.new
            team.name = params[:tname]
            team.status = 0.00
            team.course_id = course.id
            team.acceptedInvites = 1
            team.save
            current_user.team_ids << team.id
            current_user.save
            user.team_ids << team.id
            user.save
            team.save
            flash[:notice] = "#{user.name} has been invited to join the team. The course will begin when he accepts!"
        else
            flash[:notice] = "The user you want to add doesn't exist. Please ask him to join the site first!"
        end
        redirect_to(controller: "home",action: "index")
    end

    def acceptInvite

        course = Course.find(params[:course_id])

        if course
            team = current_user.teams.find_by_course_id(course.id)
            if team
                team.acceptedInvites+=1
                if team.acceptedInvites == course.mcount
{'fraction_non_alphanumeric': 0.08851522842639593, 'fraction_numerical': 0.0038071065989847717, 'mean_word_length': 1.9302973977695168, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2132750', 'n_tokens_mistral': 870, 'n_tokens_neox': 840, 'n_words': 256}