Commit eea31779 authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Add current user permissions info to /api/projects/:id.json

Signed-off-by: default avatarDmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
parent a91a6491
...@@ -44,7 +44,7 @@ module API ...@@ -44,7 +44,7 @@ module API
expose :id, :description, :default_branch expose :id, :description, :default_branch
expose :public?, as: :public expose :public?, as: :public
expose :visibility_level, :ssh_url_to_repo, :http_url_to_repo, :web_url 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 :name, :name_with_namespace
expose :path, :path_with_namespace expose :path, :path_with_namespace
expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :snippets_enabled, :created_at, :last_activity_at expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :snippets_enabled, :created_at, :last_activity_at
...@@ -175,5 +175,27 @@ module API ...@@ -175,5 +175,27 @@ module API
class Namespace < Grape::Entity class Namespace < Grape::Entity
expose :id, :path, :kind expose :id, :path, :kind
end 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
end end
...@@ -48,7 +48,7 @@ module API ...@@ -48,7 +48,7 @@ module API
# Example Request: # Example Request:
# GET /projects/:id # GET /projects/:id
get ":id" do get ":id" do
present user_project, with: Entities::Project present user_project, with: Entities::ProjectWithAccess, user: current_user
end end
# Get a single project events # Get a single project events
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment