summaryrefslogtreecommitdiff
path: root/lib/api
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api')
-rw-r--r--lib/api/entities.rb6
-rw-r--r--lib/api/helpers.rb19
-rw-r--r--lib/api/issues.rb10
-rw-r--r--lib/api/merge_requests.rb10
-rw-r--r--lib/api/milestones.rb8
-rw-r--r--lib/api/notes.rb12
-rw-r--r--lib/api/projects.rb53
-rw-r--r--lib/api/users.rb2
8 files changed, 65 insertions, 55 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 9e9d44594a2..e5b2685abf5 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -1,12 +1,12 @@
module Gitlab
module Entities
class User < Grape::Entity
- expose :id, :email, :name, :bio, :skype, :linkedin, :twitter,
+ expose :id, :username, :email, :name, :bio, :skype, :linkedin, :twitter,
:dark_scheme, :theme_id, :blocked, :created_at
end
class UserBasic < Grape::Entity
- expose :id, :email, :name, :blocked, :created_at
+ expose :id, :username, :email, :name, :blocked, :created_at
end
class UserLogin < UserBasic
@@ -18,7 +18,7 @@ module Gitlab
end
class Project < Grape::Entity
- expose :id, :code, :name, :description, :path, :default_branch
+ expose :id, :name, :description, :default_branch
expose :owner, using: Entities::UserBasic
expose :private_flag, as: :private
expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :created_at
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index e9305b40836..6bd8111c2b2 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -5,13 +5,18 @@ module Gitlab
end
def user_project
- if @project ||= current_user.projects.find_by_id(params[:id]) ||
- current_user.projects.find_by_path(params[:id])
+ @project ||= find_project
+ @project || not_found!
+ end
+
+ def find_project
+ project = Project.find_by_id(params[:id]) || Project.find_with_namespace(params[:id])
+
+ if project && can?(current_user, :read_project, project)
+ project
else
- not_found!
+ nil
end
-
- @project
end
def paginate(object)
@@ -32,6 +37,10 @@ module Gitlab
end
end
+ def can?(object, action, subject)
+ abilities.allowed?(object, action, subject)
+ end
+
def attributes_for_keys(keys)
attrs = {}
keys.each do |key|
diff --git a/lib/api/issues.rb b/lib/api/issues.rb
index 4ee2d11f15f..3be558816b5 100644
--- a/lib/api/issues.rb
+++ b/lib/api/issues.rb
@@ -17,7 +17,7 @@ module Gitlab
# Get a list of project issues
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# Example Request:
# GET /projects/:id/issues
get ":id/issues" do
@@ -27,7 +27,7 @@ module Gitlab
# Get a single project issue
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# issue_id (required) - The ID of a project issue
# Example Request:
# GET /projects/:id/issues/:issue_id
@@ -39,7 +39,7 @@ module Gitlab
# Create a new project issue
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# title (required) - The title of an issue
# description (optional) - The description of an issue
# assignee_id (optional) - The ID of a user to assign issue
@@ -62,7 +62,7 @@ module Gitlab
# Update an existing issue
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# issue_id (required) - The ID of a project issue
# title (optional) - The title of an issue
# description (optional) - The description of an issue
@@ -88,7 +88,7 @@ module Gitlab
# Delete a project issue (deprecated)
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# issue_id (required) - The ID of a project issue
# Example Request:
# DELETE /projects/:id/issues/:issue_id
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index 1fa0c549b13..470cd1e1c2d 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -8,7 +8,7 @@ module Gitlab
# List merge requests
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
#
# Example:
# GET /projects/:id/merge_requests
@@ -22,7 +22,7 @@ module Gitlab
# Show MR
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# merge_request_id (required) - The ID of MR
#
# Example:
@@ -40,7 +40,7 @@ module Gitlab
#
# Parameters:
#
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# source_branch (required) - The source branch
# target_branch (required) - The target branch
# assignee_id - Assignee user ID
@@ -67,7 +67,7 @@ module Gitlab
# Update MR
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# merge_request_id (required) - ID of MR
# source_branch - The source branch
# target_branch - The target branch
@@ -95,7 +95,7 @@ module Gitlab
# Post comment to merge request
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# merge_request_id (required) - ID of MR
# note (required) - Text of comment
# Examples:
diff --git a/lib/api/milestones.rb b/lib/api/milestones.rb
index f55dfd04cc5..6aca9d01b09 100644
--- a/lib/api/milestones.rb
+++ b/lib/api/milestones.rb
@@ -7,7 +7,7 @@ module Gitlab
# Get a list of project milestones
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# Example Request:
# GET /projects/:id/milestones
get ":id/milestones" do
@@ -19,7 +19,7 @@ module Gitlab
# Get a single project milestone
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# milestone_id (required) - The ID of a project milestone
# Example Request:
# GET /projects/:id/milestones/:milestone_id
@@ -33,7 +33,7 @@ module Gitlab
# Create a new project milestone
#
# Parameters:
- # id (required) - The ID or code name of the project
+ # id (required) - The ID of the project
# title (required) - The title of the milestone
# description (optional) - The description of the milestone
# due_date (optional) - The due date of the milestone
@@ -54,7 +54,7 @@ module Gitlab
# Update an existing project milestone
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# milestone_id (required) - The ID of a project milestone
# title (optional) - The title of a milestone
# description (optional) - The description of a milestone
diff --git a/lib/api/notes.rb b/lib/api/notes.rb
index a3e1858458d..4875ac4c03e 100644
--- a/lib/api/notes.rb
+++ b/lib/api/notes.rb
@@ -9,7 +9,7 @@ module Gitlab
# Get a list of project wall notes
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# Example Request:
# GET /projects/:id/notes
get ":id/notes" do
@@ -20,7 +20,7 @@ module Gitlab
# Get a single project wall note
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# note_id (required) - The ID of a note
# Example Request:
# GET /projects/:id/notes/:note_id
@@ -32,7 +32,7 @@ module Gitlab
# Create a new project wall note
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# body (required) - The content of a note
# Example Request:
# POST /projects/:id/notes
@@ -54,7 +54,7 @@ module Gitlab
# Get a list of project +noteable+ notes
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# noteable_id (required) - The ID of an issue or snippet
# Example Request:
# GET /projects/:id/issues/:noteable_id/notes
@@ -67,7 +67,7 @@ module Gitlab
# Get a single +noteable+ note
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# noteable_id (required) - The ID of an issue or snippet
# note_id (required) - The ID of a note
# Example Request:
@@ -82,7 +82,7 @@ module Gitlab
# Create a new +noteable+ note
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# noteable_id (required) - The ID of an issue or snippet
# body (required) - The content of a note
# Example Request:
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index 384dbcd5473..fb01524da39 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -16,7 +16,7 @@ module Gitlab
# Get a single project
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# Example Request:
# GET /projects/:id
get ":id" do
@@ -27,8 +27,6 @@ module Gitlab
#
# Parameters:
# name (required) - name for new project
- # code (optional) - code for new project, uses project name if not set
- # path (optional) - path for new project, uses project name if not set
# description (optional) - short project description
# default_branch (optional) - 'master' by default
# issues_enabled (optional) - enabled by default
@@ -56,18 +54,23 @@ module Gitlab
# Get a project team members
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
+ # query - Query string
# Example Request:
# GET /projects/:id/members
get ":id/members" do
- @members = paginate user_project.users
+ if params[:query].present?
+ @members = paginate user_project.users.where("username LIKE ?", "%#{params[:query]}%")
+ else
+ @members = paginate user_project.users
+ end
present @members, with: Entities::ProjectMember, project: user_project
end
# Get a project team members
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# user_id (required) - The ID of a user
# Example Request:
# GET /projects/:id/members/:user_id
@@ -79,7 +82,7 @@ module Gitlab
# Add a new project team member
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# user_id (required) - The ID of a user
# access_level (required) - Project access level
# Example Request:
@@ -102,7 +105,7 @@ module Gitlab
# Update project team member
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# user_id (required) - The ID of a team member
# access_level (required) - Project access level
# Example Request:
@@ -122,7 +125,7 @@ module Gitlab
# Remove a team member from project
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# user_id (required) - The ID of a team member
# Example Request:
# DELETE /projects/:id/members/:user_id
@@ -135,7 +138,7 @@ module Gitlab
# Get project hooks
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# Example Request:
# GET /projects/:id/hooks
get ":id/hooks" do
@@ -147,7 +150,7 @@ module Gitlab
# Get a project hook
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# hook_id (required) - The ID of a project hook
# Example Request:
# GET /projects/:id/hooks/:hook_id
@@ -160,7 +163,7 @@ module Gitlab
# Add hook to project
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# url (required) - The hook URL
# Example Request:
# POST /projects/:id/hooks
@@ -177,7 +180,7 @@ module Gitlab
# Update an existing project hook
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# hook_id (required) - The ID of a project hook
# url (required) - The hook URL
# Example Request:
@@ -198,7 +201,7 @@ module Gitlab
# Delete project hook
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# hook_id (required) - The ID of hook to delete
# Example Request:
# DELETE /projects/:id/hooks
@@ -211,7 +214,7 @@ module Gitlab
# Get a project repository branches
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# Example Request:
# GET /projects/:id/repository/branches
get ":id/repository/branches" do
@@ -221,7 +224,7 @@ module Gitlab
# Get a single branch
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# branch (required) - The name of the branch
# Example Request:
# GET /projects/:id/repository/branches/:branch
@@ -233,7 +236,7 @@ module Gitlab
# Get a project repository tags
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# Example Request:
# GET /projects/:id/repository/tags
get ":id/repository/tags" do
@@ -243,7 +246,7 @@ module Gitlab
# Get a project repository commits
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# ref_name (optional) - The name of a repository branch or tag
# Example Request:
# GET /projects/:id/repository/commits
@@ -261,7 +264,7 @@ module Gitlab
# Get a project snippets
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# Example Request:
# GET /projects/:id/snippets
get ":id/snippets" do
@@ -271,7 +274,7 @@ module Gitlab
# Get a project snippet
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# snippet_id (required) - The ID of a project snippet
# Example Request:
# GET /projects/:id/snippets/:snippet_id
@@ -283,7 +286,7 @@ module Gitlab
# Create a new project snippet
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# title (required) - The title of a snippet
# file_name (required) - The name of a snippet file
# lifetime (optional) - The expiration date of a snippet
@@ -309,7 +312,7 @@ module Gitlab
# Update an existing project snippet
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# snippet_id (required) - The ID of a project snippet
# title (optional) - The title of a snippet
# file_name (optional) - The name of a snippet file
@@ -335,7 +338,7 @@ module Gitlab
# Delete a project snippet
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# snippet_id (required) - The ID of a project snippet
# Example Request:
# DELETE /projects/:id/snippets/:snippet_id
@@ -349,7 +352,7 @@ module Gitlab
# Get a raw project snippet
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# snippet_id (required) - The ID of a project snippet
# Example Request:
# GET /projects/:id/snippets/:snippet_id/raw
@@ -362,7 +365,7 @@ module Gitlab
# Get a raw file contents
#
# Parameters:
- # id (required) - The ID or code name of a project
+ # id (required) - The ID of a project
# sha (required) - The commit or branch name
# filepath (required) - The path to the file to display
# Example Request:
diff --git a/lib/api/users.rb b/lib/api/users.rb
index cad99fd9f7b..140c20f6bd2 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -101,8 +101,6 @@ module Gitlab
key = current_user.keys.find params[:id]
key.delete
end
-
-
end
end
end