projects_controller.rb 1.11 KB
Newer Older
1 2
class Teams::ProjectsController < Teams::ApplicationController
  def create
3 4 5 6 7 8 9
    redirect_to :back if params[:project_ids].blank?

    project_ids = params[:project_ids]
    access = params[:greatest_project_access]

    # Reject non-allowed projects
    allowed_project_ids = current_user.owned_projects.map(&:id)
10
    project_ids.select! { |id| allowed_project_ids.include?(id.to_i) }
11 12 13

    # Assign projects to team
    user_team.assign_to_projects(project_ids, access)
14

Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
15
    redirect_to edit_team_path(user_team), notice: 'Team of users was successfully assigned to projects.'
16 17 18
  end

  def edit
19
    team_project
20 21 22
  end

  def update
23
    if user_team.update_project_access(team_project, params[:greatest_project_access])
Dmitriy Zaporozhets's avatar
Dmitriy Zaporozhets committed
24
      redirect_to edit_team_path(user_team), notice: 'Access was successfully updated.'
25 26 27
    else
      render :edit
    end
28 29 30
  end

  def destroy
31
    user_team.resign_from_project(team_project)
32
    redirect_to team_projects_path(user_team), notice: 'Team of users was successfully reassigned from project.'
33
  end
34 35 36 37

  private

  def team_project
38
    @project ||= user_team.projects.find_with_namespace(params[:id])
39
  end
40
end