Skip to content

Commit

Permalink
DEV: Apply syntax_tree formatting to lib/*
Browse files Browse the repository at this point in the history
  • Loading branch information
davidtaylorhq committed Jan 9, 2023
1 parent b0fda61 commit 6417173
Show file tree
Hide file tree
Showing 507 changed files with 16,626 additions and 12,703 deletions.
1 change: 0 additions & 1 deletion .streerc
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
--print-width=100
--plugins=plugin/trailing_comma,disable_ternary
--ignore-files=app/*
--ignore-files=lib/*
4 changes: 1 addition & 3 deletions lib/action_dispatch/session/discourse_cookie_store.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ def initialize(app, options = {})

def set_cookie(request, session_id, cookie)
if Hash === cookie
if SiteSetting.force_https
cookie[:secure] = true
end
cookie[:secure] = true if SiteSetting.force_https
unless SiteSetting.same_site_cookies == "Disabled"
cookie[:same_site] = SiteSetting.same_site_cookies
end
Expand Down
11 changes: 4 additions & 7 deletions lib/admin_confirmation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,15 @@ def create_confirmation
@token = SecureRandom.hex
Discourse.redis.setex("admin-confirmation:#{@target_user.id}", 3.hours.to_i, @token)

payload = {
target_user_id: @target_user.id,
performed_by: @performed_by.id
}
payload = { target_user_id: @target_user.id, performed_by: @performed_by.id }
Discourse.redis.setex("admin-confirmation-token:#{@token}", 3.hours.to_i, payload.to_json)

Jobs.enqueue(
:admin_confirmation_email,
to_address: @performed_by.email,
target_email: @target_user.email,
target_username: @target_user.username,
token: @token
token: @token,
)
end

Expand All @@ -51,8 +48,8 @@ def self.find_by_code(token)
return nil unless json

parsed = JSON.parse(json)
target_user = User.find(parsed['target_user_id'].to_i)
performed_by = User.find(parsed['performed_by'].to_i)
target_user = User.find(parsed["target_user_id"].to_i)
performed_by = User.find(parsed["performed_by"].to_i)

ac = AdminConfirmation.new(target_user, performed_by)
ac.token = token
Expand Down
2 changes: 0 additions & 2 deletions lib/admin_constraint.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

class AdminConstraint

def initialize(options = {})
@require_master = options[:require_master]
end
Expand All @@ -19,5 +18,4 @@ def matches?(request)
def custom_admin_check(request)
true
end

end
86 changes: 47 additions & 39 deletions lib/admin_user_index_query.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

class AdminUserIndexQuery

def initialize(params = {}, klass = User, trust_levels = TrustLevel.levels)
@params = params
@query = initialize_query_with_order(klass)
Expand All @@ -11,24 +10,22 @@ def initialize(params = {}, klass = User, trust_levels = TrustLevel.levels)
attr_reader :params, :trust_levels

SORTABLE_MAPPING = {
'created' => 'created_at',
'last_emailed' => "COALESCE(last_emailed_at, to_date('1970-01-01', 'YYYY-MM-DD'))",
'seen' => "COALESCE(last_seen_at, to_date('1970-01-01', 'YYYY-MM-DD'))",
'username' => 'username',
'email' => 'email',
'trust_level' => 'trust_level',
'days_visited' => 'user_stats.days_visited',
'posts_read' => 'user_stats.posts_read_count',
'topics_viewed' => 'user_stats.topics_entered',
'posts' => 'user_stats.post_count',
'read_time' => 'user_stats.time_read'
"created" => "created_at",
"last_emailed" => "COALESCE(last_emailed_at, to_date('1970-01-01', 'YYYY-MM-DD'))",
"seen" => "COALESCE(last_seen_at, to_date('1970-01-01', 'YYYY-MM-DD'))",
"username" => "username",
"email" => "email",
"trust_level" => "trust_level",
"days_visited" => "user_stats.days_visited",
"posts_read" => "user_stats.posts_read_count",
"topics_viewed" => "user_stats.topics_entered",
"posts" => "user_stats.post_count",
"read_time" => "user_stats.time_read",
}

def find_users(limit = 100)
page = params[:page].to_i - 1
if page < 0
page = 0
end
page = 0 if page < 0
find_users_query.limit(limit).offset(page * limit)
end

Expand All @@ -37,7 +34,13 @@ def count_users
end

def custom_direction
Discourse.deprecate(":ascending is deprecated please use :asc instead", output_in_test: true, drop_from: '2.9.0') if params[:ascending]
if params[:ascending]
Discourse.deprecate(
":ascending is deprecated please use :asc instead",
output_in_test: true,
drop_from: "2.9.0",
)
end
asc = params[:asc] || params[:ascending]
asc.present? && asc ? "ASC" : "DESC"
end
Expand All @@ -47,7 +50,7 @@ def initialize_query_with_order(klass)

custom_order = params[:order]
if custom_order.present? &&
without_dir = SORTABLE_MAPPING[custom_order.downcase.sub(/ (asc|desc)$/, '')]
without_dir = SORTABLE_MAPPING[custom_order.downcase.sub(/ (asc|desc)$/, "")]
order << "#{without_dir} #{custom_direction}"
end

Expand All @@ -61,13 +64,9 @@ def initialize_query_with_order(klass)
order << "users.username"
end

query = klass
.includes(:totps)
.order(order.reject(&:blank?).join(","))
query = klass.includes(:totps).order(order.reject(&:blank?).join(","))

unless params[:stats].present? && params[:stats] == false
query = query.includes(:user_stat)
end
query = query.includes(:user_stat) unless params[:stats].present? && params[:stats] == false

query = query.joins(:primary_email) if params[:show_emails] == "true"

Expand All @@ -77,32 +76,44 @@ def initialize_query_with_order(klass)
def filter_by_trust
levels = trust_levels.map { |key, _| key.to_s }
if levels.include?(params[:query])
@query.where('trust_level = ?', trust_levels[params[:query].to_sym])
@query.where("trust_level = ?", trust_levels[params[:query].to_sym])
end
end

def filter_by_query_classification
case params[:query]
when 'staff' then @query.where("admin or moderator")
when 'admins' then @query.where(admin: true)
when 'moderators' then @query.where(moderator: true)
when 'silenced' then @query.silenced
when 'suspended' then @query.suspended
when 'pending' then @query.not_suspended.where(approved: false, active: true)
when 'staged' then @query.where(staged: true)
when "staff"
@query.where("admin or moderator")
when "admins"
@query.where(admin: true)
when "moderators"
@query.where(moderator: true)
when "silenced"
@query.silenced
when "suspended"
@query.suspended
when "pending"
@query.not_suspended.where(approved: false, active: true)
when "staged"
@query.where(staged: true)
end
end

def filter_by_search
if params[:email].present?
return @query.joins(:primary_email).where('user_emails.email = ?', params[:email].downcase)
return @query.joins(:primary_email).where("user_emails.email = ?", params[:email].downcase)
end

filter = params[:filter]
if filter.present?
filter = filter.strip
if ip = IPAddr.new(filter) rescue nil
@query.where('ip_address <<= :ip OR registration_ip_address <<= :ip', ip: ip.to_cidr_s)
if ip =
begin
IPAddr.new(filter)
rescue StandardError
nil
end
@query.where("ip_address <<= :ip OR registration_ip_address <<= :ip", ip: ip.to_cidr_s)
else
@query.filter_by_username_or_email(filter)
end
Expand All @@ -111,14 +122,12 @@ def filter_by_search

def filter_by_ip
if params[:ip].present?
@query.where('ip_address = :ip OR registration_ip_address = :ip', ip: params[:ip].strip)
@query.where("ip_address = :ip OR registration_ip_address = :ip", ip: params[:ip].strip)
end
end

def filter_exclude
if params[:exclude].present?
@query.where('users.id != ?', params[:exclude])
end
@query.where("users.id != ?", params[:exclude]) if params[:exclude].present?
end

# this might not be needed in rails 4 ?
Expand All @@ -134,5 +143,4 @@ def find_users_query
append filter_by_search
@query
end

end
2 changes: 0 additions & 2 deletions lib/age_words.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# frozen_string_literal: true

module AgeWords

def self.age_words(secs)
if secs.blank?
"&mdash;"
Expand All @@ -10,5 +9,4 @@ def self.age_words(secs)
FreedomPatches::Rails4.distance_of_time_in_words(now, now + secs)
end
end

end
18 changes: 7 additions & 11 deletions lib/archetype.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,19 @@ def initialize(id, options)
end

def attributes
{
id: @id,
options: @options
}
{ id: @id, options: @options }
end

def self.default
'regular'
"regular"
end

def self.private_message
'private_message'
"private_message"
end

def self.banner
'banner'
"banner"
end

def self.list
Expand All @@ -40,8 +37,7 @@ def self.register(name, options = {})
end

# default archetypes
register 'regular'
register 'private_message'
register 'banner'

register "regular"
register "private_message"
register "banner"
end
21 changes: 11 additions & 10 deletions lib/auth.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
# frozen_string_literal: true

module Auth; end
module Auth
end

require 'auth/auth_provider'
require 'auth/result'
require 'auth/authenticator'
require 'auth/managed_authenticator'
require 'auth/facebook_authenticator'
require 'auth/github_authenticator'
require 'auth/twitter_authenticator'
require 'auth/google_oauth2_authenticator'
require 'auth/discord_authenticator'
require "auth/auth_provider"
require "auth/result"
require "auth/authenticator"
require "auth/managed_authenticator"
require "auth/facebook_authenticator"
require "auth/github_authenticator"
require "auth/twitter_authenticator"
require "auth/google_oauth2_authenticator"
require "auth/discord_authenticator"
45 changes: 36 additions & 9 deletions lib/auth/auth_provider.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,60 @@ def initialize(params = {})
end

def self.auth_attributes
[:authenticator, :pretty_name, :title, :message, :frame_width, :frame_height,
:pretty_name_setting, :title_setting, :enabled_setting, :full_screen_login, :full_screen_login_setting,
:custom_url, :background_color, :icon]
%i[
authenticator
pretty_name
title
message
frame_width
frame_height
pretty_name_setting
title_setting
enabled_setting
full_screen_login
full_screen_login_setting
custom_url
background_color
icon
]
end

attr_accessor(*auth_attributes)

def enabled_setting=(val)
Discourse.deprecate("(#{authenticator.name}) enabled_setting is deprecated. Please define authenticator.enabled? instead", drop_from: '2.9.0')
Discourse.deprecate(
"(#{authenticator.name}) enabled_setting is deprecated. Please define authenticator.enabled? instead",
drop_from: "2.9.0",
)
@enabled_setting = val
end

def background_color=(val)
Discourse.deprecate("(#{authenticator.name}) background_color is no longer functional. Please use CSS instead", drop_from: '2.9.0')
Discourse.deprecate(
"(#{authenticator.name}) background_color is no longer functional. Please use CSS instead",
drop_from: "2.9.0",
)
end

def full_screen_login=(val)
Discourse.deprecate("(#{authenticator.name}) full_screen_login is now forced. The full_screen_login parameter can be removed from the auth_provider.", drop_from: '2.9.0')
Discourse.deprecate(
"(#{authenticator.name}) full_screen_login is now forced. The full_screen_login parameter can be removed from the auth_provider.",
drop_from: "2.9.0",
)
end

def full_screen_login_setting=(val)
Discourse.deprecate("(#{authenticator.name}) full_screen_login is now forced. The full_screen_login_setting parameter can be removed from the auth_provider.", drop_from: '2.9.0')
Discourse.deprecate(
"(#{authenticator.name}) full_screen_login is now forced. The full_screen_login_setting parameter can be removed from the auth_provider.",
drop_from: "2.9.0",
)
end

def message=(val)
Discourse.deprecate("(#{authenticator.name}) message is no longer used because all logins are full screen. It should be removed from the auth_provider", drop_from: '2.9.0')
Discourse.deprecate(
"(#{authenticator.name}) message is no longer used because all logins are full screen. It should be removed from the auth_provider",
drop_from: "2.9.0",
)
end

def name
Expand All @@ -47,5 +75,4 @@ def can_connect
def can_revoke
authenticator.can_revoke?
end

end
4 changes: 2 additions & 2 deletions lib/auth/current_user_provider.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

module Auth; end
module Auth
end
class Auth::CurrentUserProvider

# do all current user initialization here
def initialize(env)
raise NotImplementedError
Expand Down
Loading

0 comments on commit 6417173

Please sign in to comment.