Skip to content

GitLab

  • Menu
Projects Groups Snippets
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in
  • G gitlabhq1
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 21
    • Issues 21
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 12
    • Merge requests 12
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Monitor
    • Monitor
    • Incidents
  • Packages & Registries
    • Packages & Registries
    • Package Registry
    • Infrastructure Registry
  • Analytics
    • Analytics
    • CI/CD
    • Repository
    • Value stream
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • gpt
  • large_projects
  • gitlabhq1
  • Merge requests
  • !2877

Merged
Created 12 years ago by Administrator@rootOwner

Add groups api

  • Overview 9
  • Commits 5
  • Changes 6

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

Loading
Loading

  • Administrator
    Administrator @root started a thread on commit 33c48ecd 12 years ago
    lib/api/groups.rb
    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!
    • Administrator
      Administrator @root · 12 years ago
      Owner

      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)

  • Administrator
    Administrator @root · 12 years ago
    Owner

    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)

  • Administrator
    Administrator @root · 12 years ago
    Owner

    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)

  • Administrator
    Administrator @root started a thread on commit 33c48ecd 12 years ago
    lib/api/entities.rb
    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
    • Administrator
      Administrator @root · 12 years ago
      Owner

      Created by: AlexDenisov

      You can inherit from Group, to avoid duplicated code.

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

  • Administrator
    Administrator @root started a thread on commit 33c48ecd 12 years ago
    lib/api/groups.rb
    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!
    • Administrator
      Administrator @root · 12 years ago
      Owner

      Created by: dzaporozhets

      I think It shoul be 500 here

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

  • Administrator
    Administrator @root started a thread on commit 33c48ecd 12 years ago
    lib/api/groups.rb
    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!
    • Administrator
      Administrator @root · 12 years ago
      Owner

      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)

  • Administrator
    Administrator @root started a thread on commit 33c48ecd 12 years ago
    lib/api/entities.rb
    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
    • Administrator
      Administrator @root · 12 years ago
      Owner

      Created by: simonswine

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

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

  • Administrator
    Administrator @root · 12 years ago
    Owner

    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)

  • Administrator
    Administrator @root · 12 years ago
    Owner

    Created by: dzaporozhets

    Thank you. Now it can be merged

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

  • You're only seeing other activity in the feed. To add a comment, switch to one of the following options.
Please register or sign in to reply
0 Assignees
Assign to
0 Reviewers
Request review from
Milestone
No milestone
None
None
Time tracking
0
Labels
None
Assign labels
  • No matching results
  • Manage project labels
Lock merge request
Unlocked
participants
Reference:
Source branch: github/fork/former03/feature_groups_api

    0 pending comments