diff options
author | Małgorzata Ksionek <meksionek@gmail.com> | 2019-02-12 15:29:47 +0300 |
---|---|---|
committer | Małgorzata Ksionek <meksionek@gmail.com> | 2019-02-20 13:08:13 +0300 |
commit | 211c4e5985bf40afe7cf2391c76a6cfde153fb49 (patch) | |
tree | f675af054959391d825b3ebd8d0af02767bf2557 /lib/api/projects.rb | |
parent | 459276846372d8309220a5667cb4389dcfc66281 (diff) |
Change policy regarding group visibility
Diffstat (limited to 'lib/api/projects.rb')
-rw-r--r-- | lib/api/projects.rb | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 6a93ef9f3ad..a7b4dc06832 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -436,27 +436,24 @@ module API end params do requires :group_id, type: Integer, desc: 'The ID of a group' - requires :group_access, type: Integer, values: Gitlab::Access.values, desc: 'The group access level' + requires :group_access, type: Integer, values: Gitlab::Access.values, as: :link_group_access, desc: 'The group access level' optional :expires_at, type: Date, desc: 'Share expiration date' end post ":id/share" do authorize! :admin_project, user_project group = Group.find_by_id(params[:group_id]) - unless group && can?(current_user, :read_group, group) - not_found!('Group') - end - unless user_project.allowed_to_share_with_group? break render_api_error!("The project sharing with group is disabled", 400) end - link = user_project.project_group_links.new(declared_params(include_missing: false)) + result = ::Projects::GroupLinks::CreateService.new(user_project, current_user, declared_params(include_missing: false)) + .execute(group) - if link.save - present link, with: Entities::ProjectGroupLink + if result[:status] == :success + present result[:link], with: Entities::ProjectGroupLink else - render_api_error!(link.errors.full_messages.first, 409) + render_api_error!(result[:message], result[:http_status]) end end |