diff options
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/entities.rb | 4 | ||||
-rw-r--r-- | lib/api/helpers.rb | 8 | ||||
-rw-r--r-- | lib/api/notes.rb | 13 | ||||
-rw-r--r-- | lib/api/repositories.rb | 12 | ||||
-rw-r--r-- | lib/api/users.rb | 4 |
5 files changed, 32 insertions, 9 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index b190646a1e3..09fb97abf29 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -218,5 +218,9 @@ module API expose :same, as: :compare_same_ref end + + class Contributor < Grape::Entity + expose :name, :email, :commits, :additions, :deletions + end end end diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index b6a5806d646..d7d209e16f7 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -98,10 +98,14 @@ module API def attributes_for_keys(keys) attrs = {} + keys.each do |key| - attrs[key] = params[key] if params[key].present? or (params.has_key?(key) and params[key] == false) + if params[key].present? or (params.has_key?(key) and params[key] == false) + attrs[key] = params[key] + end end - attrs + + ActionController::Parameters.new(attrs).permit! end # error helpers diff --git a/lib/api/notes.rb b/lib/api/notes.rb index 413faf0cf2d..0ef9a3c4beb 100644 --- a/lib/api/notes.rb +++ b/lib/api/notes.rb @@ -50,12 +50,15 @@ module API post ":id/#{noteables_str}/:#{noteable_id_str}/notes" do required_attributes! [:body] - @noteable = user_project.send(:"#{noteables_str}").find(params[:"#{noteable_id_str}"]) - @note = @noteable.notes.new(note: params[:body]) - @note.author = current_user - @note.project = user_project + opts = { + note: params[:body], + noteable_type: noteables_str.classify, + noteable_id: params[noteable_id_str] + } + + @note = ::Notes::CreateService.new(user_project, current_user, opts).execute - if @note.save + if @note.valid? present @note, with: Entities::Note else not_found! diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb index 03806d9343b..d091fa4f035 100644 --- a/lib/api/repositories.rb +++ b/lib/api/repositories.rb @@ -150,6 +150,18 @@ module API compare = Gitlab::Git::Compare.new(user_project.repository.raw_repository, params[:from], params[:to], MergeRequestDiff::COMMITS_SAFE_SIZE) present compare, with: Entities::Compare end + + # Get repository contributors + # + # Parameters: + # id (required) - The ID of a project + # Example Request: + # GET /projects/:id/repository/contributors + get ':id/repository/contributors' do + authorize! :download_code, user_project + + present user_project.repository.contributors, with: Entities::Contributor + end end end end diff --git a/lib/api/users.rb b/lib/api/users.rb index 92dbe97f0a4..69553f16397 100644 --- a/lib/api/users.rb +++ b/lib/api/users.rb @@ -59,7 +59,7 @@ module API authenticated_as_admin! required_attributes! [:email, :password, :name, :username] attrs = attributes_for_keys [:email, :name, :password, :skype, :linkedin, :twitter, :projects_limit, :username, :extern_uid, :provider, :bio, :can_create_group, :admin] - user = User.build_user(attrs, as: :admin) + user = User.build_user(attrs) admin = attrs.delete(:admin) user.admin = admin unless admin.nil? if user.save @@ -96,7 +96,7 @@ module API admin = attrs.delete(:admin) user.admin = admin unless admin.nil? - if user.update_attributes(attrs, as: :admin) + if user.update_attributes(attrs) present user, with: Entities::UserFull else not_found! |