aboutsummaryrefslogtreecommitdiff
path: root/app
diff options
context:
space:
mode:
authorJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-07-07 11:10:38 +0200
committerJoachim Filip Ignacy Bartosik <jbartosik@gmail.com>2010-07-08 20:35:14 +0200
commit7555e5cab5e17f44a6079fc3fbbfa97671450684 (patch)
tree8226defb808be8d1e866800b3a8b49811148bbb4 /app
parentImproved rake tasks (diff)
downloadrecruiting-webapp-7555e5cab5e17f44a6079fc3fbbfa97671450684.tar.gz
recruiting-webapp-7555e5cab5e17f44a6079fc3fbbfa97671450684.tar.bz2
recruiting-webapp-7555e5cab5e17f44a6079fc3fbbfa97671450684.zip
Allow users to suggest questions
Diffstat (limited to 'app')
-rw-r--r--app/controllers/questions_controller.rb11
-rw-r--r--app/models/guest.rb3
-rw-r--r--app/models/question.rb50
-rw-r--r--app/models/user.rb11
-rw-r--r--app/views/questions/approve_questions.dryml1
-rw-r--r--app/views/questions/suggest_questions.dryml1
-rw-r--r--app/views/taglibs/application.dryml11
-rw-r--r--app/views/taglibs/detailed.dryml1
8 files changed, 86 insertions, 3 deletions
diff --git a/app/controllers/questions_controller.rb b/app/controllers/questions_controller.rb
index c05fd12..3d158b3 100644
--- a/app/controllers/questions_controller.rb
+++ b/app/controllers/questions_controller.rb
@@ -3,8 +3,17 @@ class QuestionsController < ApplicationController
hobo_model_controller
auto_actions :all
- index_action :answered_questions, :unanswered_questions, :my_questions
+ index_action :answered_questions, :unanswered_questions, :my_questions, :suggest_questions, :approve_questions
+
def answered_questions
hobo_index (current_user.signed_up? && current_user.answered_questions)
end
+
+ def suggest_questions
+ hobo_index Question.suggested_questions current_user.try.id
+ end
+
+ def approve_questions
+ hobo_index Question.questions_to_approve
+ end
end
diff --git a/app/models/guest.rb b/app/models/guest.rb
index f653f35..98cb08f 100644
--- a/app/models/guest.rb
+++ b/app/models/guest.rb
@@ -4,4 +4,7 @@ class Guest < Hobo::Guest
false
end
+ def questions_to_approve
+ []
+ end
end
diff --git a/app/models/question.rb b/app/models/question.rb
index 0d173c1..67985ac 100644
--- a/app/models/question.rb
+++ b/app/models/question.rb
@@ -6,25 +6,56 @@ class Question < ActiveRecord::Base
title :string
content :text
documentation :string
+ approved :boolean, :default => false
timestamps
end
+ attr_readonly :user
validates_presence_of :title, :content
#allow empty documentation and no category
#maybe add a page for not complete questions
+ belongs_to :user, :creator => true
belongs_to :question_category
has_many :answers
has_one :reference_answer, :class_name => "Answer", :conditions => ["answers.reference = ?", true]
include Permissions::AnyoneCanViewAdminCanChange
- after_create :notify_new_question
+ multi_permission :create, :update, :destroy do
+ # Allow changes if user is administrator
+ return true if acting_user.administrator?
+
+ # if user owns question and it isn't approved yet
+ if !approved && user_is?(acting_user)
+ # everything is changed when it's a new record
+ return true if new_record?
+
+ # when it's not new record allow changing only some properties
+ return only_changed?(:title, :content, :documentation, :question_category)
+ end
+
+ false
+ end
+
+ def view_permitted?(field)
+ # Unapproved questions can be seen only by recruiters and owner
+ if !approved
+ return user_is?(acting_user) || acting_user.try.role.try.is_recruiter?
+ end
+
+ true
+ end
+
+ named_scope :suggested_questions, lambda { |user_id|{
+ :conditions => { :user_id => user_id, :approved => false }}}
named_scope :unanswered, lambda { |uid|{
:joins => {:question_category => {:user_categories => :user}},
:conditions => [ 'users.id = ? AND NOT EXISTS ( ' +
'SELECT * FROM answers WHERE answers.owner_id = ? AND answers.question_id = questions.id)', uid, uid]}}
+ named_scope :questions_to_approve, :conditions => { :approved => false }
+
def answered?(user)
user.signed_up? && user.answered_questions.include?(self)
end
@@ -33,13 +64,28 @@ class Question < ActiveRecord::Base
answers.owner_is(user).not_reference.first if user.signed_up?
end
+ before_create{ |question|
+ if question.user.try.role.try.is_recruiter || question.user_id.nil?
+ question.approved = true
+ end
+ }
+ after_create :notify_new_question
+ after_update :notify_approved_question
+
protected
def notify_new_question
# If question category isn't assigned don't try to access it
- if question_category
+ if question_category && approved
for user in question_category.users
UserMailer.deliver_new_question user, self
end
end
end
+
+ def notify_approved_question
+ if question_category && !approved_was && approved
+ notify_new_question
+ end
+ end
+
end
diff --git a/app/models/user.rb b/app/models/user.rb
index f6dcdcd..0e939dc 100644
--- a/app/models/user.rb
+++ b/app/models/user.rb
@@ -126,6 +126,17 @@ class User < ActiveRecord::Base
def any_pending_project_acceptances?
(ProjectAcceptance.count :conditions => { :accepting_nick => nick }) > 0
end
+
+ # This returns named scope, so it's efficient to use
+ # some_user.questions_to_approve.count
+ def questions_to_approve
+ if administrator?
+ Question.questions_to_approve
+ else
+ []
+ end
+ end
+
protected
def only_recruiter_can_be_administrator
diff --git a/app/views/questions/approve_questions.dryml b/app/views/questions/approve_questions.dryml
new file mode 100644
index 0000000..2acb381
--- /dev/null
+++ b/app/views/questions/approve_questions.dryml
@@ -0,0 +1 @@
+<index-page/>
diff --git a/app/views/questions/suggest_questions.dryml b/app/views/questions/suggest_questions.dryml
new file mode 100644
index 0000000..2acb381
--- /dev/null
+++ b/app/views/questions/suggest_questions.dryml
@@ -0,0 +1 @@
+<index-page/>
diff --git a/app/views/taglibs/application.dryml b/app/views/taglibs/application.dryml
index d981b3b..cf03f64 100644
--- a/app/views/taglibs/application.dryml
+++ b/app/views/taglibs/application.dryml
@@ -11,3 +11,14 @@
<include src="forms"/>
<include src="detailed"/>
<include src="pages"/>
+
+<def tag="main-nav">
+ <navigation class="main-nav" merge-attrs param="default">
+ <nav-item href="#{base_url}/">Home</nav-item>
+ <nav-item with="&ProjectAcceptance"><ht key="project_acceptances.nav_item">Project Acceptances</ht></nav-item>
+ <nav-item with="&Question"><ht key="questions.nav_item">Questions</ht></nav-item>
+ <nav-item with="&QuestionCategory"><ht key="question_categories.nav_item">Question Categories</ht></nav-item>
+ <nav-item href="&suggest_questions_questions_path"><ht key="questions.nav_item">Suggestion Questions</ht></nav-item>
+ <nav-item href="&approve_questions_questions_path" if="&current_user.questions_to_approve.count > 0"><ht key="questions.nav_item">Approve Questions</ht></nav-item>
+ </navigation>
+</def>
diff --git a/app/views/taglibs/detailed.dryml b/app/views/taglibs/detailed.dryml
index 0a93a5d..68f1c74 100644
--- a/app/views/taglibs/detailed.dryml
+++ b/app/views/taglibs/detailed.dryml
@@ -2,6 +2,7 @@
<def tag="detailed" for="Question">
<h2><name/><a action="edit" if="&can_edit?">(Edit)</a></h2>
+ <unless test="&this.approved">Not approved.</unless>
<view:content/>
</def>