diff options
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/entities.rb | 1 | ||||
-rw-r--r-- | lib/api/helpers.rb | 4 | ||||
-rw-r--r-- | lib/api/projects.rb | 14 |
3 files changed, 17 insertions, 2 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 8b1ebb9c994..fc7d391fd30 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -102,6 +102,7 @@ module API class RepoCommit < Grape::Entity expose :id, :short_id, :title, :author_name, :author_email, :created_at + expose :safe_message, as: :message end class RepoCommitDetail < RepoCommit diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index d7d209e16f7..8189e433789 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -5,6 +5,10 @@ module API SUDO_HEADER ="HTTP_SUDO" SUDO_PARAM = :sudo + def parse_boolean(value) + [ true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON' ].include?(value) + end + def current_user private_token = (params[PRIVATE_TOKEN_PARAM] || env[PRIVATE_TOKEN_HEADER]).to_s @current_user ||= User.find_by(authentication_token: private_token) diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 88c73bff32d..149678e6803 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -7,7 +7,7 @@ module API helpers do def map_public_to_visibility_level(attrs) publik = attrs.delete(:public) - publik = [ true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON' ].include?(publik) + publik = parse_boolean(publik) attrs[:visibility_level] = Gitlab::VisibilityLevel::PUBLIC if !attrs[:visibility_level].present? && publik == true attrs end @@ -15,10 +15,20 @@ module API # Get a projects list for authenticated user # + # Parameters: + # archived (optional) - if passed, limit by archived status + # # Example Request: # GET /projects get do - @projects = paginate current_user.authorized_projects + @projects = current_user.authorized_projects + + # If the archived parameter is passed, limit results accordingly + if params[:archived].present? + @projects = @projects.where(archived: parse_boolean(params[:archived])) + end + + @projects = paginate @projects present @projects, with: Entities::Project end |