diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-03-17 16:33:41 +0400 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-03-17 16:33:41 +0400 |
commit | eea317795ea970f762a1331beba6fde20e7a8aeb (patch) | |
tree | efb47eeb1e55dee756ff2ba8c0a508158122ebd8 /lib | |
parent | a91a6491bf3e74791ecf8dd1111d54435b8578cb (diff) |
Add current user permissions info to /api/projects/:id.json
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities.rb | 24 | ||||
-rw-r--r-- | lib/api/projects.rb | 2 |
2 files changed, 24 insertions, 2 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 9c9c7fcd6ea..6413dd0abf5 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 618a582a451..4d48d2194f8 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 |