2018-09-26 03:45:43 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-03-11 17:37:46 +00:00
|
|
|
class Projects::GroupLinksController < Projects::ApplicationController
|
|
|
|
layout 'project_settings'
|
|
|
|
before_action :authorize_admin_project!
|
2016-10-04 13:40:03 +00:00
|
|
|
before_action :authorize_admin_project_member!, only: [:update]
|
2016-03-11 17:37:46 +00:00
|
|
|
|
2020-10-08 18:08:32 +00:00
|
|
|
feature_category :subgroups
|
|
|
|
|
2016-03-11 17:37:46 +00:00
|
|
|
def create
|
2016-09-01 17:23:39 +00:00
|
|
|
group = Group.find(params[:link_group_id]) if params[:link_group_id].present?
|
|
|
|
|
|
|
|
if group
|
2019-02-12 12:29:47 +00:00
|
|
|
result = Projects::GroupLinks::CreateService.new(project, current_user, group_link_create_params).execute(group)
|
|
|
|
return render_404 if result[:http_status] == 404
|
2017-11-14 09:02:39 +00:00
|
|
|
|
2019-02-12 12:29:47 +00:00
|
|
|
flash[:alert] = result[:message] if result[:http_status] == 409
|
2016-09-01 17:23:39 +00:00
|
|
|
else
|
2019-03-27 16:52:52 +00:00
|
|
|
flash[:alert] = _('Please select a group.')
|
2016-09-01 17:23:39 +00:00
|
|
|
end
|
2016-03-11 17:37:46 +00:00
|
|
|
|
2017-07-07 14:40:41 +00:00
|
|
|
redirect_to project_project_members_path(project)
|
2016-03-11 17:37:46 +00:00
|
|
|
end
|
|
|
|
|
2016-09-01 12:48:20 +00:00
|
|
|
def update
|
2020-09-30 12:09:53 +00:00
|
|
|
group_link = @project.project_group_links.find(params[:id])
|
|
|
|
Projects::GroupLinks::UpdateService.new(group_link).execute(group_link_params)
|
|
|
|
|
|
|
|
if group_link.expires?
|
|
|
|
render json: {
|
|
|
|
expires_in: helpers.distance_of_time_in_words_to_now(group_link.expires_at),
|
|
|
|
expires_soon: group_link.expires_soon?
|
|
|
|
}
|
|
|
|
else
|
|
|
|
render json: {}
|
|
|
|
end
|
2016-09-01 12:48:20 +00:00
|
|
|
end
|
|
|
|
|
2016-03-11 17:37:46 +00:00
|
|
|
def destroy
|
2017-11-01 14:08:18 +00:00
|
|
|
group_link = project.project_group_links.find(params[:id])
|
|
|
|
|
|
|
|
::Projects::GroupLinks::DestroyService.new(project, current_user).execute(group_link)
|
2016-03-11 17:37:46 +00:00
|
|
|
|
2016-09-06 15:20:20 +00:00
|
|
|
respond_to do |format|
|
|
|
|
format.html do
|
2018-07-02 10:43:06 +00:00
|
|
|
redirect_to project_project_members_path(project), status: :found
|
2016-09-06 15:20:20 +00:00
|
|
|
end
|
|
|
|
format.js { head :ok }
|
|
|
|
end
|
2016-03-11 17:37:46 +00:00
|
|
|
end
|
2016-09-01 12:48:20 +00:00
|
|
|
|
|
|
|
protected
|
|
|
|
|
|
|
|
def group_link_params
|
|
|
|
params.require(:group_link).permit(:group_access, :expires_at)
|
|
|
|
end
|
2017-11-01 14:08:18 +00:00
|
|
|
|
|
|
|
def group_link_create_params
|
|
|
|
params.permit(:link_group_access, :expires_at)
|
|
|
|
end
|
2016-03-11 17:37:46 +00:00
|
|
|
end
|
2019-09-13 13:26:31 +00:00
|
|
|
|
|
|
|
Projects::GroupLinksController.prepend_if_ee('EE::Projects::GroupLinksController')
|