debian-mirror-gitlab/app/controllers/projects/project_members_controller.rb

102 lines
3 KiB
Ruby
Raw Normal View History

2015-04-26 12:48:37 +05:30
class Projects::ProjectMembersController < Projects::ApplicationController
# Authorize
2015-09-11 14:41:01 +05:30
before_action :authorize_admin_project!, except: :leave
2015-04-26 12:48:37 +05:30
def index
@project_members = @project.project_members
@project_members = @project_members.non_invite unless can?(current_user, :admin_project, @project)
if params[:search].present?
users = @project.users.search(params[:search]).to_a
@project_members = @project_members.where(user_id: users)
end
@project_members = @project_members.order('access_level DESC')
@group = @project.group
if @group
@group_members = @group.group_members
@group_members = @group_members.non_invite unless can?(current_user, :admin_group, @group)
if params[:search].present?
users = @group.users.search(params[:search]).to_a
@group_members = @group_members.where(user_id: users)
end
2015-09-11 14:41:01 +05:30
2015-04-26 12:48:37 +05:30
@group_members = @group_members.order('access_level DESC').limit(20)
end
@project_member = @project.project_members.new
end
def new
@project_member = @project.project_members.new
end
def create
@project.team.add_users(params[:user_ids].split(','), params[:access_level], current_user)
redirect_to namespace_project_project_members_path(@project.namespace, @project)
end
def update
@project_member = @project.project_members.find(params[:id])
@project_member.update_attributes(member_params)
end
def destroy
@project_member = @project.project_members.find(params[:id])
@project_member.destroy
respond_to do |format|
format.html do
redirect_to namespace_project_project_members_path(@project.namespace, @project)
end
format.js { render nothing: true }
end
end
def resend_invite
redirect_path = namespace_project_project_members_path(@project.namespace, @project)
@project_member = @project.project_members.find(params[:id])
2015-09-11 14:41:01 +05:30
2015-04-26 12:48:37 +05:30
if @project_member.invite?
@project_member.resend_invite
redirect_to redirect_path, notice: 'The invitation was successfully resent.'
else
redirect_to redirect_path, alert: 'The invitation has already been accepted.'
end
end
def leave
2015-09-11 14:41:01 +05:30
if @project.namespace == current_user.namespace
2015-10-24 18:46:33 +05:30
message = 'You can not leave your own project. Transfer or delete the project.'
return redirect_back_or_default(default: { action: 'index' }, options: { alert: message })
2015-09-11 14:41:01 +05:30
end
2015-04-26 12:48:37 +05:30
@project.project_members.find_by(user_id: current_user).destroy
respond_to do |format|
2015-09-25 12:07:36 +05:30
format.html { redirect_to dashboard_projects_path }
2015-04-26 12:48:37 +05:30
format.js { render nothing: true }
end
end
def apply_import
giver = Project.find(params[:source_project_id])
status = @project.team.import(giver, current_user)
notice = status ? "Successfully imported" : "Import failed"
redirect_to(namespace_project_project_members_path(project.namespace, project),
notice: notice)
end
protected
def member_params
params.require(:project_member).permit(:user_id, :access_level)
end
end