-
Notifications
You must be signed in to change notification settings - Fork 161
plan share prd #1362
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
DominikAlberski
merged 8 commits into
Release_300425_Shared_Plans
from
prd_plan_share_dev
Apr 30, 2025
Merged
plan share prd #1362
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
9865fd1
plan share wip
gbarc-dt 295017a
specs
gbarc-dt b7b5cd3
admin_revoked
gbarc-dt b50a4d6
share delete changed, admin_revoked in renderer
gbarc-dt e4c8b28
share api cleanup
gbarc-dt 8a3bf48
Merge branch 'master' into prd_plan_share_dev
gbarc-dt 1e32a79
a. state workaround
gbarc-dt a7d7caf
added credits_consumed to plan_share
gbarc-dt File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| module Travis::API::V3 | ||
| class Models::PlanShare | ||
| attr_reader :plan_id, :donor, :receiver, :shared_by, :created_at, :admin_revoked, :credits_consumed | ||
| def initialize(attributes = {}) | ||
| @plan_id = attributes.fetch('plan_id') | ||
| @donor = attributes.fetch('donor') | ||
| @receiver = attributes.fetch('receiver') | ||
| @shared_by = attributes.fetch('shared_by') | ||
| @created_at = attributes.fetch('created_at') | ||
| @admin_revoked = attributes.fetch('admin_revoked') | ||
| @credits_consumed = attributes.fetch('credits_consumed') | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module Travis::API::V3 | ||
| class Renderer::PlanShare < ModelRenderer | ||
| representation(:standard, :plan_id, :donor, :receiver, :shared_by, :created_at, :admin_revoked, :credits_consumed) | ||
| representation(:minimal, :plan_id, :donor, :receiver, :shared_by, :created_at, :admin_revoked, :credits_consumed) | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| module Travis::API::V3 | ||
| class Renderer::PlanShares < CollectionRenderer | ||
| type :plan_shares | ||
| collection_key :plan_shares | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| module Travis::API::V3 | ||
| class Services::V2Subscription::Share < Service | ||
| params :receiver_id, :receiver | ||
| def run! | ||
| raise LoginRequired unless access_control.full_access_or_logged_in? | ||
| if @env['REQUEST_METHOD'] == 'DELETE' then | ||
DominikAlberski marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| query.delete_share(access_control.user.id, params['receiver_id']) | ||
| else | ||
| query.share(access_control.user.id, params['receiver_id']) | ||
| end | ||
| no_content | ||
| end | ||
| end | ||
| end | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| describe Travis::API::V3::Services::V2Subscription::Share, set_app: true, billing_spec_helper: true do | ||
| let(:billing_url) { 'http://billingfake.travis-ci.com' } | ||
| let(:billing_auth_key) { 'secret' } | ||
| let(:receiver) { FactoryBot.create(:org) } | ||
| let(:data) { {'plan'=> subscription_id, 'receiver_id' => receiver.id } } | ||
|
|
||
| before do | ||
| Travis.config.billing.url = billing_url | ||
| Travis.config.billing.auth_key = billing_auth_key | ||
| end | ||
|
|
||
| context 'unauthenticated' do | ||
| it 'responds 403 for post' do | ||
| post('/v3/v2_subscription/123/share', {}) | ||
|
|
||
| expect(last_response.status).to eq(403) | ||
| end | ||
|
|
||
| it 'responds 403 for delete' do | ||
| delete('/v3/v2_subscription/123/share', {}) | ||
|
|
||
| expect(last_response.status).to eq(403) | ||
| end | ||
| end | ||
|
|
||
| context 'authenticated create share' do | ||
| let(:user) { FactoryBot.create(:user) } | ||
| let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: 1) } | ||
| let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}", | ||
| 'CONTENT_TYPE' => 'application/json' }} | ||
| let(:subscription_id) { rand(999) } | ||
|
|
||
| let!(:stubbed_request) do | ||
| stub_billing_request(:post, "/v2/subscriptions/#{subscription_id}/share", auth_key: billing_auth_key, user_id: user.id) | ||
| .with(body: { | ||
| 'plan' => subscription_id.to_s, | ||
| 'receiver' => receiver.id, | ||
| 'requested_by' => user.id | ||
| }) | ||
| .to_return(status: 204) | ||
| end | ||
|
|
||
| it 'shares the subscription' do | ||
| post("/v3/v2_subscription/#{subscription_id}/share", JSON.generate(data), headers) | ||
|
|
||
| expect(last_response.status).to eq(204) | ||
| expect(stubbed_request).to have_been_made.once | ||
| end | ||
| end | ||
|
|
||
| context 'authenticated delete share' do | ||
| let(:user) { FactoryBot.create(:user) } | ||
| let(:token) { Travis::Api::App::AccessToken.create(user: user, app_id: 1) } | ||
| let(:headers) {{ 'HTTP_AUTHORIZATION' => "token #{token}", | ||
| 'CONTENT_TYPE' => 'application/json' }} | ||
| let(:subscription_id) { rand(999) } | ||
|
|
||
| let!(:stubbed_request) do | ||
| stub_request(:delete, "#{billing_url}/v2/subscriptions/#{subscription_id}/share?plan=#{subscription_id}&receiver=#{receiver.id}&requested_by=#{user.id}").with( | ||
| headers: { | ||
| 'X-Travis-User-Id' => user.id | ||
| } | ||
| ) | ||
| .to_return(status: 204) | ||
| end | ||
|
|
||
| it 'deletes subscription share' do | ||
| delete("/v3/v2_subscription/#{subscription_id}/share", JSON.generate(data), headers) | ||
| expect(last_response.status).to eq(204) | ||
| expect(stubbed_request).to have_been_made.once | ||
| end | ||
| end | ||
| end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.