2015-04-26 12:48:37 +05:30
|
|
|
class Projects::ProjectMembersController < Projects::ApplicationController
|
2016-06-16 23:09:34 +05:30
|
|
|
include MembershipActions
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
# Authorize
|
2016-06-16 23:09:34 +05:30
|
|
|
before_action :authorize_admin_project_member!, except: [:index, :leave, :request_access]
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
def index
|
|
|
|
@project_members = @project.project_members
|
2016-08-24 12:49:21 +05:30
|
|
|
@project_members = @project_members.non_invite unless can?(current_user, :admin_project, @project)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
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
|
2016-06-16 23:09:34 +05:30
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
if @group
|
|
|
|
@group_members = @group.group_members
|
2016-08-24 12:49:21 +05:30
|
|
|
@group_members = @group_members.non_invite unless can?(current_user, :admin_group, @group)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
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-12-23 02:04:40 +05:30
|
|
|
@group_members = @group_members.order('access_level DESC')
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
@requesters = @project.requesters if can?(current_user, :admin_project, @project)
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
@project_member = @project.project_members.new
|
2016-06-02 11:05:42 +05:30
|
|
|
@project_group_links = @project.project_group_links
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2016-09-13 17:45:13 +05:30
|
|
|
@project.team.add_users(
|
|
|
|
params[:user_ids].split(','),
|
|
|
|
params[:access_level],
|
|
|
|
expires_at: params[:expires_at],
|
|
|
|
current_user: current_user
|
|
|
|
)
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
redirect_to namespace_project_project_members_path(@project.namespace, @project)
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
@project_member = @project.project_members.find(params[:id])
|
2015-11-26 14:37:03 +05:30
|
|
|
|
|
|
|
return render_403 unless can?(current_user, :update_project_member, @project_member)
|
|
|
|
|
2015-04-26 12:48:37 +05:30
|
|
|
@project_member.update_attributes(member_params)
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
2016-08-24 12:49:21 +05:30
|
|
|
@project_member = @project.members.find_by(id: params[:id]) ||
|
|
|
|
@project.requesters.find_by(id: params[:id])
|
2015-11-26 14:37:03 +05:30
|
|
|
|
2016-08-24 12:49:21 +05:30
|
|
|
Members::DestroyService.new(@project_member, current_user).execute
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
|
|
|
redirect_to namespace_project_project_members_path(@project.namespace, @project)
|
|
|
|
end
|
2016-06-02 11:05:42 +05:30
|
|
|
format.js { head :ok }
|
2015-04-26 12:48:37 +05:30
|
|
|
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 apply_import
|
2016-06-02 11:05:42 +05:30
|
|
|
source_project = Project.find(params[:source_project_id])
|
|
|
|
|
|
|
|
if can?(current_user, :read_project_member, source_project)
|
|
|
|
status = @project.team.import(source_project, current_user)
|
|
|
|
notice = status ? "Successfully imported" : "Import failed"
|
|
|
|
else
|
|
|
|
return render_404
|
|
|
|
end
|
2015-04-26 12:48:37 +05:30
|
|
|
|
|
|
|
redirect_to(namespace_project_project_members_path(project.namespace, project),
|
|
|
|
notice: notice)
|
|
|
|
end
|
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def member_params
|
2016-09-13 17:45:13 +05:30
|
|
|
params.require(:project_member).permit(:user_id, :access_level, :expires_at)
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|
2016-06-16 23:09:34 +05:30
|
|
|
|
|
|
|
# MembershipActions concern
|
|
|
|
alias_method :membershipable, :project
|
2015-04-26 12:48:37 +05:30
|
|
|
end
|