Commit 6d892244 authored by Adam Niedzielski's avatar Adam Niedzielski

Add API support for expires_at.

parent 9accb302
......@@ -95,6 +95,9 @@ module API
expose :access_level do |user, options|
options[:project].project_members.find_by(user_id: user.id).access_level
end
expose :expires_at do |user, options|
options[:project].project_members.find_by(user_id: user.id).expires_at
end
end
class Group < Grape::Entity
......
......@@ -38,6 +38,7 @@ module API
# id (required) - The ID of a project
# user_id (required) - The ID of a user
# access_level (required) - Project access level
# expires_at (optional) - Date string in the format YEAR-MONTH-DAY
# Example Request:
# POST /projects/:id/members
post ":id/members" do
......@@ -49,7 +50,8 @@ module API
if project_member.nil?
project_member = user_project.project_members.new(
user_id: params[:user_id],
access_level: params[:access_level]
access_level: params[:access_level],
expires_at: params[:expires_at]
)
end
......@@ -67,16 +69,17 @@ module API
# id (required) - The ID of a project
# user_id (required) - The ID of a team member
# access_level (required) - Project access level
# expires_at (optional) - Date string in the format YEAR-MONTH-DAY
# Example Request:
# PUT /projects/:id/members/:user_id
put ":id/members/:user_id" do
authorize! :admin_project, user_project
required_attributes! [:access_level]
attrs = attributes_for_keys [:access_level, :expires_at]
project_member = user_project.project_members.find_by(user_id: params[:user_id])
not_found!("User can not be found") if project_member.nil?
if project_member.update_attributes(access_level: params[:access_level])
if project_member.update_attributes(attrs)
@member = project_member.user
present @member, with: Entities::ProjectMember, project: user_project
else
......
......@@ -54,12 +54,16 @@ describe API::API, api: true do
describe "POST /projects/:id/members" do
it "should add user to project team" do
expect do
post api("/projects/#{project.id}/members", user), user_id: user2.id, access_level: ProjectMember::DEVELOPER
post api("/projects/#{project.id}/members", user),
user_id: user2.id,
access_level: ProjectMember::DEVELOPER,
expires_at: '2016-08-05'
end.to change { ProjectMember.count }.by(1)
expect(response).to have_http_status(201)
expect(json_response['username']).to eq(user2.username)
expect(json_response['access_level']).to eq(ProjectMember::DEVELOPER)
expect(json_response['expires_at']).to eq('2016-08-05')
end
it "should return a 201 status if user is already project member" do
......@@ -95,10 +99,13 @@ describe API::API, api: true do
before { project_member2 }
it "should update project team member" do
put api("/projects/#{project.id}/members/#{user3.id}", user), access_level: ProjectMember::MASTER
put api("/projects/#{project.id}/members/#{user3.id}", user),
access_level: ProjectMember::MASTER,
expires_at: '2016-08-05'
expect(response).to have_http_status(200)
expect(json_response['username']).to eq(user3.username)
expect(json_response['access_level']).to eq(ProjectMember::MASTER)
expect(json_response['expires_at']).to eq('2016-08-05')
end
it "should return a 404 error if user_id is not found" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment