Skip to content

Commit facf57c

Browse files
committed
💚 More fixes
1 parent 8db857f commit facf57c

File tree

6 files changed

+35
-38
lines changed

6 files changed

+35
-38
lines changed

.rubocop_gradual.lock

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,6 @@
88
"app/controllers/masq/sessions_controller.rb:3600302919": [
99
[39, 21, 3, "Style/AndOr: Use `&&` instead of `and`.", 193409806]
1010
],
11-
"app/models/masq/persona.rb:3585878101": [
12-
[14, 5, 55, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1041090622],
13-
[18, 5, 142, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 3038409932],
14-
[55, 5, 3, "Lint/IneffectiveAccessModifier: `private` (on line 52) does not make singleton methods private. Use `private_class_method` or `private` inside a `class << self` block instead.", 193404514],
15-
[55, 5, 78, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 2563415249]
16-
],
17-
"app/models/masq/signup.rb:1186383472": [
18-
[7, 5, 126, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 1071524745]
19-
],
2011
"lib/masq/authenticated_system.rb:2956957840": [
2112
[95, 5, 3, "Lint/IneffectiveAccessModifier: `protected` (on line 3) does not make singleton methods protected. Use `protected` inside a `class << self` block instead.", 193404514],
2213
[95, 5, 111, "Style/ClassMethodsDefinitions: Use `class << self` to define a class method.", 4258707989],

app/models/masq/account.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,15 @@ def find_and_activate!(activation_code)
5353
# Authenticates a user by their login name and password.
5454
# Returns the user or nil.
5555
def authenticate(login, password, basic_auth_used = false)
56-
a = Account.find_by(login: login)
56+
a = find_by(login: login)
5757
if a.nil? && Masq::Engine.config.masq["create_auth_ondemand"]["enabled"]
5858
# Need to set some password - but is never used
5959
pw = if Masq::Engine.config.masq["create_auth_ondemand"]["random_password"]
6060
SecureRandom.hex(13)
6161
else
6262
password
6363
end
64-
signup = Signup.create_account!(
64+
signup = Masq::Signup.create_account!(
6565
login: login,
6666
password: pw,
6767
password_confirmation: pw,
@@ -144,15 +144,15 @@ def authenticated?(password)
144144
elsif password.length < 50 && !(yubico_identity? && yubikey_mandatory?)
145145
encrypt(password) == crypted_password
146146
elsif Masq::Engine.config.masq["can_use_yubikey"]
147-
password, yubico_otp = Account.split_password_and_yubico_otp(password)
147+
password, yubico_otp = self.class.split_password_and_yubico_otp(password)
148148
@authenticated_with_yubikey = yubikey_authenticated?(yubico_otp) if encrypt(password) == crypted_password
149149
end
150150
end
151151

152152
# Is the Yubico OTP valid and belongs to this account?
153153
def yubikey_authenticated?(otp)
154-
if yubico_identity? && Account.verify_yubico_otp(otp)
155-
(Account.extract_yubico_identity_from_otp(otp) == yubico_identity)
154+
if yubico_identity? && self.class.verify_yubico_otp(otp)
155+
(self.class.extract_yubico_identity_from_otp(otp) == yubico_identity)
156156
else
157157
false
158158
end
@@ -163,8 +163,8 @@ def authenticated_with_yubikey?
163163
end
164164

165165
def associate_with_yubikey(otp)
166-
if Account.verify_yubico_otp(otp)
167-
self.yubico_identity = Account.extract_yubico_identity_from_otp(otp)
166+
if self.class.verify_yubico_otp(otp)
167+
self.yubico_identity = self.class.extract_yubico_identity_from_otp(otp)
168168
save(validate: false)
169169
else
170170
false
@@ -238,7 +238,7 @@ def make_password_reset_code
238238
end
239239

240240
def deliver_forgot_password
241-
AccountMailer.forgot_password(self).deliver_now if recently_forgot_password?
241+
Masq::AccountMailer.forgot_password(self).deliver_now if recently_forgot_password?
242242
end
243243
end
244244
end

app/models/masq/persona.rb

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,24 @@ class Persona < ActiveRecord::Base
1111

1212
# attr_protected :account_id, :deletable
1313

14-
def self.properties
15-
Persona.mappings.keys
16-
end
14+
class << self
15+
def properties
16+
mappings.keys
17+
end
18+
19+
def attribute_name_for_type_uri(type_uri)
20+
prop = mappings.detect { |i| i[1].include?(type_uri) }
21+
prop ? prop[0] : nil
22+
end
1723

18-
def self.attribute_name_for_type_uri(type_uri)
19-
prop = mappings.detect { |i| i[1].include?(type_uri) }
20-
prop ? prop[0] : nil
24+
# Mappings for SReg names and AX Type URIs to attributes
25+
def mappings
26+
Masq::Engine.config.masq["attribute_mappings"]
27+
end
2128
end
2229

30+
public
31+
2332
# Returns the personas attribute for the given SReg name or AX Type URI
2433
def property(type)
2534
prop = Persona.mappings.detect { |i| i[1].include?(type) }
@@ -48,12 +57,5 @@ def date_of_birth=(dob)
4857
def check_deletable!
4958
raise ActiveRecord::RecordNotDestroyed unless deletable
5059
end
51-
52-
private
53-
54-
# Mappings for SReg names and AX Type URIs to attributes
55-
def self.mappings
56-
Masq::Engine.config.masq["attribute_mappings"]
57-
end
5860
end
5961
end

app/models/masq/site.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class Site < ActiveRecord::Base
1010

1111
# Sets the release policies by first deleting the old ones and
1212
# then appending a new one for every given sreg and ax property.
13-
# This setter is used to set the attributes recieved from the
13+
# This setter is used to set the attributes received from the
1414
# update site form, so it gets passed AX and SReg properties.
1515
# To be backwards compatible (SReg seems to be obsolete now that
1616
# there is AX), SReg properties get a type_identifier matching
@@ -53,7 +53,7 @@ def sreg_properties
5353
end
5454

5555
# Returns a hash with all released AX properties.
56-
# AX properties have an URL as type_identifier.
56+
# AX properties have a URL as type_identifier.
5757
def ax_properties
5858
props = {}
5959
release_policies.each do |rp|

lib/masq.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ module Masq
3434
require_relative "masq/active_record_openid_store/association"
3535
require_relative "masq/active_record_openid_store/nonce"
3636
require_relative "masq/active_record_openid_store/openid_ar_store"
37+
require_relative "masq/signup"
3738

3839
# Ensure version is configured before loading the rest of the library
3940
Masq::Version.class_eval do

app/models/masq/signup.rb renamed to lib/masq/signup.rb

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ module Masq
44
class Signup
55
attr_accessor :account
66

7-
def self.create_account!(attrs = {})
8-
signup = Signup.new(attrs)
9-
signup.send(:create_account!)
10-
signup
7+
class << self
8+
def create_account!(attrs = {})
9+
factory = new(attrs)
10+
factory.send(:create_account!)
11+
factory
12+
end
1113
end
1214

1315
def succeeded?
@@ -21,16 +23,17 @@ def send_activation_email?
2123
protected
2224

2325
def initialize(attrs = {})
24-
self.account = Account.new(attrs)
26+
self.account = Masq::Account.new(attrs)
2527
end
2628

2729
def create_account!
2830
return false unless account.valid?
31+
2932
make_activation_code if send_activation_email?
3033
account.save!
3134
make_default_persona
3235
if send_activation_email?
33-
AccountMailer.signup_notification(account).deliver_now
36+
Masq::AccountMailer.signup_notification(account).deliver_now
3437
else
3538
account.activate!
3639
end

0 commit comments

Comments
 (0)