debian-mirror-gitlab/app/services/projects/group_links/create_service.rb

48 lines
1.6 KiB
Ruby
Raw Normal View History

2018-11-18 11:00:15 +05:30
# frozen_string_literal: true
2018-03-17 18:26:18 +05:30
module Projects
module GroupLinks
class CreateService < BaseService
def execute(group)
2019-03-13 22:55:13 +05:30
return error('Not Found', 404) unless group && can?(current_user, :read_namespace, group)
2018-03-17 18:26:18 +05:30
2019-03-13 22:55:13 +05:30
link = project.project_group_links.new(
2018-03-17 18:26:18 +05:30
group: group,
group_access: params[:link_group_access],
expires_at: params[:expires_at]
)
2019-03-13 22:55:13 +05:30
if link.save
2020-08-18 19:51:02 +05:30
setup_authorizations(group, link.group_access)
2019-03-13 22:55:13 +05:30
success(link: link)
else
error(link.errors.full_messages.to_sentence, 409)
end
2018-03-17 18:26:18 +05:30
end
2020-07-28 23:09:34 +05:30
private
2020-08-18 19:51:02 +05:30
def setup_authorizations(group, group_access = nil)
2021-04-17 20:07:23 +05:30
if Feature.enabled?(:specialized_project_authorization_project_share_worker, default_enabled: :yaml)
2020-08-18 19:51:02 +05:30
AuthorizedProjectUpdate::ProjectGroupLinkCreateWorker.perform_async(
project.id, group.id, group_access)
2020-07-28 23:09:34 +05:30
# AuthorizedProjectsWorker uses an exclusive lease per user but
# specialized workers might have synchronization issues. Until we
# compare the inconsistency rates of both approaches, we still run
# AuthorizedProjectsWorker but with some delay and lower urgency as a
# safety net.
group.refresh_members_authorized_projects(
blocking: false,
priority: UserProjectAccessChangedService::LOW_PRIORITY
)
else
group.refresh_members_authorized_projects(blocking: false)
end
end
2018-03-17 18:26:18 +05:30
end
end
end
2019-12-04 20:38:33 +05:30
2021-06-08 01:23:25 +05:30
Projects::GroupLinks::CreateService.prepend_mod_with('Projects::GroupLinks::CreateService')