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

Add API support for expires_at.

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