2013-01-19 18:48:05 +01:00
|
|
|
class Teams::ProjectsController < Teams::ApplicationController
|
2013-01-22 21:58:44 +01:00
|
|
|
|
|
|
|
skip_before_filter :authorize_manage_user_team!, only: [:index]
|
|
|
|
|
2013-01-19 18:48:05 +01:00
|
|
|
def index
|
2013-01-22 18:21:07 +01:00
|
|
|
@projects = user_team.projects
|
2013-01-24 19:19:18 +01:00
|
|
|
@avaliable_projects = current_user.admin? ? Project.without_team(user_team) : current_user.owned_projects.without_team(user_team)
|
2013-01-19 18:48:05 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2013-01-22 23:20:27 +01:00
|
|
|
user_team
|
2013-01-24 13:10:17 +01:00
|
|
|
@avaliable_projects = current_user.owned_projects.scoped
|
2013-01-22 23:20:27 +01:00
|
|
|
@avaliable_projects = @avaliable_projects.without_team(user_team) if user_team.projects.any?
|
|
|
|
|
|
|
|
redirect_to team_projects_path(user_team), notice: "No avalible projects." unless @avaliable_projects.any?
|
2013-01-19 18:48:05 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2013-01-24 13:15:14 +01:00
|
|
|
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)
|
2013-01-25 12:56:04 +01:00
|
|
|
project_ids.select! { |id| allowed_project_ids.include?(id.to_i) }
|
2013-01-24 13:15:14 +01:00
|
|
|
|
|
|
|
# Assign projects to team
|
|
|
|
user_team.assign_to_projects(project_ids, access)
|
2013-01-22 18:21:07 +01:00
|
|
|
|
2013-01-24 13:15:14 +01:00
|
|
|
redirect_to team_projects_path(user_team), notice: 'Team of users was successfully assigned to projects.'
|
2013-01-19 18:48:05 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2013-01-22 18:29:19 +01:00
|
|
|
team_project
|
2013-01-19 18:48:05 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2013-01-22 18:29:19 +01:00
|
|
|
if user_team.update_project_access(team_project, params[:greatest_project_access])
|
2013-01-22 23:20:27 +01:00
|
|
|
redirect_to team_projects_path(user_team), notice: 'Access was successfully updated.'
|
2013-01-22 18:21:07 +01:00
|
|
|
else
|
|
|
|
render :edit
|
|
|
|
end
|
2013-01-19 18:48:05 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2013-01-22 18:29:19 +01:00
|
|
|
user_team.resign_from_project(team_project)
|
2013-01-22 23:20:27 +01:00
|
|
|
redirect_to team_projects_path(user_team), notice: 'Team of users was successfully reassigned from project.'
|
2013-01-19 18:48:05 +01:00
|
|
|
end
|
2013-01-22 18:29:19 +01:00
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def team_project
|
2013-01-22 23:20:27 +01:00
|
|
|
@project ||= user_team.projects.find_with_namespace(params[:id])
|
2013-01-22 18:29:19 +01:00
|
|
|
end
|
|
|
|
|
2013-01-19 18:48:05 +01:00
|
|
|
end
|