Skip to content
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

Remove dead code #806

Open
wants to merge 14 commits into
base: master
Choose a base branch
from
6 changes: 1 addition & 5 deletions app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,7 @@ def update_permissions
return
end

if params[:pinned]
User.find(params[:user_id]).add_pinned_role params[:role]
else
User.find(params[:user_id]).add_role params[:role]
end
User.find(params[:user_id]).add_role params[:role]
else
User.find(params[:user_id]).remove_role params[:role]
end
Expand Down
1 change: 0 additions & 1 deletion app/controllers/api_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

class APIController < ApplicationController
before_action :verify_key, except: %i[filter_generator api_docs filter_fields calculate_filter]
before_action :verify_trusted_key, only: [:regex_search]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method has been deleted long before.

before_action :set_pagesize, except: %i[filter_generator api_docs]
before_action :verify_write_token, only: %i[create_feedback report_post spam_flag add_domain_tag]
skip_before_action :verify_authenticity_token, only: %i[posts_by_url create_feedback report_post spam_flag post_deleted add_domain_tag
Expand Down
2 changes: 0 additions & 2 deletions app/controllers/dumps_controller.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# frozen_string_literal: true

class DumpsController < ApplicationController
before_action :set_dump, only: %i[show edit update destroy]

Copy link
Contributor Author

@user12986714 user12986714 Sep 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The four methods in only clause does not exist.

# GET /dumps
# GET /dumps.json
def index
Expand Down
20 changes: 3 additions & 17 deletions app/controllers/smoke_detectors_controller.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# frozen_string_literal: true

class SmokeDetectorsController < ApplicationController
before_action :authenticate_user!, except: %i[audits check_token]
before_action :verify_admin, except: %i[audits force_failover force_pull mine token_regen new create check_token]
before_action :authenticate_user!, except: :audits
before_action :verify_admin, except: %i[audits force_failover force_pull mine token_regen new create]
before_action :verify_blacklist_manager, only: %i[force_failover force_pull]
before_action :verify_smoke_detector_runner, only: %i[mine token_regen new create]
before_action :set_smoke_detector, except: %i[audits mine new create check_token]
before_action :set_smoke_detector, except: %i[audits mine new create]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think Helios is still active but this may need to be reverted.


def destroy
unless current_user.present? && (current_user.has_role?(:admin) || current_user.id == @smoke_detector.user_id)
Expand Down Expand Up @@ -83,20 +83,6 @@ def token_regen
redirect_to params[:redirect] || smoke_detector_mine_path
end

# Used by Helios to verify new tokens
def check_token
token = SmokeDetector.where(access_token: params[:token]).first
payload = {
exists: token.present?,
owner_name: token&.user&.username,
location: token&.location,
created_at: token&.created_at,
updated_at: token&.updated_at
}

render json: payload
end
Comment on lines -87 to -98
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I forget when this was introduced, but I think we will want to keep this unless helios is official dead.


private

def set_smoke_detector
Expand Down
21 changes: 0 additions & 21 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -132,27 +132,6 @@ def update_mod_sites
redirect_to dev_user_path(@user)
end

def migrate_token_confirmation
return unless params[:state] != Rails.cache.fetch("token_migration_state/#{current_user.id}")
flash[:danger] = "It looks like you didn't actually authenticate! It might still work, but I don't think it will."
end

def migrate_token
state = Rails.cache.fetch("token_migration_state/#{current_user.id}")
res = HTTParty.get("#{AppConfig['token_store']['host']}/auth/confirm",
headers: { 'X-API-Key': AppConfig['token_store']['key'] },
query: { account_id: current_user.stack_exchange_account_id, state: state })
Rails.logger.info res
if params[:state] == state && JSON.parse(res.body)['token_exists'] && current_user.update(write_authenticated: true)
flash[:success] = 'Your registration was completed sucessfully!'
elsif params[:error].present?
flash[:danger] = "Got an error: #{params[:error]}: #{params[:error_description]}"
else
flash[:danger] = "We couldn't complete your registration. Please try again."
end
redirect_to edit_user_registration_path
end

private

def set_user
Expand Down
19 changes: 0 additions & 19 deletions app/javascript/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,25 +45,6 @@ onLoad(() => {
});
});

$('input.pin-checkbox').change(function () {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pinned roles are indistinguishable from non-pinned roles.

const $this = $(this);
$this.disabled = true;
$.ajax({
type: 'put',
data: {
permitted: $this.is(':checked'),
pinned: true,
user_id: $this.data('user-id'),
role: $this.data('role')
},
dataType: 'json',
url: '/admin/permissions/update',
success() {
$this.disabled = false;
}
});
});

$('input.trust-checkbox').change(function () {
const $this = $(this);
$this.disabled = true;
Expand Down
15 changes: 0 additions & 15 deletions app/models/application_record.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,6 @@
class ApplicationRecord < ActiveRecord::Base
self.abstract_class = true

def self.fuzzy_search(term, **cols)
sanitized = sanitize_for_search term, **cols
select(Arel.sql("`#{table_name}`.*, #{sanitized} AS search_score"))
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is never used.

def self.match_search(term, with_search_score: true, **cols)
sanitized = sanitize_for_search term, **cols
if with_search_score
Expand Down Expand Up @@ -69,14 +64,4 @@ def self.mass_habtm(join_table, first_type, second_type, record_pairs)
def self.fields(*names)
names.map { |n| "#{table_name}.#{n}" }
end

def self.full_dump
username = Rails.configuration.database_configuration[Rails.env]['username']
password = Rails.configuration.database_configuration[Rails.env]['password']
host = Rails.configuration.database_configuration[Rails.env]['host']
`#{Rails.root}/dump/dump.sh "#{username}" "#{password}" "#{host}"`

Dump.destroy_all
Dump.create file: File.open(Dir.glob('dumps/*')[0])
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bugged and no longer used.

end
5 changes: 0 additions & 5 deletions app/models/reason.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,4 @@ def both_percentage

count.to_f / posts.count
end

# Attempt to use cached post_count if it's available (included in the dashboard/index query)
def fast_post_count
try(:post_count) || posts.count
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is never used.

end
14 changes: 0 additions & 14 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,20 +250,6 @@ def moderator?
moderator_sites.any?
end

def add_pinned_role(name)
role = Role.find_by name: name
if UsersRole.where(user: self, role: role).exists?
UsersRole.where(user: self, role: role).order(:user_id).last.update(pinned: true)
else
UsersRole.create(user: self, role: role, pinned: true)
end
end

# rubocop:disable Style/PredicateName
def has_pinned_role?(role)
UsersRole.where(user: self, role: Role.find_by(name: role), pinned: true).exists?
end

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indistinguishable

def can_use_regex_search?
(has_role? :reviewer) || moderator_sites.any?
end
Expand Down
4 changes: 0 additions & 4 deletions app/views/users/migrate_token_confirmation.html.erb

This file was deleted.

1 change: 0 additions & 1 deletion config/config.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,6 @@ common: &common
- users.encrypted_password
- users.reset_password_token
- users.reset_password_sent_at
- users.encrypted_api_token
- users.two_factor_token
- users.salt
- users.iv
Expand Down
4 changes: 0 additions & 4 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,6 @@
post ':id/force_failover', to: 'smoke_detectors#force_failover', as: :smoke_detector_force_failover
post ':id/force_pull', to: 'smoke_detectors#force_pull', as: :smoke_detector_force_pull
get 'audits', to: 'smoke_detectors#audits'
get 'check_token/:token', to: 'smoke_detectors#check_token'
end

scope 'spammers' do
Expand Down Expand Up @@ -470,9 +469,6 @@

get 'denied', to: 'users#missing_privileges', as: :missing_privileges

get 'migrate_token', to: 'users#migrate_token_confirmation', as: :migrate_token_confirmation
post 'migrate_token', to: 'users#migrate_token', as: :migrate_token

get ':id', to: 'users#show', as: :dev_user, constraints: { id: /-?\d+/ }
post ':id/update_ids', to: 'users#refresh_ids', as: :update_user_chat_ids
post ':id/reset_pass', to: 'users#send_password_reset', as: :send_password_reset
Expand Down
7 changes: 7 additions & 0 deletions db/migrate/20200906202319_drop_table_dumps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class DropTableDumps < ActiveRecord::Migration[5.2]
def change
execute 'DROP TABLE dumps'
end
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Table no longer being used after Rails based full dump being disabled.

end
8 changes: 8 additions & 0 deletions db/migrate/20200906202320_remove_api_token_legacy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# frozen_string_literal: true

class RemoveAPITokenLegacy < ActiveRecord::Migration[5.2]
def change
remove_column :users, :encrypted_api_token_legacy
remove_column :users, :token_migrated_legacy
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Legacy column; may introduce security risks.

end
end
7 changes: 7 additions & 0 deletions db/migrate/20200907140530_remove_pinned_role.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# frozen_string_literal: true

class RemovePinnedRole < ActiveRecord::Migration[5.2]
def change
remove_column :users_roles, :pinned
end
end
19 changes: 0 additions & 19 deletions dump/dump.sh

This file was deleted.

21 changes: 0 additions & 21 deletions dump/redact.sql

This file was deleted.