Skip to content
Snippets Groups Projects

Add groups api

Merged gitlab-qa-bot requested to merge github/fork/former03/feature_groups_api into master

Created by: simonswine

Hey,

i reworked my groups api addon pull request (#2523), so that it now contains tests+docs. It also distinguishes between admins and normal users

Cheers

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
lib/api/groups.rb 0 → 100644
21 #
22 # Parameters:
23 # name (required) - Name
24 # path (required) - Path
25 # Example Request:
26 # POST /groups
27 post do
28 authenticated_as_admin!
29 attrs = attributes_for_keys [:name, :path]
30 @group = Group.new(attrs)
31 @group.owner = current_user
32
33 if @group.save
34 present @group, with: Entities::Group
35 else
36 not_found!
  • Created by: Xylakant

    There's no test covering this case. Also, I don't think that 404 Not Found is an appropriate status for "This operation failed." See #2825 (closed) for my take on this.

    By Administrator on 2013-02-03T18:39:51 (imported from GitLab project)

    By Administrator on 2013-02-03T18:39:51 (imported from GitLab)

  • Created by: simonswine

    I see your problem Xylakant, but these are my first steps in rails programming. I have no idea, how can i get the error from the save() method and which validator failed. I also have know idea how to return http status code 409. If i had an example, but your ticket (#2825 (closed)) haven't been fully resoved yet...

    By Administrator on 2013-02-01T18:03:52 (imported from GitLab project)

    By Administrator on 2013-02-01T18:03:52 (imported from GitLab)

  • Created by: Xylakant

    Hi Simon,

    just to clarify: The API is written using grape and while it does use some of the code of the rails app, this is not really rails. Still, since the models are pretty standard ActiveRecord based models, you should be able to retrieve the validation errors by calling @group.errors after a failed save. You can return any error to the client by using the error! method, see https://github.com/intridea/grape#raising-exceptions. Given that there is no decision about which status code should be returned in a failure case, I guess you could as well leave it as it is, so that the API is at least consistent. There's still time to change it once a core dev decides.

    By Administrator on 2013-02-01T22:29:27 (imported from GitLab project)

    By Administrator on 2013-02-01T22:29:27 (imported from GitLab)

  • gitlab-qa-bot
  • 32 32 end
    33 33 end
    34 34
    35 class Group < Grape::Entity
    36 expose :id, :name, :path, :owner_id
    37 end
    38
    39 class GroupDetail < Group
    40 expose :projects, using: Entities::Project
    41 end
    • Created by: AlexDenisov

      You can inherit from Group, to avoid duplicated code.

      By Administrator on 2013-02-03T18:39:51 (imported from GitLab project)

      By Administrator on 2013-02-03T18:39:51 (imported from GitLab)

  • gitlab-qa-bot
  • lib/api/groups.rb 0 → 100644
    21 #
    22 # Parameters:
    23 # name (required) - Name
    24 # path (required) - Path
    25 # Example Request:
    26 # POST /groups
    27 post do
    28 authenticated_as_admin!
    29 attrs = attributes_for_keys [:name, :path]
    30 @group = Group.new(attrs)
    31 @group.owner = current_user
    32
    33 if @group.save
    34 present @group, with: Entities::Group
    35 else
    36 not_found!
    • Created by: dzaporozhets

      I think It shoul be 500 here

      By Administrator on 2013-02-03T18:39:51 (imported from GitLab project)

      By Administrator on 2013-02-03T18:39:51 (imported from GitLab)

  • gitlab-qa-bot
  • lib/api/groups.rb 0 → 100644
    21 #
    22 # Parameters:
    23 # name (required) - Name
    24 # path (required) - Path
    25 # Example Request:
    26 # POST /groups
    27 post do
    28 authenticated_as_admin!
    29 attrs = attributes_for_keys [:name, :path]
    30 @group = Group.new(attrs)
    31 @group.owner = current_user
    32
    33 if @group.save
    34 present @group, with: Entities::Group
    35 else
    36 not_found!
    • Created by: Xylakant

      I don't understand a 500. 500 Internal Server Error is reserved in case a server process died for unexpected reasons. I'm not absolutely certain in which cases the save can fail, but I assume one case is if a client tries to create two groups with the same name. That case should probably be 409 Conflict oder a generic 400 Bad Request since the error is clearly on the clients side.

      By Administrator on 2013-02-03T18:39:51 (imported from GitLab project)

      By Administrator on 2013-02-03T18:39:51 (imported from GitLab)

  • gitlab-qa-bot
  • 32 32 end
    33 33 end
    34 34
    35 class Group < Grape::Entity
    36 expose :id, :name, :path, :owner_id
    37 end
    38
    39 class GroupDetail < Group
    40 expose :projects, using: Entities::Project
    41 end
    • Created by: simonswine

      Yeah, you're absolutely right. I just changed it...

      By Administrator on 2013-02-03T18:41:16 (imported from GitLab project)

      By Administrator on 2013-02-03T18:41:16 (imported from GitLab)

  • Created by: simonswine

    Thanks Xylakant for you're explanations. I've got a project in pipeline, where i will use the api, perhaps i find the time for a bigger pull request for gitlab api return codes

    By Administrator on 2013-02-03T18:43:03 (imported from GitLab project)

    By Administrator on 2013-02-03T18:43:03 (imported from GitLab)

  • Created by: dzaporozhets

    Thank you. Now it can be merged

    By Administrator on 2013-02-06T11:19:21 (imported from GitLab project)

    By Administrator on 2013-02-06T11:19:21 (imported from GitLab)

  • Please register or sign in to reply
    Loading