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 /app/models
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
Diffstat (limited to 'app/models')
-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
8 files changed, 31 insertions, 28 deletions
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)