1- require 'devise/orm/active_record'
2- require 'userstamp'
1+ # frozen_string_literal: true
2+
3+ require "devise/orm/active_record"
4+ require "userstamp"
35
46module Alchemy
57 class User < ActiveRecord ::Base
@@ -12,7 +14,7 @@ class User < ActiveRecord::Base
1214 :password ,
1315 :password_confirmation ,
1416 :send_credentials ,
15- :tag_list
17+ :tag_list ,
1618 ]
1719
1820 devise *Alchemy . devise_modules
@@ -29,9 +31,9 @@ class User < ActiveRecord::Base
2931 # Unlock all locked pages before destroy.
3032 before_destroy :unlock_pages!
3133
32- scope :admins , -> { where ( arel_table [ :alchemy_roles ] . matches ( ' %admin%' ) ) }
33- scope :logged_in , -> { where ( ' last_request_at > ?' , logged_in_timeout . seconds . ago ) }
34- scope :logged_out , -> { where ( ' last_request_at is NULL or last_request_at <= ?' , logged_in_timeout . seconds . ago ) }
34+ scope :admins , -> { where ( arel_table [ :alchemy_roles ] . matches ( " %admin%" ) ) }
35+ scope :logged_in , -> { where ( " last_request_at > ?" , logged_in_timeout . seconds . ago ) }
36+ scope :logged_out , -> { where ( " last_request_at is NULL or last_request_at <= ?" , logged_in_timeout . seconds . ago ) }
3537
3638 ROLES = Config . get ( :user_roles )
3739
@@ -51,10 +53,7 @@ def logged_in_timeout
5153 def search ( query )
5254 query = "%#{ query . downcase } %"
5355
54- where arel_table [ :login ] . lower . matches ( query )
55- . or arel_table [ :email ] . lower . matches ( query )
56- . or arel_table [ :firstname ] . lower . matches ( query )
57- . or arel_table [ :lastname ] . lower . matches ( query )
56+ where arel_table [ :login ] . lower . matches ( query ) . or arel_table [ :email ] . lower . matches ( query ) . or arel_table [ :firstname ] . lower . matches ( query ) . or arel_table [ :lastname ] . lower . matches ( query )
5857 end
5958 end
6059
@@ -67,12 +66,12 @@ def role
6766 end
6867
6968 def alchemy_roles
70- read_attribute ( :alchemy_roles ) . split ( ' ' )
69+ read_attribute ( :alchemy_roles ) . split ( " " )
7170 end
7271
7372 def alchemy_roles = ( roles_string )
7473 if roles_string . is_a? Array
75- write_attribute ( :alchemy_roles , roles_string . join ( ' ' ) )
74+ write_attribute ( :alchemy_roles , roles_string . join ( " " ) )
7675 elsif roles_string . is_a? String
7776 write_attribute ( :alchemy_roles , roles_string )
7877 end
@@ -84,8 +83,9 @@ def add_role(role)
8483
8584 # Returns true if the user ahs admin role
8685 def is_admin?
87- has_role? ' admin'
86+ has_role? " admin"
8887 end
88+
8989 alias_method :admin? , :is_admin?
9090
9191 # Returns true if the user has the given role.
@@ -105,6 +105,7 @@ def unlock_pages!
105105 def pages_locked_by_me
106106 Page . locked_by ( self ) . order ( :updated_at )
107107 end
108+
108109 alias_method :locked_pages , :pages_locked_by_me
109110
110111 # Returns the firstname and lastname as a string
@@ -118,11 +119,12 @@ def fullname(options = {})
118119 if lastname . blank? && firstname . blank?
119120 login
120121 else
121- options = { : flipped => false } . merge ( options )
122+ options = { flipped : false } . merge ( options )
122123 fullname = options [ :flipped ] ? "#{ lastname } , #{ firstname } " : "#{ firstname } #{ lastname } "
123124 fullname . squeeze ( " " ) . strip
124125 end
125126 end
127+
126128 alias_method :name , :fullname
127129 alias_method :alchemy_display_name , :fullname
128130
@@ -150,7 +152,7 @@ def store_request_time!
150152 # Delivers a welcome mail depending from user's role.
151153 #
152154 def deliver_welcome_mail
153- if has_role? ( ' author' ) || has_role? ( ' editor' ) || has_role? ( ' admin' )
155+ if has_role? ( " author" ) || has_role? ( " editor" ) || has_role? ( " admin" )
154156 Notifications . alchemy_user_created ( self ) . deliver_later
155157 else
156158 Notifications . member_created ( self ) . deliver_later
@@ -159,7 +161,7 @@ def deliver_welcome_mail
159161
160162 # Overwritten to send a different email to members
161163 def send_reset_password_instructions_notification ( token )
162- if has_role? ( ' member' )
164+ if has_role? ( " member" )
163165 send_devise_notification ( :member_reset_password_instructions , token , { } )
164166 else
165167 send_devise_notification ( :reset_password_instructions , token , { } )
0 commit comments