Merge branch 'master' into master

This commit is contained in:
Stella Rouzi 2017-07-05 16:37:49 +03:00 committed by GitHub
commit eca509ccc7
32 changed files with 1414 additions and 862 deletions

View file

@ -8,9 +8,9 @@ module Admin
return false
end
unless (current_user.has_role? :organizer, :any) || (current_user.has_role? :cfp, :any) ||
(current_user.has_role? :info_desk, :any) ||
(current_user.has_role? :info_desk, :any) || (current_user.has_role? :organization_admin, :any) ||
(current_user.has_role? :volunteers_coordinator, :any) || current_user.is_admin
raise CanCan::AccessDenied.new('You are not authorized to access this area!')
raise CanCan::AccessDenied.new('You are not authorized to access this page.')
end
end
end

View file

@ -0,0 +1,14 @@
module Admin
class PhysicalTicketController < Admin::BaseController
before_action :authenticate_user!
load_resource :conference, find_by: :short_title
load_and_authorize_resource
authorize_resource :conference_registrations, class: Registration
def index
@physical_tickets = @conference.physical_tickets
@tickets_sold_distribution = @conference.tickets_sold_distribution
@tickets_turnover_distribution = @conference.tickets_turnover_distribution
end
end
end

View file

@ -2,7 +2,7 @@ module Admin
class TracksController < Admin::BaseController
load_and_authorize_resource :conference, find_by: :short_title
load_and_authorize_resource :program, through: :conference, singleton: true
load_and_authorize_resource through: :program
load_and_authorize_resource through: :program, find_by: :short_name
def index; end
@ -53,7 +53,7 @@ module Admin
private
def track_params
params.require(:track).permit(:name, :description, :color)
params.require(:track).permit(:name, :description, :color, :short_name)
end
end
end

View file

@ -29,6 +29,7 @@ class Ability
# Abilities for not signed in users (guests)
def not_signed_in
can [:index], Organization
can [:index], Conference
can [:show], Conference do |conference|
conference.splashpage && conference.splashpage.public == true
@ -110,6 +111,7 @@ class Ability
# Abilities from not_signed_in and signed_in are also inherited
signed_in(user)
signed_in_with_organization_admin_role(user) if user.has_role? :organization_admin, :any
signed_in_with_organizer_role(user) if user.has_role? :organizer, :any
signed_in_with_cfp_role(user) if user.has_role? :cfp, :any
signed_in_with_info_desk_role(user) if user.has_role? :info_desk, :any
@ -146,57 +148,73 @@ class Ability
end
end
def signed_in_with_organizer_role(user)
# ids of all the conferences for which the user has the 'organizer' role
conf_ids_for_organizer = Conference.with_role(:organizer, user).pluck(:id)
def signed_in_with_organization_admin_role(user)
org_ids_for_organization_admin = Organization.with_role(:organization_admin, user).pluck(:id)
conf_ids_for_organization_admin = Conference.where(organization_id: org_ids_for_organization_admin).pluck(:id)
can :manage, Resource, conference_id: conf_ids_for_organizer
can [:new, :create], Conference if user.has_role?(:organizer, :any)
can :manage, Conference, id: conf_ids_for_organizer
can :manage, Splashpage, conference_id: conf_ids_for_organizer
can :manage, Contact, conference_id: conf_ids_for_organizer
can :manage, EmailSettings, conference_id: conf_ids_for_organizer
can :manage, Campaign, conference_id: conf_ids_for_organizer
can :manage, Target, conference_id: conf_ids_for_organizer
can :manage, Commercial, commercialable_type: 'Conference',
commercialable_id: conf_ids_for_organizer
can :manage, Registration, conference_id: conf_ids_for_organizer
can :manage, RegistrationPeriod, conference_id: conf_ids_for_organizer
can :manage, Question, conference_id: conf_ids_for_organizer
can :manage, Question do |question|
!(question.conferences.pluck(:id) & conf_ids_for_organizer).empty?
can [:read, :update, :destroy], Organization, id: org_ids_for_organization_admin
can :new, Conference
can :manage, Conference, organization_id: org_ids_for_organization_admin
can [:index, :show], Role
can [:edit, :update], Role do |role|
role.resource_type == 'Organization' && (org_ids_for_organization_admin.include? role.resource_id)
end
can :manage, Vposition, conference_id: conf_ids_for_organizer
can :manage, Vday, conference_id: conf_ids_for_organizer
can :manage, Program, conference_id: conf_ids_for_organizer
can :manage, Schedule, program: { conference_id: conf_ids_for_organizer }
can :manage, EventSchedule, schedule: { program: { conference_id: conf_ids_for_organizer } }
can :manage, Cfp, program: { conference_id: conf_ids_for_organizer }
can :manage, Event, program: { conference_id: conf_ids_for_organizer}
can :manage, EventType, program: { conference_id: conf_ids_for_organizer}
can :manage, Track, program: { conference_id: conf_ids_for_organizer}
can :manage, DifficultyLevel, program: { conference_id: conf_ids_for_organizer}
signed_in_with_organizer_role(user, conf_ids_for_organization_admin)
end
def signed_in_with_organizer_role(user, conf_ids_for_organization_admin = [])
# ids of all the conferences for which the user has the 'organizer' role and
# conferences that belong to organizations for which user is 'organization_admin'
conf_ids = conf_ids_for_organization_admin.concat(Conference.with_role(:organizer, user).pluck(:id)).uniq
can :manage, Resource, conference_id: conf_ids
can [:read, :update, :destroy], Conference, id: conf_ids
can :manage, Splashpage, conference_id: conf_ids
can :manage, Contact, conference_id: conf_ids
can :manage, EmailSettings, conference_id: conf_ids
can :manage, Campaign, conference_id: conf_ids
can :manage, Target, conference_id: conf_ids
can :manage, Commercial, commercialable_type: 'Conference',
commercialable_id: conf_ids
can :manage, Registration, conference_id: conf_ids
can :manage, RegistrationPeriod, conference_id: conf_ids
can :manage, Question, conference_id: conf_ids
can :manage, Question do |question|
!(question.conferences.pluck(:id) & conf_ids).empty?
end
can :manage, Vposition, conference_id: conf_ids
can :manage, Vday, conference_id: conf_ids
can :manage, Program, conference_id: conf_ids
can :manage, Schedule, program: { conference_id: conf_ids }
can :manage, EventSchedule, schedule: { program: { conference_id: conf_ids } }
can :manage, Cfp, program: { conference_id: conf_ids}
can :manage, Event, program: { conference_id: conf_ids}
can :manage, EventType, program: { conference_id: conf_ids}
can :manage, Track, program: { conference_id: conf_ids}
can :manage, DifficultyLevel, program: { conference_id: conf_ids}
can :manage, Commercial, commercialable_type: 'Event',
commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organizer).pluck(:id)).pluck(:id)
can :manage, Venue, conference_id: conf_ids_for_organizer
commercialable_id: Event.where(program_id: Program.where(conference_id: conf_ids).pluck(:id)).pluck(:id)
can :manage, Venue, conference_id: conf_ids
can :manage, Commercial, commercialable_type: 'Venue',
commercialable_id: Venue.where(conference_id: conf_ids_for_organizer).pluck(:id)
can :manage, Lodging, conference_id: conf_ids_for_organizer
can :manage, Room, venue: { conference_id: conf_ids_for_organizer}
can :manage, Sponsor, conference_id: conf_ids_for_organizer
can :manage, SponsorshipLevel, conference_id: conf_ids_for_organizer
can :manage, Ticket, conference_id: conf_ids_for_organizer
commercialable_id: Venue.where(conference_id: conf_ids).pluck(:id)
can :manage, Lodging, conference_id: conf_ids
can :manage, Room, venue: { conference_id: conf_ids}
can :manage, Sponsor, conference_id: conf_ids
can :manage, SponsorshipLevel, conference_id: conf_ids
can :manage, Ticket, conference_id: conf_ids
can :index, Comment, commentable_type: 'Event',
commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_organizer).pluck(:id)).pluck(:id)
commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids).pluck(:id)).pluck(:id)
# Abilities for Role (Conference resource)
can [:index, :show], Role
can [:index, :show], Role do |role|
role.resource_type == 'Conference'
end
can [:edit, :update, :toggle_user], Role do |role|
role.resource_type == 'Conference' && (conf_ids_for_organizer.include? role.resource_id)
role.resource_type == 'Conference' && (conf_ids.include? role.resource_id)
end
can [:index, :revert_object, :revert_attribute], PaperTrail::Version do |version|
version.item_type == 'User' || (conf_ids_for_organizer.include? version.conference_id)
version.item_type == 'User' || (conf_ids.include? version.conference_id)
end
end
@ -222,8 +240,9 @@ class Ability
commentable_id: Event.where(program_id: Program.where(conference_id: conf_ids_for_cfp).pluck(:id)).pluck(:id)
# Abilities for Role (Conference resource)
can [:index, :show], Role
can [:index, :show], Role do |role|
role.resource_type == 'Conference'
end
# Can add or remove users from role, when user has that same role for the conference
# Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP')
can :toggle_user, Role do |role|
@ -251,8 +270,9 @@ class Ability
end
# Abilities for Role (Conference resource)
can [:index, :show], Role
can [:index, :show], Role do |role|
role.resource_type == 'Conference'
end
# Can add or remove users from role, when user has that same role for the conference
# Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP')
can :toggle_user, Role do |role|
@ -270,8 +290,9 @@ class Ability
can :manage, Vday, conference_id: conf_ids_for_volunteers_coordinator
# Abilities for Role (Conference resource)
can [:index, :show], Role
can [:index, :show], Role do |role|
role.resource_type == 'Conference'
end
# Can add or remove users from role, when user has that same role for the conference
# Eg. If you are member of the CfP team, you can add more CfP team members (add users to the role 'CfP')
can :toggle_user, Role do |role|

View file

@ -1,7 +1,17 @@
class Organization < ActiveRecord::Base
resourcify :roles, dependent: :delete_all
has_many :conferences, dependent: :destroy
after_create :create_roles
validates :name, presence: true
mount_uploader :picture, PictureUploader, mount_on: :picture
private
def create_roles
roles.where(name: 'organization_admin').first_or_create(description: 'For the administrators of an organization and its conferences')
end
end

View file

@ -56,7 +56,7 @@ class Ticket < ActiveRecord::Base
end
def tickets_sold
ticket_purchases.sum(:quantity)
ticket_purchases.paid.sum(:quantity)
end
def tickets_turnover

View file

@ -7,6 +7,12 @@ class Track < ActiveRecord::Base
before_create :generate_guid
validates :name, presence: true
validates :color, format: /\A#[0-9A-F]{6}\z/
validates :short_name,
presence: true,
format: /\A[a-zA-Z0-9_-]*\z/,
uniqueness: {
scope: :program
}
before_validation :capitalize_color

View file

@ -0,0 +1,43 @@
.container
.row
.col-md-12.page-header
%h2
Tickets Sold
.text-muted
Tickets sold for the conference
.row
.col-md-4
= render partial: 'admin/conferences/doughnut_chart',
locals: { title: 'Tickets sold', data: @tickets_sold_distribution }
.col-md-4
= render partial: 'admin/conferences/doughnut_chart',
locals: {title: 'Tickets turnover', data: @tickets_turnover_distribution}
%br
- if @physical_tickets.any?
.row
.col-md-12
%table.table.table-hover.datatable#tickets
%thead
%th ID
%th Type
%th User
%th Actions
%tbody
- @physical_tickets.each do |physical_ticket|
%tr
%td= physical_ticket.id
%td= physical_ticket.ticket.title
%td= physical_ticket.user.email
%td
.btn-group
= link_to 'Show',
conference_physical_ticket_path(@conference.short_title,
physical_ticket.id),
class: 'btn btn-primary'
= link_to 'Generate PDF',
conference_physical_ticket_path(@conference.short_title,
physical_ticket.id,
format: :pdf),
class: 'button btn btn-default btn-info'
- else
%h5 No Tickets sold!

View file

@ -25,5 +25,5 @@
= link_to 'Delete', admin_conference_registration_period_path,
method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-danger'
- else
- if can? :create, @conference
- if can? :create, @conference.build_registration_period
= link_to 'New Registration Period', new_admin_conference_registration_period_path, class: 'btn btn-primary'

View file

@ -90,5 +90,5 @@
- else
.row
.col-md-12.text-right
- if can? :create, @conference
- if can? :create, @conference.build_splashpage
= link_to 'Create Splashpage', new_admin_conference_splashpage_path, class: 'btn btn-primary'

View file

@ -4,11 +4,6 @@
%h1 Tickets
%p.text-muted
Tickets to get during registration
.row
.col-md-4
= render partial: 'admin/conferences/doughnut_chart', locals: { title: 'Tickets sold', data: @tickets_sold_distribution,}
.col-md-4
= render partial: 'admin/conferences/doughnut_chart', locals: { title: 'Tickets turnover', data: @tickets_turnover_distribution }
%br
- if @conference.tickets.any?
.row
@ -42,3 +37,4 @@
.row
.col-md-12
= link_to 'Add Ticket', new_admin_conference_ticket_path, class: 'btn btn-success pull-right'
= link_to 'Tickets Sold', admin_conference_physical_ticket_index_path, class: 'button btn btn-default btn-info pull-right'

View file

@ -8,8 +8,9 @@
Track
.row
.col-md-12
= semantic_form_for(@track, url: (@track.new_record? ? admin_conference_program_tracks_path : admin_conference_program_track_path(@conference.short_title, @track))) do |f|
= semantic_form_for(@track, url: (@track.new_record? ? admin_conference_program_tracks_path : admin_conference_program_track_path(@conference.short_title, @track.short_name))) do |f|
= f.input :name
= f.input :short_name, hint: "A short and unique handle for the track, using only letters, numbers, underscores, and dashes. This will be used to identify the track in URLs etc. Example: 'my_awesome_track'", input_html: { required: 'required', pattern: '[a-zA-Z0-9_-]+', title: 'Only letters, numbers, underscores, and dashes.' }
= f.input :color, input_html: {size: 6, type: 'color'}, required: true
= f.input :description, input_html: {rows: 2, data: { provide: 'markdown-editable' } }, hint: markdown_hint
= f.action :submit, as: :button, button_html: { class: 'btn btn-primary' }

View file

@ -9,6 +9,7 @@
%table.table.table-hover#tracks
%thead
%th Name
%th Short name
%th Description
%th Color
%th Actions
@ -16,8 +17,10 @@
- @tracks.each do |track|
%tr
%td
= link_to(admin_conference_program_track_path(@conference.short_title, track)) do
= link_to(admin_conference_program_track_path(@conference.short_title, track.short_name)) do
= track.name
%td
= track.short_name
%td
%p
= truncate(track.description)
@ -26,9 +29,9 @@
= track.color
%td
.btn-group{role: "group"}
= link_to 'Edit', edit_admin_conference_program_track_path(@conference.short_title, track.id),
= link_to 'Edit', edit_admin_conference_program_track_path(@conference.short_title, track.short_name),
method: :get, class: 'btn btn-primary'
= link_to 'Delete', admin_conference_program_track_path(@conference.short_title, track.id),
= link_to 'Delete', admin_conference_program_track_path(@conference.short_title, track.short_name),
method: :delete, class: 'btn btn-danger',
data: { confirm: "Do you really want to delete #{track.name}? Attention: This track will be removed from all Events that have it set" }
.row

View file

@ -94,7 +94,7 @@
= 'track'
- track = current_or_last_object_state(version.item_type, version.item_id)
= link_if_alive version, track.name,
admin_conference_program_track_path(conference_id: Conference.find(version.conference_id).short_title, id: version.item_id)
admin_conference_program_track_path(conference_id: Conference.find(version.conference_id).short_title, id: track.try(:short_name))
- when 'EventType'
= 'event type'