2018-07-17 12:50:37 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2017-11-01 10:08:18 -04:00
|
|
|
module Projects
|
|
|
|
module GroupLinks
|
|
|
|
class CreateService < BaseService
|
|
|
|
def execute(group)
|
2019-02-12 07:29:47 -05:00
|
|
|
return error('Not Found', 404) unless group && can?(current_user, :read_namespace, group)
|
2017-11-01 10:08:18 -04:00
|
|
|
|
2019-02-12 07:29:47 -05:00
|
|
|
link = project.project_group_links.new(
|
2017-11-01 10:08:18 -04:00
|
|
|
group: group,
|
|
|
|
group_access: params[:link_group_access],
|
|
|
|
expires_at: params[:expires_at]
|
|
|
|
)
|
2019-02-12 07:29:47 -05:00
|
|
|
|
|
|
|
if link.save
|
2021-07-08 05:09:33 -04:00
|
|
|
setup_authorizations(group)
|
2019-02-12 07:29:47 -05:00
|
|
|
success(link: link)
|
|
|
|
else
|
|
|
|
error(link.errors.full_messages.to_sentence, 409)
|
|
|
|
end
|
2017-11-01 10:08:18 -04:00
|
|
|
end
|
2020-06-17 11:08:36 -04:00
|
|
|
|
|
|
|
private
|
|
|
|
|
2021-07-08 05:09:33 -04:00
|
|
|
def setup_authorizations(group)
|
|
|
|
AuthorizedProjectUpdate::ProjectRecalculateWorker.perform_async(project.id)
|
2020-06-17 11:08:36 -04:00
|
|
|
|
2021-06-11 11:09:58 -04:00
|
|
|
# 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
|
|
|
|
)
|
2020-06-17 11:08:36 -04:00
|
|
|
end
|
2017-11-01 10:08:18 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-09-13 09:26:31 -04:00
|
|
|
|
2021-05-11 17:10:21 -04:00
|
|
|
Projects::GroupLinks::CreateService.prepend_mod_with('Projects::GroupLinks::CreateService')
|