gitlabhq/app/controllers/team_members_controller.rb

64 lines
1.7 KiB
Ruby
Raw Normal View History

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
@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)
@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
@user_project_relation = project.users_projects.new
2011-10-08 23:36:38 +02:00
end
def create
users = User.where(id: params[:user_ids])
@project.team << [users, params[:project_access]]
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
@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
unless @user_project_relation.valid?
flash[:alert] = "User should have at least one role"
2011-10-08 23:36:38 +02:00
end
redirect_to project_team_index_path(@project)
2011-10-08 23:36:38 +02:00
end
def destroy
@user_project_relation = project.users_projects.find_by_user_id(member)
@user_project_relation.destroy
2011-10-08 23:36:38 +02:00
respond_to do |format|
format.html { redirect_to project_team_index_path(@project) }
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])
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
protected
def member
@member ||= User.find_by_username(params[:id])
end
2011-10-08 23:36:38 +02:00
end