aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-08-02 14:17:55 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-08-05 18:18:50 +0200
commit996128e23cdd2e2c232da3e8fe3ef9deb94c2477 (patch)
tree802abb87644b31e21e1862f99cc248693928f0a1
parentSwitch back to Rails 2.3.5 (diff)
downloadrecruiting-webapp-996128e23cdd2e2c232da3e8fe3ef9deb94c2477.tar.gz
recruiting-webapp-996128e23cdd2e2c232da3e8fe3ef9deb94c2477.tar.bz2
recruiting-webapp-996128e23cdd2e2c232da3e8fe3ef9deb94c2477.zip
Add functions to Guest model to avoid try-s
-rw-r--r--app/controllers/project_acceptances_controller.rb2
-rw-r--r--app/controllers/questions_controller.rb4
-rw-r--r--app/models/answer.rb4
-rw-r--r--app/models/comment.rb2
-rw-r--r--app/models/guest.rb19
-rw-r--r--app/models/project_acceptance.rb18
-rw-r--r--app/models/question.rb2
-rw-r--r--app/models/question_content_email.rb2
-rw-r--r--app/models/user.rb8
-rw-r--r--app/models/user_category.rb4
-rw-r--r--app/views/taglibs/pages.dryml10
-rw-r--r--app/views/taglibs/views.dryml2
12 files changed, 40 insertions, 37 deletions
diff --git a/app/controllers/project_acceptances_controller.rb b/app/controllers/project_acceptances_controller.rb
index 059ec14..cd6f8fe 100644
--- a/app/controllers/project_acceptances_controller.rb
+++ b/app/controllers/project_acceptances_controller.rb
@@ -6,6 +6,6 @@ class ProjectAcceptancesController < ApplicationController
index_action :pending_acceptances
def pending_acceptances
- hobo_index ProjectAcceptance.accepting_nick_is(current_user.try.nick)
+ hobo_index ProjectAcceptance.accepting_nick_is(current_user.nick)
end
end
diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb
index c770ea5..d58f322 100644
--- a/app/controllers/questions_controller.rb
+++ b/app/controllers/questions_controller.rb
@@ -6,11 +6,11 @@ class QuestionsController < ApplicationController
index_action :answered_questions, :unanswered_questions, :suggest_questions, :approve_questions
def answered_questions
- hobo_index current_user.try.answered_questions
+ hobo_index current_user.answered_questions
end
def suggest_questions
- hobo_index Question.suggested_questions(current_user.try.id)
+ hobo_index Question.suggested_questions(current_user.id)
end
def approve_questions
diff --git a/app/models/answer.rb b/app/models/answer.rb
index ff45ee5..f3200dd 100644
--- a/app/models/answer.rb
+++ b/app/models/answer.rb
@@ -66,12 +66,12 @@ class Answer < ActiveRecord::Base
end
def reference_edit_permitted?
- acting_user.try.role.try.is_recruiter?
+ acting_user.role.is_recruiter?
end
def view_permitted?(field)
owned_soft? ||
- acting_user.try.role.try.is_recruiter? ||
+ acting_user.role.is_recruiter? ||
owner.mentor_is?(acting_user)
end
diff --git a/app/models/comment.rb b/app/models/comment.rb
index ce6117e..53db93b 100644
--- a/app/models/comment.rb
+++ b/app/models/comment.rb
@@ -24,7 +24,7 @@ class Comment < ActiveRecord::Base
# and recruit who owns answer can view
return true if owner_is?(acting_user)
return true if answer.owner_is?(acting_user)
- return true if acting_user.try.role.try.is_recruiter?
+ return true if acting_user.role.is_recruiter?
false
end
diff --git a/app/models/guest.rb b/app/models/guest.rb
index 98cb08f..904dfe1 100644
--- a/app/models/guest.rb
+++ b/app/models/guest.rb
@@ -1,10 +1,13 @@
class Guest < Hobo::Guest
-
- def administrator?
- false
- end
-
- def questions_to_approve
- []
- end
+ def administrator?; false; end
+ def answered_questions; []; end
+ def any_pending_acceptances?; false; end
+ def id; nil; end
+ def mentor; nil; end
+ def mentor_is?(x); false; end
+ def nick; nil; end
+ def project_lead; false; end
+ def questions_to_approve; []; end
+ def role; Role.new(:guest); end
+ def token; nil; end
end
diff --git a/app/models/project_acceptance.rb b/app/models/project_acceptance.rb
index e96de8d..50ff4cd 100644
--- a/app/models/project_acceptance.rb
+++ b/app/models/project_acceptance.rb
@@ -21,28 +21,28 @@ class ProjectAcceptance < ActiveRecord::Base
def create_permitted?
# Recruiters can create project_acceptances
# Project leads can create project_acceptances they should approve
- return true if acting_user.try.role.try.is_recruiter?
- return true if acting_user.try.project_lead && accepting_nick == acting_user.try.nick
+ return true if acting_user.role.is_recruiter?
+ return true if acting_user.project_lead && accepting_nick == acting_user.nick
false
end
multi_permission :update, :destroy, :edit do
# Allow admins everything
- return true if acting_user.try.administrator?
+ return true if acting_user.administrator?
# Allow users mentor and recruiters if not accepted and
# accepted was not changed
- recruiter_user_or_mentor = acting_user.try.role.try.is_recruiter? ||
+ recruiter_user_or_mentor = acting_user.role.is_recruiter? ||
user.try.mentor_is?(acting_user)
return true if recruiter_user_or_mentor && !accepted && !accepted_changed?
# Allow user with nick accepting_nick to change :accepted
- return true if (acting_user.try.nick == accepting_nick) && only_changed?(:accepted)
+ return true if (acting_user.nick == accepting_nick) && only_changed?(:accepted)
# Allow CRU new records to recruiters and project leads
- return true if new_record? && acting_user.try.role.try.is_recruiter?
- return true if new_record? && acting_user.try.project_lead
+ return true if new_record? && acting_user.role.is_recruiter?
+ return true if new_record? && acting_user.project_lead
false
end
@@ -50,7 +50,7 @@ class ProjectAcceptance < ActiveRecord::Base
def view_permitted(field)
# Allow user(relation), mentor of user and recruiters to view
return true if user_is?(acting_user)
- return true if acting_user.try.role.try.is_recruiter?
+ return true if acting_user.role.is_recruiter?
return true if user.mentor_is?(acting_user)
false
@@ -59,7 +59,7 @@ class ProjectAcceptance < ActiveRecord::Base
# Returns new project acceptance with user = recruit, accepting_nick = lead.nick
# if lead is marked as project_lead AND there isn't such a project acceptance yet
def self.new_for_users(recruit, lead)
- return nil unless lead.try.project_lead
+ return nil unless lead.project_lead
return nil unless recruit.signed_up?
return nil unless ProjectAcceptance.first(:conditions => { :accepting_nick => lead.nick, :user_id => recruit.id}).nil?
ProjectAcceptance.new :accepting_nick => lead.nick, :user => recruit
diff --git a/app/models/question.rb b/app/models/question.rb
index e3fdd08..1122dd1 100644
--- a/app/models/question.rb
+++ b/app/models/question.rb
@@ -47,7 +47,7 @@ class Question < ActiveRecord::Base
# Unapproved questions can be seen only by recruiters and owner
if !approved
- return user_is?(acting_user) || acting_user.try.role.try.is_recruiter?
+ return user_is?(acting_user) || acting_user.role.is_recruiter?
end
# Allow viewing ungrouped questions to everybody
diff --git a/app/models/question_content_email.rb b/app/models/question_content_email.rb
index 37c1197..937ea15 100644
--- a/app/models/question_content_email.rb
+++ b/app/models/question_content_email.rb
@@ -16,7 +16,7 @@ class QuestionContentEmail < ActiveRecord::Base
inherit_permissions(:question)
def req_text_view_permitted?
- return true if acting_user.try.role.try.is_recruiter?
+ return true if acting_user.role.is_recruiter?
return true if question.owner_is?(acting_user) && !question.approved
end
diff --git a/app/models/user.rb b/app/models/user.rb
index e289255..ef81354 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -94,8 +94,8 @@ class User < ActiveRecord::Base
# Acting user became mentor of edited recruit and edited user had no mentor
return true if acting_user.administrator?
return true if acting_user == self && changes_allowed_to_self?
- return true if acting_user.try.role.try.is_recruiter? && changes_allowed_for_recruiter?
- return true if role.is_recruit? && acting_user.try.role.try.is_mentor? && mentor_picked_up_or_resigned?
+ return true if acting_user.role.is_recruiter? && changes_allowed_for_recruiter?
+ return true if role.is_recruit? && acting_user.role.is_mentor? && mentor_picked_up_or_resigned?
end
def role_edit_permitted?
@@ -203,8 +203,8 @@ class User < ActiveRecord::Base
# and mentor changed from nil to acting user
# or mentor changed from nil to current user
return false unless only_changed?(:mentor)
- return false unless (mentor_id_was.nil? || (mentor_id_was == acting_user.try.id))
- return false unless (mentor_id.nil? || (mentor_id == acting_user.try.id))
+ return false unless (mentor_id_was.nil? || (mentor_id_was == acting_user.id))
+ return false unless (mentor_id.nil? || (mentor_id == acting_user.id))
true
end
diff --git a/app/models/user_category.rb b/app/models/user_category.rb
index 31de7a7..d5cfaa3 100644
--- a/app/models/user_category.rb
+++ b/app/models/user_category.rb
@@ -13,14 +13,14 @@ class UserCategory < ActiveRecord::Base
validates_uniqueness_of :user_id, :scope => :question_category_id
multi_permission :create, :update, :destroy do
- return true if acting_user.try.role.try.is_recruiter?
+ return true if acting_user.role.is_recruiter?
return true if user_is?(acting_user)
false
end
def view_permitted?(field)
- return true if acting_user.try.role.try.is_recruiter?
+ return true if acting_user.role.is_recruiter?
return true if user_is?(acting_user)
return true if user.mentor_is?(acting_user)
diff --git a/app/views/taglibs/pages.dryml b/app/views/taglibs/pages.dryml
index be66a67..091f6fc 100644
--- a/app/views/taglibs/pages.dryml
+++ b/app/views/taglibs/pages.dryml
@@ -16,7 +16,7 @@
<a with="&current_user">view your profile</a>.<br/>
</section>
- <section class="users recruits" if="&this.try.role.try.is_recruit?">
+ <section class="users recruits" if="&this.role.is_recruit?">
<if:question_categories>
You are currently assigned to categories:
@@ -29,12 +29,12 @@
</ul>
</if>
- <if test="&current_user.try.any_pending_project_acceptances?">
+ <if test="&current_user.any_pending_project_acceptances?">
<a with="&ProjectAcceptance" action="pending_acceptances">Recruits waiting for your acceptance</a>.
</if>
<if test="&current_user.answered_all_multi_choice_questions?">
- <if test="&Answer.wrong_answers_of(current_user.try.id).count > 0">
+ <if test="&Answer.wrong_answers_of(current_user.id).count > 0">
You answered all multiple choice questions, but some of them wrong.<br/>
</if>
<else>
@@ -46,7 +46,7 @@
</section>
- <section class="users mentors" if="&current_user.try.role.try.is_mentor? || current_user.try.role.try.is_recruiter?">
+ <section class="users mentors" if="&current_user.role.is_mentor? || current_user.role.is_recruiter?">
<a with="&User" action="mentorless_recruits" if="&User.mentorless_recruits.count > 0">See mentorless recruits</a><br/>
@@ -60,7 +60,7 @@
</section>
- <section class="users recruiters" if="&this.try.role.try.is_recruiter?">
+ <section class="users recruiters" if="&this.role.is_recruiter?">
<h3>Registered users:</h3>
<collection with="&User.all"/>
diff --git a/app/views/taglibs/views.dryml b/app/views/taglibs/views.dryml
index 79bd41d..c4bcd89 100644
--- a/app/views/taglibs/views.dryml
+++ b/app/views/taglibs/views.dryml
@@ -38,6 +38,6 @@
%>
<if test="&current_user.signed_up?">
- Your answer should have subject (without quotes) "<%= "#{this.question.id}-#{current_user.try.token}" %>".
+ Your answer should have subject (without quotes) "<%= "#{this.question.id}-#{current_user.token}" %>".
</if>
</def>