diff options
author | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-05-30 20:08:21 +0200 |
---|---|---|
committer | Joachim Filip Ignacy Bartosik <jbartosik@gmail.com> | 2011-06-03 19:27:10 +0200 |
commit | 7d5a200601a723b8a6acef4f49ea02bd2bba9935 (patch) | |
tree | 9c12dd3e3cf0a7d108b7eb3755c26260a80a7e5c /site/app | |
parent | Application receives data from IRC bot (diff) | |
download | council-webapp-7d5a200601a723b8a6acef4f49ea02bd2bba9935.tar.gz council-webapp-7d5a200601a723b8a6acef4f49ea02bd2bba9935.tar.bz2 council-webapp-7d5a200601a723b8a6acef4f49ea02bd2bba9935.zip |
Proxy model
Diffstat (limited to 'site/app')
-rw-r--r-- | site/app/controllers/proxies_controller.rb | 7 | ||||
-rw-r--r-- | site/app/models/proxy.rb | 57 |
2 files changed, 64 insertions, 0 deletions
diff --git a/site/app/controllers/proxies_controller.rb b/site/app/controllers/proxies_controller.rb new file mode 100644 index 0000000..afd6822 --- /dev/null +++ b/site/app/controllers/proxies_controller.rb @@ -0,0 +1,7 @@ +class ProxiesController < ApplicationController + + hobo_model_controller + + auto_actions :all + +end diff --git a/site/app/models/proxy.rb b/site/app/models/proxy.rb new file mode 100644 index 0000000..7be0a0b --- /dev/null +++ b/site/app/models/proxy.rb @@ -0,0 +1,57 @@ +class Proxy < ActiveRecord::Base + + hobo_model # Don't put anything above this + + fields do + # Remeber nicks from when meeting took place + # May be useful when reading logs (if user changes nick) + council_member_nick :string, :null => false + proxy_nick :string, :null => false + timestamps + end + + belongs_to :council_member, :class_name => 'User', :null => false + belongs_to :proxy, :class_name => 'User', :null => false + belongs_to :agenda, :null => false + + validates_presence_of :council_member, :proxy, :agenda + validates_uniqueness_of :council_member_id, :scope => :agenda_id + validates_uniqueness_of :proxy_id, :scope => :agenda_id + validate :council_member_must_be_council_member + validate :proxy_must_not_be_council_member + + # --- Permissions --- # + + def create_permitted? + return false unless acting_user.council_member? + council_member_is?(acting_user) + end + + def update_permitted? + false + end + + def destroy_permitted? + return false if agenda.state == 'old' + council_member_is?(acting_user) + end + + def view_permitted?(field) + true + end + + before_create do |p| + p.council_member_nick = p.council_member.irc_nick + p.proxy_nick = p.proxy.irc_nick + end + + protected + def council_member_must_be_council_member + return if council_member.nil? + errors.add(:council_member, 'must be council member') unless council_member.council_member? + end + def proxy_must_not_be_council_member + return if proxy.nil? + errors.add(:proxy, 'must not be council member') if proxy.council_member? + end +end |