Skip to content

Commit

Permalink
Merge pull request #15995 from CartoDB/feature/ch124513/phl-disable-m…
Browse files Browse the repository at this point in the history
…e-page

Add feature flag to disable public profile for a given user
  • Loading branch information
amiedes authored Dec 22, 2020
2 parents d4483ce + 820cafa commit 758538d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ sudo make install
- Maps API client now honors 429 Too Many Requests error [#16025](https://github.com/CartoDB/cartodb/pull/16025)
- Fix a loop between our logger and rollbar [#16026](https://github.com/CartoDB/cartodb/pull/16026)
- Make the MessageBroker subscriber PIDFILE check more resilient [#16022](https://github.com/CartoDB/cartodb/pull/16022)
- Public profile can be disabled via Feature Flag [#15982](https://github.com/CartoDB/cartodb/pull/15995)

4.44.0 (2020-11-20)
-------------------
Expand Down
15 changes: 15 additions & 0 deletions app/controllers/admin/pages_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,12 +95,16 @@ def sitemap
end

def datasets
render_403 && return if public_profile_disabled?

datasets = CartoDB::ControllerFlows::Public::Datasets.new(self)
content = CartoDB::ControllerFlows::Public::Content.new(self, request, datasets)
content.render()
end

def maps
render_403 && return if public_profile_disabled?

maps = CartoDB::ControllerFlows::Public::Maps.new(self)
content = CartoDB::ControllerFlows::Public::Content.new(self, request, maps)
content.render()
Expand All @@ -117,6 +121,8 @@ def public
def user_feed
# The template of this endpoint get the user_feed data calling
# to another endpoint in the front-end part
render_403 && return if public_profile_disabled?

if @viewed_user.nil?
username = CartoDB.extract_subdomain(request).strip.downcase
org = get_organization_if_exists(username)
Expand Down Expand Up @@ -502,4 +508,13 @@ def website_url(url)
end
end

private

def public_profile_disabled?
if !@viewed_user.nil? && current_user != @viewed_user
user = Carto::User.find_by(id: @viewed_user.id)
user.has_feature_flag?('disable_public_profile_page')
end
end

end
4 changes: 4 additions & 0 deletions app/models/carto/helpers/user_commons.rb
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ def activate_feature_flag!(feature_flag)
def update_feature_flags(feature_flag_ids = nil)
return unless feature_flag_ids

# Clear blank strings as things like [''] get parsed into SQL NULL values by ActiveRecord
# which will cause the query to return no records
feature_flag_ids = feature_flag_ids.select(&:present?)

self_feature_flags_user.where.not(feature_flag_id: feature_flag_ids).destroy_all

new_feature_flags_ids = feature_flag_ids - self_feature_flags_user.pluck(:feature_flag_id)
Expand Down
6 changes: 6 additions & 0 deletions spec/helpers/user_commons_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,12 @@

expect(user.reload.feature_flags).not_to be_empty
end

it 'ignores blank strings passed as arguments' do
user.update_feature_flags([''])

expect(user.feature_flags).to be_empty
end
end
end

Expand Down

0 comments on commit 758538d

Please sign in to comment.