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
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
24 changes: 0 additions & 24 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 @@ -37,15 +32,6 @@ def self.sanitize_for_search(term, **cols)
ActiveRecord::Base.send(:sanitize_sql_array, ["MATCH (#{cols}) AGAINST (? IN BOOLEAN MODE)", term])
end

# From http://stackoverflow.com/questions/6591722/how-to-generate-fixtures-based-on-my-development-database
def dump_fixture
fixture_file = "#{Rails.root}/test/fixtures/#{self.class.table_name}.yml"
File.open(fixture_file, 'a') do |f|
f.puts({ "#{self.class.table_name.singularize}_#{id}" => attributes }
.to_yaml.sub!(/---\s?/, "\n"))
end
end

user12986714 marked this conversation as resolved.
Show resolved Hide resolved
def self.sanitize_like(unsafe, *args)
sanitize_sql_like unsafe, *args
end
Expand All @@ -69,14 +55,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
6 changes: 0 additions & 6 deletions app/views/dashboard/index.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,3 @@
<form role="search">
<div class="form-group">
<input type="text" id="search" class="form-control" placeholder="Search reasons">
</div>
</form>

user12986714 marked this conversation as resolved.
Show resolved Hide resolved
<p>
<strong><%= @reasons.count %></strong>
<%= "filter".pluralize(@reasons.count) %> have caught
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
5 changes: 5 additions & 0 deletions db/migrate/20200906202319_drop_table_dumps.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

class DropTableDumps < ActiveRecord::Migration[5.2]
execute 'DROP TABLE dumps'
end
6 changes: 6 additions & 0 deletions db/migrate/20200906202320_remove_api_token_legacy.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# frozen_string_literal: true

class RemoveAPITokenLegacy < ActiveRecord::Migration[5.2]
remove_column :users, :encrypted_api_token_legacy
remove_column :users, :token_migrated_legacy
end