Skip to content

Commit

Permalink
Merge pull request #15805 from CartoDB/feature/ch98420/store-the-ip-f…
Browse files Browse the repository at this point in the history
…irewall-information-in-redis

Now every user manages its own dbdirect IPs
  • Loading branch information
Jorge Tarrero authored Sep 3, 2020
2 parents 7b8d56d + 1739a98 commit 502062d
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 21 deletions.
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ Development
- None yet

### Bug fixes / enhancements

* Now every user manages its own dbdirect IPs, regardless of being a organization user [#15805](https://github.com/CartoDB/cartodb/pull/15805)
* Add a script to measure Sequel model LOC [#15803](https://github.com/CartoDB/cartodb/pull/15803)

4.41.0 (2020-09-01)
Expand Down
18 changes: 3 additions & 15 deletions app/models/carto/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -307,24 +307,12 @@ def dbdirect_effective_ips

def dbdirect_effective_ips=(ips)
ips ||= []
bearer = dbdirect_bearer
if bearer.dbdirect_ip
bearer.dbdirect_ip.update!(ips: ips)
else
bearer.create_dbdirect_ip!(ips: ips)
end
reload
dbdirect_ip ? dbdirect_ip.update!(ips: ips) : create_dbdirect_ip!(ips: ips)
end

def dbdirect_effective_ip
dbdirect_bearer.dbdirect_ip
end

def dbdirect_bearer
if organization.present? && organization.owner != self
organization.owner.reload
else
reload
end
reload.dbdirect_ip
end

private
Expand Down
9 changes: 4 additions & 5 deletions spec/requests/carto/api/dbdirect_ips_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ def rule(id)
end
end

it 'IP changes affect all the organization members' do
it 'IP changes affect only to org user, not org admin' do
ips = ['100.20.30.40']
params = {
ips: ips,
Expand All @@ -207,10 +207,9 @@ def rule(id)
expect(response.status).to eq(201)
expect(response.body[:ips]).to eq ips
expect(@org_user.reload.dbdirect_effective_ips).to eq ips
expect(@org_owner.reload.dbdirect_effective_ips).to eq ips
expect(@dbdirect_metadata.get(@org_owner.username)).to eq ips
expect(@dbdirect_metadata.get(@carto_user1.username)).to be_empty
expect(@dbdirect_metadata.get(@org_user.username)).to be_empty
expect(@org_owner.reload.dbdirect_effective_ips).to be_empty
expect(@dbdirect_metadata.get(@org_owner.username)).to be_empty
expect(@dbdirect_metadata.get(@org_user.username)).to eq ips
end
end
end
Expand Down

0 comments on commit 502062d

Please sign in to comment.