2012-09-27 20:59:42 +02:00
|
|
|
class TeamMembersController < ProjectResourceController
|
2011-10-08 23:36:38 +02:00
|
|
|
# Authorize
|
2011-10-17 12:39:03 +02:00
|
|
|
before_filter :authorize_read_project!
|
2012-09-16 16:56:32 +02:00
|
|
|
before_filter :authorize_admin_project!, except: [:index, :show]
|
|
|
|
|
|
|
|
def index
|
2013-02-18 20:10:49 +01:00
|
|
|
@team = @project.users_projects.scoped
|
|
|
|
@team = @team.send(params[:type]) if %w(masters developers reporters guests).include?(params[:type])
|
|
|
|
@team = @team.sort_by(&:project_access).reverse.group_by(&:project_access)
|
2013-02-18 20:21:24 +01:00
|
|
|
|
|
|
|
@assigned_teams = @project.user_team_project_relationships
|
2012-09-16 16:56:32 +02:00
|
|
|
end
|
2011-10-08 23:36:38 +02:00
|
|
|
|
|
|
|
def new
|
2013-01-22 18:20:39 +01:00
|
|
|
@user_project_relation = project.users_projects.new
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2013-01-04 07:43:25 +01:00
|
|
|
users = User.where(id: params[:user_ids])
|
|
|
|
|
|
|
|
@project.team << [users, params[:project_access]]
|
2012-09-07 08:50:35 +02:00
|
|
|
|
2012-11-29 18:14:05 +01:00
|
|
|
if params[:redirect_to]
|
|
|
|
redirect_to params[:redirect_to]
|
|
|
|
else
|
|
|
|
redirect_to project_team_index_path(@project)
|
|
|
|
end
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2013-01-22 18:20:39 +01:00
|
|
|
@user_project_relation = project.users_projects.find_by_user_id(member)
|
|
|
|
@user_project_relation.update_attributes(params[:team_member])
|
2011-10-08 23:36:38 +02:00
|
|
|
|
2013-01-22 18:20:39 +01:00
|
|
|
unless @user_project_relation.valid?
|
2011-12-07 00:27:07 +01:00
|
|
|
flash[:alert] = "User should have at least one role"
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
2012-09-16 15:21:20 +02:00
|
|
|
redirect_to project_team_index_path(@project)
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2013-01-25 19:34:49 +01:00
|
|
|
@user_project_relation = project.users_projects.find_by_user_id(member)
|
2013-01-22 18:20:39 +01:00
|
|
|
@user_project_relation.destroy
|
2011-10-08 23:36:38 +02:00
|
|
|
|
|
|
|
respond_to do |format|
|
2012-09-16 15:21:20 +02:00
|
|
|
format.html { redirect_to project_team_index_path(@project) }
|
2012-08-11 00:07:50 +02:00
|
|
|
format.js { render nothing: true }
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|
|
|
|
end
|
2012-10-24 13:20:53 +02:00
|
|
|
|
|
|
|
def apply_import
|
|
|
|
giver = Project.find(params[:source_project_id])
|
2013-01-04 07:43:25 +01:00
|
|
|
status = @project.team.import(giver)
|
2012-10-24 13:20:53 +02:00
|
|
|
notice = status ? "Succesfully imported" : "Import failed"
|
|
|
|
|
|
|
|
redirect_to project_team_members_path(project), notice: notice
|
|
|
|
end
|
2013-01-22 18:20:39 +01:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def member
|
2013-01-25 19:34:49 +01:00
|
|
|
@member ||= User.find_by_username(params[:id])
|
2013-01-22 18:20:39 +01:00
|
|
|
end
|
2011-10-08 23:36:38 +02:00
|
|
|
end
|