Browse Source

Negated if, Not

Maarten van den Berg 6 years ago
parent
commit
9afdf65599

+ 0 - 28
.rubocop.yml

221
     - 'app/models/participant.rb'
221
     - 'app/models/participant.rb'
222
     - 'app/models/token.rb'
222
     - 'app/models/token.rb'
223
 
223
 
224
-# Offense count: 18
225
-# Cop supports --auto-correct.
226
-# Configuration parameters: EnforcedStyle.
227
-# SupportedStyles: both, prefix, postfix
228
-Style/NegatedIf:
229
-  Exclude:
230
-    - 'app/controllers/activities_controller.rb'
231
-    - 'app/controllers/authentication_controller.rb'
232
-    - 'app/controllers/dashboard_controller.rb'
233
-    - 'app/controllers/members_controller.rb'
234
-    - 'app/helpers/activities_helper.rb'
235
-    - 'app/helpers/authentication_helper.rb'
236
-    - 'app/helpers/groups_helper.rb'
237
-    - 'app/models/activity.rb'
238
-    - 'app/models/member.rb'
239
-    - 'app/models/person.rb'
240
-
241
 # Offense count: 1
224
 # Offense count: 1
242
 # Cop supports --auto-correct.
225
 # Cop supports --auto-correct.
243
 # Configuration parameters: EnforcedStyle, MinBodyLength.
226
 # Configuration parameters: EnforcedStyle, MinBodyLength.
246
   Exclude:
229
   Exclude:
247
     - 'db/seeds.rb'
230
     - 'db/seeds.rb'
248
 
231
 
249
-# Offense count: 12
250
-# Cop supports --auto-correct.
251
-Style/Not:
252
-  Exclude:
253
-    - 'app/controllers/authentication_controller.rb'
254
-    - 'app/controllers/members_controller.rb'
255
-    - 'app/helpers/authentication_helper.rb'
256
-    - 'app/models/activity.rb'
257
-    - 'app/models/member.rb'
258
-    - 'app/models/person.rb'
259
-
260
 # Offense count: 1
232
 # Offense count: 1
261
 # Cop supports --auto-correct.
233
 # Cop supports --auto-correct.
262
 # Configuration parameters: Strict.
234
 # Configuration parameters: Strict.

+ 1 - 1
app/controllers/activities_controller.rb

161
     @non_organizers_options.sort!
161
     @non_organizers_options.sort!
162
     @organizers_options.sort!
162
     @organizers_options.sort!
163
 
163
 
164
-    @subgroup = Subgroup.new if !@subgroup
164
+    @subgroup ||= Subgroup.new
165
     @subgroups = @activity.subgroups.order(is_assignable: :desc, name: :asc)
165
     @subgroups = @activity.subgroups.order(is_assignable: :desc, name: :asc)
166
   end
166
   end
167
 
167
 

+ 5 - 5
app/controllers/authentication_controller.rb

16
 
16
 
17
         flash_message(:success, I18n.t(:greeting, name: u.person.first_name))
17
         flash_message(:success, I18n.t(:greeting, name: u.person.first_name))
18
         redirect_to root_path
18
         redirect_to root_path
19
-      elsif u && (not u.confirmed)
19
+      elsif u && !u.confirmed
20
         flash_message(:warning, I18n.t('authentication.activation_required'))
20
         flash_message(:warning, I18n.t('authentication.activation_required'))
21
         redirect_to action: 'login_form'
21
         redirect_to action: 'login_form'
22
       else
22
       else
46
   def create_password
46
   def create_password
47
     person = Person.find_by(email: params[:user][:email])
47
     person = Person.find_by(email: params[:user][:email])
48
 
48
 
49
-    if not person
49
+    unless person
50
       flash_message(:warning, I18n.t('authentication.unknown_email'))
50
       flash_message(:warning, I18n.t('authentication.unknown_email'))
51
       redirect_to action: 'create_password_form'
51
       redirect_to action: 'create_password_form'
52
       return
52
       return
59
       return
59
       return
60
     end
60
     end
61
 
61
 
62
-    if not user
62
+    unless user
63
       user = User.new
63
       user = User.new
64
       user.person = person
64
       user.person = person
65
       user.email = person.email
65
       user.email = person.email
79
 
79
 
80
   def forgotten_password
80
   def forgotten_password
81
     user = User.find_by(email: params[:password_reset][:email])
81
     user = User.find_by(email: params[:password_reset][:email])
82
-    if not user
82
+    unless user
83
       flash_message(:danger, I18n.t('authentication.unknown_email'))
83
       flash_message(:danger, I18n.t('authentication.unknown_email'))
84
       redirect_to action: 'forgotten_password_form'
84
       redirect_to action: 'forgotten_password_form'
85
       return
85
       return
91
 
91
 
92
   def reset_password_form
92
   def reset_password_form
93
     token = Token.find_by(token: params[:token], tokentype: Token::TYPES[:password_reset])
93
     token = Token.find_by(token: params[:token], tokentype: Token::TYPES[:password_reset])
94
-    if not token_valid? token
94
+    unless token_valid? token
95
       return
95
       return
96
     end
96
     end
97
 
97
 

+ 1 - 1
app/controllers/dashboard_controller.rb

52
     new = params[:new_password]
52
     new = params[:new_password]
53
     confirm = params[:new_password_confirm]
53
     confirm = params[:new_password_confirm]
54
 
54
 
55
-    if !u.authenticate(current)
55
+    unless u.authenticate(current)
56
       flash_message(:danger, t('authentication.invalid_pass'))
56
       flash_message(:danger, t('authentication.invalid_pass'))
57
       redirect_to settings_path
57
       redirect_to settings_path
58
       return
58
       return

+ 2 - 2
app/controllers/members_controller.rb

42
   def process_invite
42
   def process_invite
43
     @person = Person.find_by(email: params[:person][:email])
43
     @person = Person.find_by(email: params[:person][:email])
44
     new_rec = false
44
     new_rec = false
45
-    if not @person
45
+    unless @person
46
       @person = Person.new(invite_params)
46
       @person = Person.new(invite_params)
47
       new_rec = true
47
       new_rec = true
48
 
48
 
49
-      if not @person.save
49
+      unless @person.save
50
         respond_to do |format|
50
         respond_to do |format|
51
           format.html { render 'invite' }
51
           format.html { render 'invite' }
52
           format.json { render json: @person.errors, status: :unprocessable_entity }
52
           format.json { render json: @person.errors, status: :unprocessable_entity }

+ 1 - 1
app/helpers/activities_helper.rb

1
 module ActivitiesHelper
1
 module ActivitiesHelper
2
   def require_organizer!
2
   def require_organizer!
3
-    if !@activity.may_change?(current_person)
3
+    unless @activity.may_change?(current_person)
4
       flash_message(:danger, I18n.t('authentication.organizer_required'))
4
       flash_message(:danger, I18n.t('authentication.organizer_required'))
5
       redirect_to group_activity_path(@group, @activity)
5
       redirect_to group_activity_path(@group, @activity)
6
     end
6
     end

+ 3 - 3
app/helpers/authentication_helper.rb

103
     end
103
     end
104
 
104
 
105
     # Edge case if a session no longer exists in the database
105
     # Edge case if a session no longer exists in the database
106
-    if not @user_session
106
+    unless @user_session
107
       log_out(session_broken: true)
107
       log_out(session_broken: true)
108
     end
108
     end
109
   end
109
   end
118
   end
118
   end
119
 
119
 
120
   def require_login!
120
   def require_login!
121
-    if !is_logged_in?
121
+    unless is_logged_in?
122
       flash_message(:warning, I18n.t('authentication.login_required'))
122
       flash_message(:warning, I18n.t('authentication.login_required'))
123
       redirect_to controller: 'authentication', action: 'login_form'
123
       redirect_to controller: 'authentication', action: 'login_form'
124
       return false
124
       return false
131
   end
131
   end
132
 
132
 
133
   def require_admin!
133
   def require_admin!
134
-    if !current_person.is_admin?
134
+    unless current_person.is_admin?
135
       flash_message(:danger, I18n.t('authentication.admin_required'))
135
       flash_message(:danger, I18n.t('authentication.admin_required'))
136
       redirect_to '/dashboard'
136
       redirect_to '/dashboard'
137
     end
137
     end

+ 3 - 3
app/helpers/groups_helper.rb

2
   def require_membership!
2
   def require_membership!
3
     return unless require_login!
3
     return unless require_login!
4
 
4
 
5
-    if !(@group.is_member?(current_person) || current_person.is_admin?)
5
+    unless @group.is_member?(current_person) || current_person.is_admin?
6
       flash_message(:danger, I18n.t('groups.membership_required'))
6
       flash_message(:danger, I18n.t('groups.membership_required'))
7
       redirect_to dashboard_home_path
7
       redirect_to dashboard_home_path
8
     end
8
     end
11
   def require_leader!
11
   def require_leader!
12
     return unless require_login!
12
     return unless require_login!
13
 
13
 
14
-    if !(@group.is_leader?(current_person) ||
15
-         current_person.is_admin?)
14
+    unless @group.is_leader?(current_person) ||
15
+           current_person.is_admin?
16
       flash_message(:danger, I18n.t('groups.leadership_required'))
16
       flash_message(:danger, I18n.t('groups.leadership_required'))
17
       redirect_to dashboard_home_path
17
       redirect_to dashboard_home_path
18
     end
18
     end

+ 1 - 1
app/models/activity.rb

137
   #  2. do not have Participants (and thus, no way to confirm) yet
137
   #  2. do not have Participants (and thus, no way to confirm) yet
138
   def create_missing_participants!
138
   def create_missing_participants!
139
     people = self.group.people
139
     people = self.group.people
140
-    if not self.participants.empty?
140
+    unless self.participants.empty?
141
       people = people.where('people.id NOT IN (?)', self.people.ids)
141
       people = people.where('people.id NOT IN (?)', self.people.ids)
142
     end
142
     end
143
 
143
 

+ 1 - 1
app/models/member.rb

22
   def create_future_participants!
22
   def create_future_participants!
23
     activities = self.group.future_activities
23
     activities = self.group.future_activities
24
 
24
 
25
-    if not self.person.activities.empty?
25
+    unless self.person.activities.empty?
26
       activities = activities.where(
26
       activities = activities.where(
27
         'activities.id NOT IN (?)', self.person.activities.ids
27
         'activities.id NOT IN (?)', self.person.activities.ids
28
       )
28
       )

+ 2 - 2
app/models/person.rb

82
     result = []
82
     result = []
83
     reader.each do |row|
83
     reader.each do |row|
84
       p = Person.find_by(email: row['email'])
84
       p = Person.find_by(email: row['email'])
85
-      if not p
85
+      unless p
86
         p = Person.new
86
         p = Person.new
87
         p.first_name  = row['first_name']
87
         p.first_name  = row['first_name']
88
         p.infix       = row['infix']
88
         p.infix       = row['infix']
207
   # Ensure the person's user email is updated at the same time as the person's
207
   # Ensure the person's user email is updated at the same time as the person's
208
   # email.
208
   # email.
209
   def update_user_email
209
   def update_user_email
210
-    if not self.user.nil?
210
+    unless self.user.nil?
211
       self.user.update!(email: self.email)
211
       self.user.update!(email: self.email)
212
     end
212
     end
213
   end
213
   end