Commit eea317795ea970f762a1331beba6fde20e7a8aeb
1 parent
a91a6491
Exists in
spb-stable
and in
3 other branches
Add current user permissions info to /api/projects/:id.json
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Showing
2 changed files
with
24 additions
and
2 deletions
Show diff stats
lib/api/entities.rb
| @@ -44,7 +44,7 @@ module API | @@ -44,7 +44,7 @@ module API | ||
| 44 | expose :id, :description, :default_branch | 44 | expose :id, :description, :default_branch |
| 45 | expose :public?, as: :public | 45 | expose :public?, as: :public |
| 46 | expose :visibility_level, :ssh_url_to_repo, :http_url_to_repo, :web_url | 46 | expose :visibility_level, :ssh_url_to_repo, :http_url_to_repo, :web_url |
| 47 | - expose :owner, using: Entities::UserBasic | 47 | + expose :owner, using: Entities::UserBasic, unless: ->(project, options) { project.group } |
| 48 | expose :name, :name_with_namespace | 48 | expose :name, :name_with_namespace |
| 49 | expose :path, :path_with_namespace | 49 | expose :path, :path_with_namespace |
| 50 | expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :snippets_enabled, :created_at, :last_activity_at | 50 | 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 | ||
| 175 | class Namespace < Grape::Entity | 175 | class Namespace < Grape::Entity |
| 176 | expose :id, :path, :kind | 176 | expose :id, :path, :kind |
| 177 | end | 177 | end |
| 178 | + | ||
| 179 | + class ProjectAccess < Grape::Entity | ||
| 180 | + expose :project_access, as: :access_level | ||
| 181 | + expose :notification_level | ||
| 182 | + end | ||
| 183 | + | ||
| 184 | + class GroupAccess < Grape::Entity | ||
| 185 | + expose :group_access, as: :access_level | ||
| 186 | + expose :notification_level | ||
| 187 | + end | ||
| 188 | + | ||
| 189 | + class ProjectWithAccess < Project | ||
| 190 | + expose :permissions do | ||
| 191 | + expose :project_access, using: Entities::ProjectAccess do |project, options| | ||
| 192 | + project.users_projects.find_by(user_id: options[:user].id) | ||
| 193 | + end | ||
| 194 | + | ||
| 195 | + expose :group_access, using: Entities::GroupAccess do |project, options| | ||
| 196 | + project.group.users_groups.find_by(user_id: options[:user].id) | ||
| 197 | + end | ||
| 198 | + end | ||
| 199 | + end | ||
| 178 | end | 200 | end |
| 179 | end | 201 | end |
lib/api/projects.rb
| @@ -48,7 +48,7 @@ module API | @@ -48,7 +48,7 @@ module API | ||
| 48 | # Example Request: | 48 | # Example Request: |
| 49 | # GET /projects/:id | 49 | # GET /projects/:id |
| 50 | get ":id" do | 50 | get ":id" do |
| 51 | - present user_project, with: Entities::Project | 51 | + present user_project, with: Entities::ProjectWithAccess, user: current_user |
| 52 | end | 52 | end |
| 53 | 53 | ||
| 54 | # Get a single project events | 54 | # Get a single project events |