<commit_before>module LatoSwpmanager
  class Back::ProjectsController < Back::BackController

    before_action do
      view_setCurrentVoice('swpmanager_projects')
    end

    def index
      # check user is admin
      redirect_to lato_core.root_path and return false unless @superuser_admin
      # find correct projects for user
      if @superuser_superadmin
        @projects = Project.all.paginate(page: params[:page], per_page: 20).order('title ASC')
      else
        @projects = Project.where(superuser_creator_id: @superuser.id).paginate(page: params[:page], per_page: 20).order('title ASC')
      end
    end

    def new
      # check user is admin
      redirect_to lato_core.root_path and return false unless @superuser_admin
      # generate new project
      @project = Project.new
      fetch_external_objects
    end

    def create
      # check user is admin
      redirect_to lato_core.root_path and return false unless @superuser_admin
      # generate project
      project = Project.new(project_params)
      # save superuser creator
      project.superuser_creator_id = @superuser.id
      #  save project
      if project.save
        flash[:success] = "Project created"
        redirect_to lato_swpmanager.project_path(project.id)
      else
        flash[:danger] = "Project not created"
        redirect_to lato_swpmanager.projects_path
      end
    end

    def show
      @project = Project.find(params[:id])
      @tasks = @project.tasks

      if !@superuser_admin && !(@superuser_collaborator.projects.include? @project)
        redirect_to lato_core.root_path and return false
      end
    end

    def edit
      redirect_to lato_core.root_path and return false unless @superuser_admin

      @project = Project.find(params[:id])
      fetch_external_objects
    end

    def update
      redirect_to lato_core.root_path and return false unless @superuser_admin

      project = Project.find(params[:id])

      if project.update(project_params)
        flash[:success] = "Project updated"
      else
        flash[:danger] = "Project not updated"
      end

      redirect_to lato_swpmanager.project_path
    end

    def destroy
      redirect_to lato_core.root_path and return false unless @superuser_admin

      project = Project.find(params[:id])

      project.destroy

      flash[:success] = "Project deleted"
      redirect_to lato_swpmanager.projects_path
    end

    def tasks
      redirect_to lato_core.root_path and return false unless @superuser_admin

      @project = Project.find(params[:id])

      @tasks = Task.where(project_id: @project.id).order('end_date ASC')

      @deadline_tasks = @tasks.where('end_date <= ?', Date.today + 1).where.not(status: 'completed')
      @wait_tasks = @tasks.where(status: 'wait')
      @develop_tasks = @tasks.where(status: 'develop')
      @test_tasks = @tasks.where(status: 'test')
      @completed_tasks = @tasks.where(status: 'completed')

      if params[:task_id]
        @task = Task.find(params[:task_id])
      else
        @task = Task.new
      end

      if params[:init_date]
        @init_date = params[:init_date].to_date
        @end_date = @init_date + 6
      else
        @init_date = Date.yesterday
        @end_date = @init_date + 6
      end
    end

    def stats
      redirect_to lato_core.root_path and return false unless @superuser_admin

      @project = Project.find(params[:id])

      @tasks = Task.where(project_id: @project.id).order('end_date ASC')
      @wait_tasks = @tasks.where(status: 'wait')
      @develop_tasks = @tasks.where(status: 'develop')
      @test_tasks = @tasks.where(status: 'test')
      @completed_tasks = @tasks.where(status: 'completed')
      @collaborators = @project.collaborators
    end

    private def fetch_external_objects
      @clients = false
      @collaborators = Collaborator.all
      @superusers = LatoCore::Superuser.where('permission >= ?', swpmanager_getCollaboratorAdminSuperuserPermission)
    end

  end
end
<commit_msg>auto-commit<commit_after>module LatoSwpmanager
  class Back::ProjectsController < Back::BackController

    before_action do
      view_setCurrentVoice('swpmanager_projects')
    end

    def index
      # check user is admin
      redirect_to lato_core.root_path and return false unless @superuser_admin
      # find correct projects for user
      if @superuser_superadmin
        @projects = Project.all.paginate(page: params[:page], per_page: 20).order('title ASC')
      else
        @projects = Project.where(superuser_creator_id: @superuser.id).paginate(page: params[:page], per_page: 20).order('title ASC')
      end
    end

    def new
      # check user is admin
      redirect_to lato_core.root_path and return false unless @superuser_admin
      # generate new project
      @project = Project.new
      fetch_external_objects
    end

    def create
      # check user is admin
      redirect_to lato_core.root_path and return false unless @superuser_admin
      # generate project
      project = Project.new(project_params)
      # save superuser creator
      project.superuser_creator_id = @superuser.id
      #  save project
      if project.save
        flash[:success] = "Project created"
        redirect_to lato_swpmanager.project_path(project.id)
      else
        flash[:danger] = "Project not created"
        redirect_to lato_swpmanager.projects_path
      end
    end

    def show
      @project = Project.find(params[:id])
      @tasks = @project.tasks
      # check user is collaborator of project
      if (!@superuser_admin && !(@superuser_collaborator.projects.include? @project))
        redirect_to lato_core.root_path and return false
      end
      # check user is manager of project
      if (@superuser_admin && !(@project.superuser_manager_id === @superuser.id))
        redirect_to lato_core.root_path and return false
      end
    end

    def edit
      # check user is admin
      redirect_to lato_core.root_path and return false unless @superuser_admin
      # find project
      @project = Project.find(params[:id])
      # check user is manager of project
      if (@superuser_admin && !(@project.superuser_manager_id === @superuser.id))
        redirect_to lato_core.root_path and return false
      end
      # fetch external object
      fetch_external_objects
    end

    def update
      # check user is admin
      redirect_to lato_core.root_path and return false unless @superuser_admin
      # find project
      project = Project.find(params[:id])
      # check user is manager of project
      if (@superuser_admin && !(project.superuser_manager_id === @superuser.id))
        redirect_to lato_core.root_path and return false
      end
      # exec update
      if project.update(project_params)
        flash[:success] = "Project updated"
      else
        flash[:danger] = "Project not updated"
      end

      redirect_to lato_swpmanager.project_path
    end

    def destroy
      # check superuser is admin
      redirect_to lato_core.root_path and return false unless @superuser_admin
      # find project
      project = Project.find(params[:id])
      # check user is manager of project
      if (@superuser_admin && !(project.superuser_manager_id === @superuser.id))
        redirect_to lato_core.root_path and return false
      end
      # destroy project
      project.destroy

      flash[:success] = "Project deleted"
      redirect_to lato_swpmanager.projects_path
    end

    def tasks
      # check superuser is admin
      redirect_to lato_core.root_path and return false unless @superuser_admin
      # find project
      @project = Project.find(params[:id])
      # check user is manager of project
      if (@superuser_admin && !(@project.superuser_manager_id === @superuser.id))
        redirect_to lato_core.root_path and return false
      end
      # find datas
      @tasks = Task.where(project_id: @project.id).order('end_date ASC')
      @deadline_tasks = @tasks.where('end_date <= ?', Date.today + 1).where.not(status: 'completed')
      @wait_tasks = @tasks.where(status: 'wait')
      @develop_tasks = @tasks.where(status: 'develop')
      @test_tasks = @tasks.where(status: 'test')
      @completed_tasks = @tasks.where(status: 'completed')
      # prepare datas for form
      if params[:task_id]
        @task = Task.find(params[:task_id])
      else
        @task = Task.new
      end
      # prepare datas for timeline
      if params[:init_date]
        @init_date = params[:init_date].to_date
        @end_date = @init_date + 6
      else
        @init_date = Date.yesterday
        @end_date = @init_date + 6
      end
    end

    def stats
      # check user is admin
      redirect_to lato_core.root_path and return false unless @superuser_admin
      # find project
      @project = Project.find(params[:id])
      # check user is manager of project
      if (@superuser_admin && !(@project.superuser_manager_id === @superuser.id))
        redirect_to lato_core.root_path and return false
      end
      # find datas
      @tasks = Task.where(project_id: @project.id).order('end_date ASC')
      @wait_tasks = @tasks.where(status: 'wait')
      @develop_tasks = @tasks.where(status: 'develop')
      @test_tasks = @tasks.where(status: 'test')
      @completed_tasks = @tasks.where(status: 'completed')
      @collaborators = @project.collaborators
    end

    private def fetch_external_objects
      @clients = false
      @collaborators = Collaborator.all
      @superusers = LatoCore::Superuser.where('permission >= ?', swpmanager_getCollaboratorAdminSuperuserPermission)
    end

  end
end

{'fraction_non_alphanumeric': 0.08902540608079966, 'fraction_numerical': 0.0014577259475218659, 'mean_word_length': 2.8358626198083066, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '7057247', 'n_tokens_mistral': 2873, 'n_tokens_neox': 2786, 'n_words': 703}