diff options
author | Douwe Maan <douwe@gitlab.com> | 2016-08-19 17:08:03 +0000 |
---|---|---|
committer | Douwe Maan <douwe@gitlab.com> | 2016-08-19 17:08:03 +0000 |
commit | 725036669cca45df17f1acbb1a45a031a1a84c85 (patch) | |
tree | f8fae23c197b4db87ed8ed3f387f943c17492b2f /lib | |
parent | 8fc800cbcc9994ccf8e582df2e94e8e27b5e6fbe (diff) | |
parent | 1e00e4369d316d079e31227d4a45ad2101553ec2 (diff) | |
download | gitlab-ce-725036669cca45df17f1acbb1a45a031a1a84c85.tar.gz |
Merge branch 'expiration-date-on-memberships' into 'master'
Expiration date on memberships
Closes https://gitlab.com/gitlab-org/gitlab-ce/issues/17495
See merge request !5876
Diffstat (limited to 'lib')
-rw-r--r-- | lib/api/entities.rb | 4 | ||||
-rw-r--r-- | lib/api/members.rb | 9 |
2 files changed, 10 insertions, 3 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb index 67420772335..54ce2dcfa57 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -97,6 +97,10 @@ module API member = options[:member] || options[:members].find { |m| m.user_id == user.id } member.access_level end + expose :expires_at do |user, options| + member = options[:member] || options[:members].find { |m| m.user_id == user.id } + member.expires_at + end end class AccessRequester < UserBasic diff --git a/lib/api/members.rb b/lib/api/members.rb index 2fae83f60b2..94c16710d9a 100644 --- a/lib/api/members.rb +++ b/lib/api/members.rb @@ -49,6 +49,7 @@ module API # id (required) - The group/project ID # user_id (required) - The user ID of the new member # access_level (required) - A valid access level + # expires_at (optional) - Date string in the format YEAR-MONTH-DAY # # Example Request: # POST /groups/:id/members @@ -72,7 +73,7 @@ module API conflict!('Member already exists') if source_type == 'group' && member unless member - source.add_user(params[:user_id], params[:access_level], current_user) + source.add_user(params[:user_id], params[:access_level], current_user: current_user, expires_at: params[:expires_at]) member = source.members.find_by(user_id: params[:user_id]) end @@ -81,7 +82,7 @@ module API else # Since `source.add_user` doesn't return a member object, we have to # build a new one and populate its errors in order to render them. - member = source.members.build(attributes_for_keys([:user_id, :access_level])) + member = source.members.build(attributes_for_keys([:user_id, :access_level, :expires_at])) member.valid? # populate the errors # This is to ensure back-compatibility but 400 behavior should be used @@ -97,6 +98,7 @@ module API # id (required) - The group/project ID # user_id (required) - The user ID of the member # access_level (required) - A valid access level + # expires_at (optional) - Date string in the format YEAR-MONTH-DAY # # Example Request: # PUT /groups/:id/members/:user_id @@ -107,8 +109,9 @@ module API required_attributes! [:user_id, :access_level] member = source.members.find_by!(user_id: params[:user_id]) + attrs = attributes_for_keys [:access_level, :expires_at] - if member.update_attributes(access_level: params[:access_level]) + if member.update_attributes(attrs) present member.user, with: Entities::Member, member: member else # This is to ensure back-compatibility but 400 behavior should be used |