Workshop facilitators

This commit is contained in:
Godwin
2015-09-19 16:30:39 -07:00
parent 6104a6c521
commit 0ffee810dd
73 changed files with 5335 additions and 877 deletions
+26 -1
View File
@@ -1914,4 +1914,29 @@ html[data-lingua-franca-example="html"] {
p {
font-size: 1.1em;
}
}
}
.facilitator .button {
font-size: 0.9em;
vertical-align: -0.75em;
}
#main .facilitators .actions {
margin: 0;
}
#main form.add-facilitator {
text-align: left;
margin-top: 0;
button {
font-size: 0.9em;
float: right;
}
.email-field {
width: 82%;
font-size: 0.9em;
float: left;
}
}
+109
View File
@@ -924,6 +924,115 @@ class ConferencesController < ApplicationController
redirect_to view_workshop_url(@this_conference.slug, workshop.id)
end
def facilitate_workshop
set_conference
set_conference_registration
@workshop = Workshop.find_by_id_and_conference_id(params[:workshop_id], @this_conference.id)
do_404 unless @workshop
do_403 if @workshop.facilitator?(current_user) || !current_user
render 'workshops/facilitate'
end
def facilitate_request
set_conference
set_conference_registration
workshop = Workshop.find_by_id_and_conference_id(params[:workshop_id], @this_conference.id)
do_404 unless workshop
do_403 if workshop.facilitator?(current_user) || !current_user
# create the request by making the user a facilitator but making their role 'requested'
WorkshopFacilitator.create(user_id: current_user.id, workshop_id: workshop.id, role: :requested)
UserMailer.send_mail :workshop_facilitator_request do
{
:args => [ workshop, current_user, params[:message] ]
}
end
redirect_to sent_facilitate_workshop_url(@this_conference.slug, workshop.id)
end
def sent_facilitate_request
set_conference
set_conference_registration
@workshop = Workshop.find_by_id_and_conference_id(params[:workshop_id], @this_conference.id)
do_404 unless @workshop
do_403 unless @workshop.requested_collaborator?(current_user)
render 'workshops/facilitate_request_sent'
end
def approve_facilitate_request
set_conference
set_conference_registration
workshop = Workshop.find_by_id_and_conference_id(params[:workshop_id], @this_conference.id)
do_404 unless workshop && current_user
user_id = params[:user_id].to_i
action = params[:approve_or_deny].to_sym
user = User.find(user_id)
if action == :approve
if current_user && workshop.active_facilitator?(current_user) && workshop.requested_collaborator?(User.find(user_id))
f = WorkshopFacilitator.find_by_workshop_id_and_user_id(
workshop.id, user_id)
f.role = :collaborator
f.save
UserMailer.send_mail :workshop_facilitator_request_approved do
{
:args => [ workshop, user ]
}
end
return redirect_to view_workshop_url(@this_conference.slug, workshop.id)
end
elsif action == :deny
if current_user && workshop.active_facilitator?(current_user) && workshop.requested_collaborator?(User.find(user_id))
WorkshopFacilitator.delete_all(
:workshop_id => workshop.id,
:user_id => user_id)
UserMailer.send_mail :workshop_facilitator_request_denied do
{
:args => [ workshop, user ]
}
end
return redirect_to view_workshop_url(@this_conference.slug, workshop.id)
end
elsif action == :remove
if current_user && current_user.id == user_id
unless workshop.creator?(user)
WorkshopFacilitator.delete_all(
:workshop_id => workshop.id,
:user_id => user_id)
end
return redirect_to view_workshop_url(@this_conference.slug, workshop.id)
end
end
do_403
end
def add_workshop_facilitator
user = User.find_by_email(params[:email]) || User.create(email: params[:email])
set_conference
set_conference_registration
workshop = Workshop.find_by_id_and_conference_id(params[:workshop_id], @this_conference.id)
do_404 unless workshop && current_user
unless workshop.facilitator?(user)
WorkshopFacilitator.create(user_id: user.id, workshop_id: workshop.id, role: :collaborator)
UserMailer.send_mail :workshop_facilitator_request_approved do
{
:args => [ workshop, user ]
}
end
end
return redirect_to view_workshop_url(@this_conference.slug, params[:workshop_id])
end
# DELETE /conferences/1
#def destroy
# @conference.destroy
+39 -19
View File
@@ -1,24 +1,7 @@
class UserMailer < ActionMailer::Base
add_template_helper(ApplicationHelper)
#add_template_helper(LinguaFrancaHelper)
include LinguaFrancaHelper
#def self.before(*names)
# names.each do |name|
# m = instance_method(name)
# define_method(name) do |*args, &block|
# #yield
# if ![:send_action].include?(name.to_sym)
# puts " ====== #{name} ====== "
# I18n.backend.set_page_name(name)
# m.bind(self).(*args, &block)
# else
# puts " ------ #{name} ------ "
# end
# end
# end
#end
default from: "Bike!Bike! <noreply@bikebike.org>"
# Subject can be set in your I18n file at config/locales/en.yml
@@ -82,7 +65,6 @@ class UserMailer < ActionMailer::Base
end
def broadcast(host, subject, content, user, conference)
#puts " == #{instance_methods.to_json.to_s} == "
@host = host
@content = content
@banner = (@host || 'http://localhost/') + (conference ? (conference.poster.preview.url || '') : image_url('logo.png'))
@@ -91,5 +73,43 @@ class UserMailer < ActionMailer::Base
end
end
#before(*instance_methods) { }
def workshop_facilitator_request(workshop, requester, message)
@host = UserMailer.default_url_options[:host]
@workshop = workshop
@requester = requester
addresses = []
@workshop.active_facilitators.each do |f|
addresses << f.email
end
@message = message
@conference = Conference.find(@workshop.conference_id)
mail to: addresses,
from: @requester.email,
subject: _('email.subject.workshop_facilitator_request',
"Request to facilitate #{@workshop.title} from #{@requester.firstname}",
:vars => {:workshop_title => @workshop.title, :requester_name => @requester.firstname})
end
def workshop_facilitator_request_approved(workshop, user)
@host = UserMailer.default_url_options[:host]
@workshop = workshop
@conference = Conference.find(@workshop.conference_id)
@user = user
mail to: user.email,
subject: (_'email.subject.workshop_request_approved',
"You have been added as a facilitator of #{@workshop.title}",
:vars => {:workshop_title => @workshop.title})
end
def workshop_facilitator_request_denied(workshop, user)
@host = UserMailer.default_url_options[:host]
@workshop = workshop
@conference = Conference.find(@workshop.conference_id)
@user = user
mail to: user.email,
subject: (_'email.subject.workshop_request_denied',
"Your request to facilitate #{@workshop.title} has been denied",
:vars => {:workshop_title => @workshop.title})
end
end
+7
View File
@@ -35,8 +35,15 @@ class Conference < ActiveRecord::Base
action = action.to_sym
'/conferences/' + conference_type.slug + '/' + slug + (action == :show ? '' : '/' + action.to_s)
end
def location
organizations.first.location
end
def registered?(user)
registration = ConferenceRegistration.find_by(:user_id => user.id, :conference_id => id)
return false unless registration
return registration.is_attending
end
end
+39 -6
View File
@@ -15,8 +15,11 @@ class Workshop < ActiveRecord::Base
end
def role(user)
return nil unless user
workshop_facilitators.each do |u|
return u.role.to_sym if u.user_id == user.id
if u.user_id == user.id
return conference.registered?(user) ? u.role.to_sym : :unregistered
end
end
return nil
end
@@ -25,12 +28,38 @@ class Workshop < ActiveRecord::Base
!!role(user)
end
def active_facilitators
users = []
workshop_facilitators.each do |u|
users << User.find(u.user_id) if u.role.to_sym != :request
end
return users
end
def active_facilitator?(user)
facilitator?(user) && !requested_collaborator?(user)
end
def public_facilitator?(user)
return false if !active_facilitator?(user)
return true if creator?(user)
conference.registered?(user)
end
def creator?(user)
role(user) == :creator
end
def collaborator?(user)
role(user) == :collaborator
end
def requested_collaborator?(user)
role(user) == :requested
end
def can_edit?(user)
creator?(user) || conference.host?(user)
creator?(user) || collaborator?(user) || conference.host?(user)
end
def can_delete?(user)
@@ -38,16 +67,20 @@ class Workshop < ActiveRecord::Base
end
def can_show_interest?(user)
!facilitator?(user)
!active_facilitator?(user)
end
def interested?(user)
user.present? && !!WorkshopInterest.find_by(workshop_id: id, user_id: user.id)
user.present? && !active_facilitator?(user) && WorkshopInterest.find_by(workshop_id: id, user_id: user.id)
end
def interested_count
workshops = WorkshopInterest.where(:workshop_id => id)
workshops ? workshops.size : 0
collaborators = []
workshop_facilitators.each do |f|
collaborators << f.user_id unless f.role.to_sym == :requested
end
interested = WorkshopInterest.where("workshop_id=#{id} AND user_id NOT IN (#{collaborators.join ','})")
interested ? interested.size : 0
end
def can_translate?(user)
+1 -1
View File
@@ -1 +1 @@
=markdown @content
=markdown @message
@@ -0,0 +1,10 @@
%p=_'email.workshop.paragraph.request_message',"Below is a message from #{@requester.firstname}:", :vars => {:workshop_title => @workshop.title, :user_name => @requester.firstname}
%blockquote=markdown @message
%p
=_'email.workshop.paragraph.request_instructions',"You can approve or deny this request on your workshop page: "
- workshop_link = @host + view_workshop_url(@conference.slug, @workshop.id)
%a{href: workshop_link}=workshop_link
%p=_'email.workshop.paragraph.request_reply_instructions',"You can also reply directly to this email to ask follow-up questions."
@@ -0,0 +1,11 @@
=_'email.workshop.paragraph.request_message',"Below is a message from #{@requester.firstname}:", :vars => {:workshop_title => @workshop.title, :user_name => @requester.firstname}
=' ------------------------- '
=@message
=' ------------------------- '
=_'email.workshop.paragraph.request_instructions',"You can approve or deny this request on your workshop page: "
=@host + view_workshop_url(@conference.slug, @workshop.id)
=_'email.workshop.paragraph.request_reply_instructions',"You can also reply directly to this email to ask follow-up questions."
@@ -0,0 +1,4 @@
%p
- workshop_link = link_to (_!@workshop.title), @host + view_workshop_url(@conference.slug, @workshop.id).html_safe
=_'email.workshop.paragraph.request_approved',"You have been added as a facilitator of #{workshop_link}.", :vars => {:workshop_title => workshop_link}
@@ -0,0 +1,3 @@
=_'email.workshop.paragraph.request_approved',"Your request to become a facilitator of #{@workshop.title} has been approved and you may now edit the workshop.", :vars => {:workshop_title => @workshop.title}
=@host + view_workshop_url(@conference.slug, @workshop.id)
@@ -0,0 +1,3 @@
%p
- workshop_link = link_to (_!@workshop.title), @host + view_workshop_url(@conference.slug, @workshop.id).html_safe
=_'email.workshop.paragraph.request_denied',"Your request to become a facilitator of #{workshop_link} has been denied. If you think this was in error, you may contact the current facilitators by making another request to facilitate.", :vars => {:workshop_title => workshop_link}
@@ -0,0 +1,3 @@
=_'email.workshop.paragraph.request_denied',"Your request to become a facilitator of #{@workshop.title} has been denied. If you think this was in error, you may contact the current facilitators by making another request to facilitate.", :vars => {:workshop_title => @workshop.title}
=@host + view_workshop_url(@conference.slug, @workshop.id)
+15
View File
@@ -0,0 +1,15 @@
= render 'conferences/page_header', :page_key => 'Facilitate_Workshop'
%article
= row do
= form_tag facilitate_workshop_request_path(@this_conference.slug, @workshop.id), class: 'composition' do
= (hidden_field_tag :workshop_id, @workshop.id) if @workshop
= columns(medium: 12) do
%h2=_'articles.workshops.headings.facilitate', "Request to Facilitate #{@workshop.title}", :vars => { :workshop_title => @workshop.title }
=m('articles.workshops.paragraphs.facilitate_request','Please tell the current workshop facilitators who you are, why you want to help facilitate the workshop, and how you think you will help make the workshop better. All of the current facilitators will be emailed and they may ask more questions before approving or denying your request. Please note that this will reveal your email address to the facilitators.')
.text-area-field.input-field
= label_tag :message
= text_area_tag :message, nil, :required => true
= columns(medium: 12) do
.actions.right
= button_tag :send, :value => :send
@@ -0,0 +1,9 @@
= render 'conferences/page_header', :page_key => 'Facilitate_Workshop'
%article
= row do
= columns(medium: 12) do
=m('articles.workshops.paragraphs.facilitate_request_sent','Your request has been sent. You will receive an email once your request is approved or denied or if the current facilitators have any questions.')
= columns(medium: 12) do
.actions
= link_to (_'actions.workshops.View'), view_workshop_url(@this_conference.slug, @workshop.id), :class => 'button'
= link_to (_'actions.workshops.View_All'), workshops_url(@this_conference.slug), :class => 'button'
+27 -10
View File
@@ -12,14 +12,34 @@
= form_tag toggle_workshop_interest_path(@this_conference.slug, @workshop.id) do
= button_tag (@workshop.interested?(current_user) ? :remove_interest : :show_interest), :value => :toggle_interest, :class => (@workshop.interested?(current_user) ? 'delete' : 'add')
=markdown _!(@workshop.info) || ''
- if @workshop.can_translate?(current_user)
.actions
- I18n.backend.enabled_locales.each do |locale|
= (link_to (_'actions.workshops.Translate', "Translate into #{language_name(locale)}", :vars => {:language => language_name(locale)}), edit_workshop_url(@this_conference.slug, @workshop.id, url_params(locale)), :class => 'button translate') if locale.to_sym != I18n.locale.to_sym
= columns(medium: 6) do
%h3=_'articles.workshops.headings.facilitators'
.facilitators
- @workshop.workshop_facilitators.each do |f|
.facilitator
- u = User.find(f.user_id)
.name=_!(u.firstname || u.username || u.email)
.role=_"roles.workshops.facilitator.#{f.role}"
- u = User.find(f.user_id)
- if @workshop.public_facilitator?(u) || f.user_id == current_user.id || @workshop.active_facilitator?(current_user)
.facilitator
.name=_!(u.firstname || u.username || u.email)
.role
=_"roles.workshops.facilitator.#{@workshop.role(u).to_s}"
- if f.role.to_sym == :requested && @workshop.active_facilitator?(current_user)
=(link_to (_'actions.workshops.Approve'), approve_facilitate_workshop_request_path(@this_conference.slug, @workshop.id, f.user_id, 'approve'), :class => 'button modify')
=(link_to (_'actions.workshops.Deny'), approve_facilitate_workshop_request_path(@this_conference.slug, @workshop.id, f.user_id, 'deny'), :class => 'button delete')
- elsif (f.user_id == current_user.id && f.role.to_sym != :creator) || (!@this_conference.registered?(u) && @workshop.active_facilitator?(current_user))
=(link_to (_'actions.workshops.Remove'), approve_facilitate_workshop_request_path(@this_conference.slug, @workshop.id, f.user_id, 'remove'), :class => 'button delete')
.actions
=(link_to (_'actions.workshops.Facilitate'), facilitate_workshop_path(@this_conference.slug, @workshop.id), :class => 'button modify') if !@workshop.facilitator?(current_user)
- if @workshop.active_facilitator?(current_user)
= form_tag workshop_add_facilitator_path(@this_conference.slug, @workshop.id), :class => 'add-facilitator' do
%h4='Add a facilitator'
.email-field.input-field
= email_field_tag :email, nil, required: true
= label_tag :email
= button_tag :add
- if @workshop.languages
= columns(medium: 6) do
%h3=_'articles.workshops.headings.languages','Workshop Language'
@@ -28,7 +48,7 @@
= columns(medium: 6) do
%h3=_'articles.workshops.headings.theme','Theme'
%p= [:race_gender, :mechanics, :funding, :organization, :community].include?((@workshop.theme || '').to_sym) ? (_"workshop.options.theme.#{@workshop.theme}") : @workshop.theme
- if @workshop.can_edit?(current_user) || @this_conference.host?(current_user)
- if @workshop.active_facilitator?(current_user) || @this_conference.host?(current_user)
- if @workshop.needs
= columns(medium: 6) do
%h3=_'articles.workshops.headings.needs','What do you need?'
@@ -38,9 +58,6 @@
%h3=_'articles.workshops.headings.notes','Notes'
=markdown _!(@workshop.notes)
= columns(medium: 12) do
.actions
.actions.right
= (link_to (_'actions.workshops.Edit'), edit_workshop_path(@this_conference.slug, @workshop.id), :class => 'button modify') if @workshop.can_edit?(current_user)
- if @workshop.can_translate?(current_user)
- I18n.backend.enabled_locales.each do |locale|
= (link_to (_'actions.workshops.Translate', "Translate into #{language_name(locale)}", :vars => {:language => language_name(locale)}), edit_workshop_url(@this_conference.slug, @workshop.id, url_params(locale)), :class => 'button translate') if locale.to_sym != I18n.locale.to_sym
= (link_to (_'actions.workshops.Delete'), delete_workshop_path(@this_conference.slug, @workshop.id), :class => 'button delete') if @workshop.can_delete?(current_user)
= (link_to (_'actions.workshops.Delete'), delete_workshop_path(@this_conference.slug, @workshop.id), :class => 'button delete') if @workshop.can_delete?(current_user)