From 19819515e43fb048d235d855ee795dabd849b5e0 Mon Sep 17 00:00:00 2001 From: Ben Teitelbaum Date: Sun, 22 Feb 2015 22:58:38 -0800 Subject: [PATCH] split manage/message and clean up those views #14 --- app/controllers/events_controller.rb | 25 ++++++-- app/controllers/workshops_controller.rb | 5 ++ app/models/ability.rb | 5 +- app/views/events/_form.html.erb | 6 +- app/views/events/manage.html.erb | 74 +++++++++------------ app/views/events/message.html.erb | 31 +++++++++ app/views/workshops/manage.html.erb | 85 ------------------------- app/views/workshops/message.html.erb | 38 +++++++++++ config/routes.rb | 9 ++- 9 files changed, 137 insertions(+), 141 deletions(-) create mode 100644 app/views/events/message.html.erb delete mode 100755 app/views/workshops/manage.html.erb create mode 100644 app/views/workshops/message.html.erb diff --git a/app/controllers/events_controller.rb b/app/controllers/events_controller.rb index f48d5d5f..cfbac197 100755 --- a/app/controllers/events_controller.rb +++ b/app/controllers/events_controller.rb @@ -70,20 +70,33 @@ def show # GET /events/1/manage # GET /events/1.json/manage - def manage_attendees + def manage if @event.manageable? @activities_n_counts = Activity.activities_n_counts(:limit => 20, :trackable => @event) - respond_to do |format| - format.html { render 'manage' } - format.json { render json: @event } - end + render 'manage' else if not @event.rsvp render_error(:message => 'Cannot manage attendees because RSVP is not set for this workshop', :status => :unauthorized) elsif @event.external render_error(:message => 'Cannot manage attendees of an external workshop', :status => :unauthorized) else - render_error(:message => 'Workshop unmanageable for some reason', :status => :unauthorized) + raise "workshop unmanageable for some unknown reason" + end + end + end + + # GET /events/1/message + # GET /events/1.json/message + def message + if @event.manageable? + render 'message' + else + if not @event.rsvp + render_error(:message => 'Cannot message attendees because RSVP is not set for this workshop', :status => :unauthorized) + elsif @event.external + render_error(:message => 'Cannot message attendees of an external workshop', :status => :unauthorized) + else + raise "workshop unmessageable for some unknown reason" end end end diff --git a/app/controllers/workshops_controller.rb b/app/controllers/workshops_controller.rb index 323a0267..38b72ce0 100755 --- a/app/controllers/workshops_controller.rb +++ b/app/controllers/workshops_controller.rb @@ -141,6 +141,11 @@ def update def manage @attendees = @workshop.attendees.uniq end + + # GET /w/:id/message(.:format) + def message + @attendees = @workshop.attendees.uniq + end # POST /w/1/sms_attendees def sms_attendees diff --git a/app/models/ability.rb b/app/models/ability.rb index a3b3f537..c5ffe42c 100755 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -2,7 +2,7 @@ class Ability include CanCan::Ability def initialize(user, session) - alias_action :edit, :update, :destroy, :accept_attendee, :cancel_attend, :manage_attendees, :lock, :unlock, :sms_attendees, :upload_photo, :manage, :to => :manage_as_host + alias_action :edit, :update, :destroy, :accept_attendee, :cancel_attend, :lock, :unlock, :sms_attendees, :upload_photo, :manage, :message, :to => :manage_as_host # anyone can [:show, :attend_by_email], Event @@ -27,7 +27,8 @@ def initialize(user, session) end can [:plus, :minus, :create, :index, :destroy], Review, :author_id => user.id - + + cannot :manage_as_host, Workshop can :simple_index_partial, Workshop # host if user.host? diff --git a/app/views/events/_form.html.erb b/app/views/events/_form.html.erb index 3f58fdd8..39532696 100755 --- a/app/views/events/_form.html.erb +++ b/app/views/events/_form.html.erb @@ -1,9 +1,9 @@ - <%= simple_form_for(@event) do |f| %>