diff --git a/.rubocop.yml b/.rubocop.yml index 670f9c9fb4..10ada77ef8 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -152,6 +152,9 @@ Style/FrozenStringLiteralComment: to help transition to frozen string literals by default. Enabled: false +Style/GlobalVars: + Enabled: false + Style/GuardClause: Enabled: false diff --git a/app/commands/central_user_commands.rb b/app/commands/central_user_commands.rb index 653ed50372..12468f9955 100644 --- a/app/commands/central_user_commands.rb +++ b/app/commands/central_user_commands.rb @@ -51,10 +51,7 @@ class CentralUserCommands logger.info(message: 'Processing :delete_user', class_name: self.class.name) if user - user.set_force_destroy if [true, 'true'].include?(payload[:force]) - user.destroy - logger.info(message: 'User deleted', current_user: user.username, class_name: self.class.name) - notifications_topic.publish(:user_deleted, { username: user.username }) + process_user_deletion(user) else logger.warn(message: 'User not found', user_id: payload[:id], class_name: self.class.name) notifications_topic.publish(:user_deleted, {}) @@ -74,4 +71,13 @@ class CentralUserCommands end end + private + + def process_user_deletion(user) + user.set_force_destroy if [true, 'true'].include?(payload[:force]) + user.destroy + logger.info(message: 'User deleted', current_user: user.username, class_name: self.class.name) + notifications_topic.publish(:user_deleted, { username: user.username }) + end + end diff --git a/spec/commands/central_user_commands_spec.rb b/spec/commands/central_user_commands_spec.rb index 1c6930305f..04f3320676 100644 --- a/spec/commands/central_user_commands_spec.rb +++ b/spec/commands/central_user_commands_spec.rb @@ -50,6 +50,7 @@ describe CentralUserCommands do } end + # rubocop:disable RSpec/MultipleExpectations it 'updates the corresponding attributes' do central_user_commands.update_user(message) @@ -79,6 +80,7 @@ describe CentralUserCommands do expect(user.disqus_shortname).to eq('abc') expect(user.builder_enabled).to eq(true) end + # rubocop:enable RSpec/MultipleExpectations it 'successfully handles updates of boolean flags' do central_user_commands.update_user( diff --git a/spec/support/shared_entities_spec_helper.rb b/spec/support/shared_entities_spec_helper.rb index 4476325563..96ed2b21ca 100644 --- a/spec/support/shared_entities_spec_helper.rb +++ b/spec/support/shared_entities_spec_helper.rb @@ -55,14 +55,18 @@ module SharedEntitiesSpecHelper def share_table_with_organization(table, owner, organization) bypass_named_maps - headers = {'CONTENT_TYPE' => 'application/json'} + headers = { 'CONTENT_TYPE' => 'application/json' } perm_id = table.table_visualization.permission.id - params = { acl: [{ type: Carto::Permission::TYPE_ORGANIZATION, - entity: { id: organization.id }, - access: Carto::Permission::ACCESS_READONLY - }] - } + params = { + acl: [ + { + type: Carto::Permission::TYPE_ORGANIZATION, + entity: { id: organization.id }, + access: Carto::Permission::ACCESS_READONLY + } + ] + } url = api_v1_permissions_update_url(user_domain: owner.username, api_key: owner.api_key, id: perm_id) put url, params.to_json, headers last_response.status.should == 200 @@ -78,11 +82,15 @@ module SharedEntitiesSpecHelper owner = visualization.user perm_id = visualization.permission.id - params = { acl: [{ type: Carto::Permission::TYPE_USER, - entity: { id: user.id }, - access: access - }] - } + params = { + acl: [ + { + type: Carto::Permission::TYPE_USER, + entity: { id: user.id }, + access: access + } + ] + } url = api_v1_permissions_update_url(user_domain: owner.username, api_key: owner.api_key, id: perm_id) put_json url, params do |response| response.status.should == 200