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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

47 lines
1.4 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
2022-07-16 23:28:13 +05:30
include GroupLinkable
2018-03-17 18:26:18 +05:30
2022-07-16 23:28:13 +05:30
def initialize(project, shared_with_group, user, params)
@shared_with_group = shared_with_group
2019-03-13 22:55:13 +05:30
2022-07-16 23:28:13 +05:30
super(project, user, params)
2018-03-17 18:26:18 +05:30
end
2020-07-28 23:09:34 +05:30
private
2022-07-16 23:28:13 +05:30
delegate :root_ancestor, to: :project
def valid_to_create?
can?(current_user, :read_namespace, shared_with_group) && sharing_allowed?
end
def build_link
@link = project.project_group_links.new(
group: shared_with_group,
group_access: params[:link_group_access],
expires_at: params[:expires_at]
)
end
def setup_authorizations
2021-09-30 23:02:18 +05:30
AuthorizedProjectUpdate::ProjectRecalculateWorker.perform_async(project.id)
2020-07-28 23:09:34 +05:30
2021-09-04 01:27:46 +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.
2022-07-16 23:28:13 +05:30
shared_with_group.refresh_members_authorized_projects(
2021-09-04 01:27:46 +05:30
priority: UserProjectAccessChangedService::LOW_PRIORITY
)
2020-07-28 23:09:34 +05:30
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')