diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-06-13 15:28:53 +0200 |
---|---|---|
committer | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-06-17 20:39:41 +0200 |
commit | a698363f18aa0b38bb2a3989a148543d0fac8b5a (patch) | |
tree | 48ca1cead452712b1427a2c44886f70832d35a32 | |
parent | Change names to communicative (diff) | |
download | council-webapp-a698363f18aa0b38bb2a3989a148543d0fac8b5a.tar.gz council-webapp-a698363f18aa0b38bb2a3989a148543d0fac8b5a.tar.bz2 council-webapp-a698363f18aa0b38bb2a3989a148543d0fac8b5a.zip |
Remove some duplication
Reported by Metrical/Reek. Some reported duplication left (Calls to
ActiveRecord fields, calls to acting_user etc.)
-rw-r--r-- | site/app/controllers/agendas_controller.rb | 3 | ||||
-rw-r--r-- | site/app/controllers/front_controller.rb | 5 | ||||
-rw-r--r-- | site/app/models/agenda.rb | 14 | ||||
-rw-r--r-- | site/app/models/user.rb | 5 |
4 files changed, 16 insertions, 11 deletions
diff --git a/site/app/controllers/agendas_controller.rb b/site/app/controllers/agendas_controller.rb index 8760069..c6865a1 100644 --- a/site/app/controllers/agendas_controller.rb +++ b/site/app/controllers/agendas_controller.rb @@ -25,8 +25,9 @@ class AgendasController < ApplicationController private def authenticate_bot + botconf = CustomConfig['Bot'] authenticate_or_request_with_http_basic do |user_name, password| - user_name == CustomConfig['Bot']['user'] && password == CustomConfig['Bot']['password'] + user_name == botconf['user'] && password == botconf['password'] end end end diff --git a/site/app/controllers/front_controller.rb b/site/app/controllers/front_controller.rb index 86e3201..dda167e 100644 --- a/site/app/controllers/front_controller.rb +++ b/site/app/controllers/front_controller.rb @@ -11,8 +11,9 @@ class FrontController < ApplicationController end def search - if params[:query] - site_search(params[:query]) + query = params[:query] + if query + site_search(query) end end diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb index 16dc2e7..baaac89 100644 --- a/site/app/models/agenda.rb +++ b/site/app/models/agenda.rb @@ -107,8 +107,8 @@ class Agenda < ActiveRecord::Base # So I think efficiency improvement would be insignificant. # Joachim council = ::User.council_member_is(true) - proxies = Agenda.current.proxies - [council - proxies.*.council_member + proxies.*.proxy].flatten + proxies = Agenda.current.proxies.* + [council - proxies.council_member + proxies.proxy].flatten end def self.voters @@ -131,9 +131,10 @@ class Agenda < ActiveRecord::Base def self.irc_reminders agenda = Agenda.current + meeting_time = agenda.meeting_time.strftime('%a %b %d %H:%M:%S %Y') return {} if Time.now < agenda.time_for_reminders(:irc) - return { 'remind_time' => agenda.meeting_time.strftime('%a %b %d %H:%M:%S %Y'), - 'message' => "Remember about council meeting on #{agenda.meeting_time.to_s}", + return { 'remind_time' => meeting_time, + 'message' => "Remember about council meeting on #{meeting_time}", 'users' => Agenda.voters} end @@ -153,10 +154,11 @@ class Agenda < ActiveRecord::Base protected def there_is_only_one_non_archival_agenda return if(state.to_s == 'old') + not_old_agendas = Agenda.state_is_not(:old) if id.nil? - return if Agenda.state_is_not(:old).count == 0 + return if not_old_agendas.count == 0 else - return if Agenda.state_is_not(:old).id_is_not(id).count == 0 + return if not_old_agendas.id_is_not(id).count == 0 end errors.add(:state, 'There can be only one non-archival agenda at time.') end diff --git a/site/app/models/user.rb b/site/app/models/user.rb index 0ca3e33..7809e87 100644 --- a/site/app/models/user.rb +++ b/site/app/models/user.rb @@ -72,10 +72,11 @@ class User < ActiveRecord::Base end def can_appoint_a_proxy?(user) + agenda = Agenda.current return false unless council_member? return false if user.council_member? - return false unless Proxy.council_member_is(self).agenda_is(Agenda.current).count == 0 - return false unless Proxy.proxy_is(user).agenda_is(Agenda.current).count == 0 + return false unless Proxy.council_member_is(self).agenda_is(agenda).count == 0 + return false unless Proxy.proxy_is(user).agenda_is(agenda).count == 0 true end end |