Commit 2abb48ad authored by Jason Goodman's avatar Jason Goodman

Add source members url to billable memberships api

Link to group or project memberships page
parent dc1f0ae2
......@@ -4,11 +4,21 @@ module EE
module API
module Entities
class BillableMembership < Grape::Entity
include ::Gitlab::Routing
expose :id
expose :source_id
expose :source_full_name do |member|
member.source.full_name
end
expose :source_members_url do |member|
case member.source_type
when 'Namespace'
group_group_members_url(member.source)
when 'Project'
project_project_members_url(member.source)
end
end
expose :created_at
expose :expires_at
expose :access_level do
......
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe ::EE::API::Entities::BillableMembership do
describe '#as_json' do
it 'returns source_members_url for a group' do
membership = create(:group_member)
group_members_url = Gitlab::Routing.url_helpers.group_group_members_url(membership.source)
expect(described_class.new(membership).as_json[:source_members_url]).to eq(group_members_url)
end
it 'returns source_members_url for a project' do
membership = create(:project_member)
project_members_url = Gitlab::Routing.url_helpers.project_project_members_url(membership.source)
expect(described_class.new(membership).as_json[:source_members_url]).to eq(project_members_url)
end
end
end
......@@ -522,6 +522,7 @@ RSpec.describe API::Members do
'id' => membership.id,
'source_id' => group.id,
'source_full_name' => group.full_name,
'source_members_url' => group_group_members_url(group),
'created_at' => membership.created_at.as_json,
'expires_at' => nil,
'access_level' => {
......
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