Skip to content
This repository was archived by the owner on Jun 2, 2021. It is now read-only.

Commit 06b711d

Browse files
committed
Revert "Update setting permissions on org creation"
This reverts commit 25d291b.
1 parent 32fab3a commit 06b711d

4 files changed

Lines changed: 19 additions & 91 deletions

File tree

app/actions/organization_create.rb

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
require 'role_create'
2-
31
module VCAP::CloudController
42
class OrganizationCreate
53
class Error < ::StandardError
@@ -10,7 +8,7 @@ def initialize(perm_client:, user_audit_info:)
108
@user_audit_info = user_audit_info
119
end
1210

13-
def create(message, user)
11+
def create(message)
1412
org = nil
1513
Organization.db.transaction do
1614
org = VCAP::CloudController::Organization.create(
@@ -21,10 +19,8 @@ def create(message, user)
2119
MetadataUpdate.update(org, message)
2220
end
2321

24-
VCAP::CloudController::RoleTypes::ORGANIZATION_ROLES.each do |role|
25-
VCAP::CloudController::RoleCreate.new(message, @user_audit_info).create_organization_role(type: role,
26-
user: user,
27-
organization: org)
22+
VCAP::CloudController::Roles::ORG_ROLE_NAMES.each do |role|
23+
perm_client.create_org_role(role: role, org_id: org.guid)
2824
end
2925

3026
Repositories::OrganizationEventRepository.new.record_organization_create(org, @user_audit_info, message.audit_hash)

app/controllers/v3/organizations_controller.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def create
4747
message = VCAP::CloudController::OrganizationCreateMessage.new(hashed_params[:body])
4848
unprocessable!(message.errors.full_messages) unless message.valid?
4949

50-
org = OrganizationCreate.new(perm_client: perm_client, user_audit_info: user_audit_info).create(message, current_user)
50+
org = OrganizationCreate.new(perm_client: perm_client, user_audit_info: user_audit_info).create(message)
5151

5252
render json: Presenters::V3::OrganizationPresenter.new(org), status: :created
5353
rescue OrganizationCreate::Error => e

spec/request/organizations_spec.rb

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,18 @@ module VCAP::CloudController
1010
let!(:organization2) { Organization.make name: 'Dungeon World' }
1111
let!(:organization3) { Organization.make name: 'The Sprawl' }
1212
let!(:inaccessible_organization) { Organization.make name: 'D&D' }
13-
let(:uaa_client) { instance_double(VCAP::CloudController::UaaClient) }
1413

1514
before do
1615
organization1.add_user(user)
1716
organization2.add_user(user)
1817
organization3.add_user(user)
1918
Domain.dataset.destroy # this will clean up the seeded test domains
2019
TestConfig.override(kubernetes: {})
21-
22-
allow(CloudController::DependencyLocator.instance).to receive(:uaa_client).and_return(uaa_client)
23-
allow(uaa_client).to receive(:usernames_for_ids).with([user.guid]).and_return(
24-
{ user.guid => 'Ragnaros' }
25-
)
2620
end
2721

2822
describe 'POST /v3/organizations' do
29-
let(:request_body) {
30-
{
23+
it 'creates a new organization with the given name' do
24+
request_body = {
3125
name: 'org1',
3226
metadata: {
3327
labels: {
@@ -40,8 +34,7 @@ module VCAP::CloudController
4034
}
4135
}
4236
}.to_json
43-
}
44-
it 'creates a new organization with the given name' do
37+
4538
expect {
4639
post '/v3/organizations', request_body, admin_header
4740
}.to change {
@@ -75,12 +68,12 @@ module VCAP::CloudController
7568
end
7669

7770
it 'allows creating a suspended org' do
78-
suspended_request_body = {
71+
request_body = {
7972
name: 'suspended-org',
8073
suspended: true
8174
}.to_json
8275

83-
post '/v3/organizations', suspended_request_body, admin_header
76+
post '/v3/organizations', request_body, admin_header
8477
expect(last_response.status).to eq(201)
8578

8679
created_org = Organization.last
@@ -103,58 +96,6 @@ module VCAP::CloudController
10396
}
10497
)
10598
end
106-
107-
context 'when "user_org_creation" feature flag is enabled' do
108-
before do
109-
VCAP::CloudController::FeatureFlag.make(name: 'user_org_creation', enabled: true)
110-
end
111-
112-
it 'lets ALL users create orgs' do
113-
expect {
114-
post '/v3/organizations', request_body, user_header
115-
}.to change {
116-
Organization.count
117-
}.by 1
118-
119-
created_org = Organization.last
120-
121-
expect(last_response.status).to eq(201)
122-
expect(parsed_response).to be_a_response_like(
123-
{
124-
'guid' => created_org.guid,
125-
'created_at' => iso8601,
126-
'updated_at' => iso8601,
127-
'name' => 'org1',
128-
'links' => {
129-
'self' => { 'href' => "#{link_prefix}/v3/organizations/#{created_org.guid}" },
130-
'domains' => { 'href' => "http://api2.vcap.me/v3/organizations/#{created_org.guid}/domains" },
131-
'default_domain' => { 'href' => "http://api2.vcap.me/v3/organizations/#{created_org.guid}/domains/default" },
132-
'quota' => { 'href' => "http://api2.vcap.me/v3/organization_quotas/#{created_org.quota_definition.guid}" }
133-
},
134-
'relationships' => { 'quota' => { 'data' => { 'guid' => created_org.quota_definition.guid } } },
135-
'metadata' => {
136-
'labels' => { 'freaky' => 'friday' },
137-
'annotations' => { 'make' => 'subaru', 'model' => 'xv crosstrek', 'color' => 'orange' }
138-
},
139-
'suspended' => false
140-
}
141-
)
142-
end
143-
it 'gives the user all org roles associated with the new org' do
144-
expect {
145-
post '/v3/organizations', request_body, user_header
146-
}.to change {
147-
Organization.count
148-
}.by 1
149-
150-
created_org = Organization.last
151-
expect(OrganizationManager.first(organization_id: created_org.id, user_id: user.id)).to be_present
152-
expect(OrganizationBillingManager.first(organization_id: created_org.id, user_id: user.id)).to be_present
153-
expect(OrganizationAuditor.first(organization_id: created_org.id, user_id: user.id)).to be_present
154-
expect(OrganizationUser.first(organization_id: created_org.id, user_id: user.id)).to be_present
155-
expect(last_response.status).to eq(201)
156-
end
157-
end
15899
end
159100

160101
describe 'GET /v3/organizations' do

spec/unit/actions/organization_create_spec.rb

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,8 @@ module VCAP::CloudController
88
let(:user_email) { 'user@example.com' }
99
let(:user_audit_info) { UserAuditInfo.new(user_guid: user.guid, user_email: user_email) }
1010
let(:perm_client) { instance_spy(VCAP::CloudController::Perm::Client) }
11-
let(:uaa_client) { instance_double(VCAP::CloudController::UaaClient) }
1211
subject(:org_create) { OrganizationCreate.new(perm_client: perm_client, user_audit_info: user_audit_info) }
1312

14-
before do
15-
allow(CloudController::DependencyLocator.instance).to receive(:uaa_client).and_return(uaa_client)
16-
allow(uaa_client).to receive(:usernames_for_ids).with([user.guid]).and_return(
17-
{ user.guid => 'Ragnaros' }
18-
)
19-
end
20-
2113
context 'when creating a non-suspended organization' do
2214
let(:message) do
2315
VCAP::CloudController::OrganizationUpdateMessage.new({
@@ -36,7 +28,7 @@ module VCAP::CloudController
3628
end
3729

3830
it 'creates a organization' do
39-
organization = org_create.create(message, user)
31+
organization = org_create.create(message)
4032

4133
expect(organization.name).to eq('my-organization')
4234

@@ -52,11 +44,10 @@ module VCAP::CloudController
5244
end
5345

5446
it 'creates an audit event' do
55-
created_org = org_create.create(message, user)
56-
expect(VCAP::CloudController::Event.count).to eq(5)
57-
org_create_event = VCAP::CloudController::Event.find(type: 'audit.organization.create')
58-
expect(org_create_event).to exist
59-
expect(org_create_event.values).to include(
47+
created_org = org_create.create(message)
48+
expect(VCAP::CloudController::Event.count).to eq(1)
49+
event = VCAP::CloudController::Event.first
50+
expect(event.values).to include(
6051
type: 'audit.organization.create',
6152
actor: user_audit_info.user_guid,
6253
actor_type: 'user',
@@ -67,8 +58,8 @@ module VCAP::CloudController
6758
actee_name: 'my-organization',
6859
organization_guid: created_org.guid
6960
)
70-
expect(org_create_event.metadata).to eq({ 'request' => message.audit_hash })
71-
expect(org_create_event.timestamp).to be
61+
expect(event.metadata).to eq({ 'request' => message.audit_hash })
62+
expect(event.timestamp).to be
7263
end
7364
end
7465

@@ -77,7 +68,7 @@ module VCAP::CloudController
7768
name: 'my-organization',
7869
suspended: true
7970
})
80-
organization = org_create.create(message, user)
71+
organization = org_create.create(message)
8172

8273
expect(organization.name).to eq('my-organization')
8374
expect(organization.suspended?).to be true
@@ -92,7 +83,7 @@ module VCAP::CloudController
9283

9384
message = VCAP::CloudController::OrganizationUpdateMessage.new(name: 'foobar')
9485
expect {
95-
org_create.create(message, user)
86+
org_create.create(message)
9687
}.to raise_error(OrganizationCreate::Error, 'blork is busted')
9788
end
9889

@@ -106,7 +97,7 @@ module VCAP::CloudController
10697
it 'raises a human-friendly error' do
10798
message = VCAP::CloudController::OrganizationUpdateMessage.new(name: name)
10899
expect {
109-
org_create.create(message, user)
100+
org_create.create(message)
110101
}.to raise_error(OrganizationCreate::Error, "Organization '#{name}' already exists.")
111102
end
112103
end

0 commit comments

Comments
 (0)