aboutsummaryrefslogtreecommitdiff
path: root/site/app
diff options
context:
space:
mode:
Diffstat (limited to 'site/app')
-rw-r--r--site/app/controllers/approvals_controller.rb7
-rw-r--r--site/app/models/agenda.rb12
-rw-r--r--site/app/models/approval.rb27
-rw-r--r--site/app/views/agendas/show.dryml16
4 files changed, 61 insertions, 1 deletions
diff --git a/site/app/controllers/approvals_controller.rb b/site/app/controllers/approvals_controller.rb
new file mode 100644
index 0000000..aeead3b
--- /dev/null
+++ b/site/app/controllers/approvals_controller.rb
@@ -0,0 +1,7 @@
+class ApprovalsController < ApplicationController
+
+ hobo_model_controller
+
+ auto_actions :all, :except => [:new, :index]
+
+end
diff --git a/site/app/models/agenda.rb b/site/app/models/agenda.rb
index bf38838..75a9a23 100644
--- a/site/app/models/agenda.rb
+++ b/site/app/models/agenda.rb
@@ -13,6 +13,7 @@ class Agenda < ActiveRecord::Base
has_many :agenda_items
has_many :participations
has_many :proxies
+ has_many :approvals
lifecycle do
state :open, :default => true
@@ -45,7 +46,16 @@ class Agenda < ActiveRecord::Base
end
def view_permitted?(field)
- true
+ return true unless field == :summary
+ return true if approvals.count >= 4
+ return true if acting_user.council_member?
+ false
+ end
+
+ after_update do |agenda|
+ if agenda.summary_changed?
+ agenda.approvals.each { |approval| approval.destroy }
+ end
end
before_create do |agenda|
diff --git a/site/app/models/approval.rb b/site/app/models/approval.rb
new file mode 100644
index 0000000..d36232c
--- /dev/null
+++ b/site/app/models/approval.rb
@@ -0,0 +1,27 @@
+require 'permissions/set.rb'
+
+class Approval < ActiveRecord::Base
+
+ hobo_model # Don't put anything above this
+
+ fields do
+ timestamps
+ end
+
+ belongs_to :user, :null => false
+ belongs_to :agenda, :null => false
+
+ validates_presence_of :user_id
+ validates_presence_of :agenda_id
+ validates_uniqueness_of :user_id, :scope => :agenda_id
+
+ def view_permitted?(field)
+ true
+ end
+
+ multi_permission(:create, :destroy, :update) do
+ return false unless user_is?(acting_user)
+ return false unless acting_user.council_member?
+ true
+ end
+end
diff --git a/site/app/views/agendas/show.dryml b/site/app/views/agendas/show.dryml
index 40a413e..0471eb4 100644
--- a/site/app/views/agendas/show.dryml
+++ b/site/app/views/agendas/show.dryml
@@ -13,5 +13,21 @@
<a href="&send(this.second)"><view:first/></a>
</collection>
</div>
+ <if test="&current_user.council_member? and not this.summary.nil? and not this.summary.empty?">
+ <form action="&create_approval_path" if="&Approval.user_is(current_user).agenda_is(this).count.zero?">
+ <input type="hidden" name="approval[user_id]" value="&current_user.id"/>
+ <input type="hidden" name="approval[agenda_id]" value="&this.id"/>
+ <submit label="approve summary"/>
+ </form>
+ <else>
+ <with with="&Approval.agenda_is(this).user_is(current_user).first">
+ <delete-button label="remove your approval for this summary" />
+ </with>
+ </else>
+ </if>
+ <unless test="&this.approvals.count.zero?">
+ Summary for this agenda was approved by <%= this.approvals.count %> council member(s):
+ <%= this.approvals.*.user.*.name.join(", ") %>.
+ </unless>
</append-content-body:>
</show-page>