diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 9c9c7fcd6ea0bd412f64fb256ea471b81c1cbf48..6413dd0abf5d5cadfbd02f78b7a8ab4718541c84 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -44,7 +44,7 @@ module API expose :id, :description, :default_branch expose :public?, as: :public expose :visibility_level, :ssh_url_to_repo, :http_url_to_repo, :web_url - expose :owner, using: Entities::UserBasic + expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group } expose :name, :name_with_namespace expose :path, :path_with_namespace expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :snippets_enabled, :created_at, :last_activity_at @@ -175,5 +175,27 @@ module API class Namespace < Grape::Entity expose :id, :path, :kind end + + class ProjectAccess < Grape::Entity + expose :project_access, as: :access_level + expose :notification_level + end + + class GroupAccess < Grape::Entity + expose :group_access, as: :access_level + expose :notification_level + end + + class ProjectWithAccess < Project + expose :permissions do + expose :project_access, using: Entities::ProjectAccess do |project, options| + project.users_projects.find_by(user_id: options[:user].id) + end + + expose :group_access, using: Entities::GroupAccess do |project, options| + project.group.users_groups.find_by(user_id: options[:user].id) + end + end + end end end diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 618a582a451e135e8b4b6c9323b6567ed6b01054..4d48d2194f8007b75f62af269fb05092fcd897fd 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -48,7 +48,7 @@ module API # Example Request: # GET /projects/:id get ":id" do - present user_project, with: Entities::Project + present user_project, with: Entities::ProjectWithAccess, user: current_user end # Get a single project events