Merge pull request #560 from hennevogel/feature-user-view

Various small UI fixes
This commit is contained in:
Henne Vogelsang 2014-12-09 15:52:44 +01:00
commit b65a33f047
64 changed files with 932 additions and 2243 deletions

View file

@ -61,7 +61,6 @@ class Ability
signed_in(user) # Inherit abilities from signed user
# User with role
can :manage, User if user.is_admin # ??? || (user.has_role? :organizer, :any)
can [:new, :create], Conference if user.is_admin || (user.has_role? :organizer, :any)
can [:index, :show, :gallery_photos], Conference
can :manage, Conference, id: conf_ids_for_organizer
@ -100,45 +99,47 @@ class Ability
can :manage, CallForPaper, conference_id: conf_ids_for_organizer + conf_ids_for_cfp
can :manage, Venue, conference_id: conf_ids_for_organizer
can :index, Venue, conference_id: conf_ids_for_organizer + conf_ids_for_cfp
can :manage, :all if user.is_admin
end
# Abilities for everyone, even guests (not logged in users)
def guest
## Abilities for everyone, even guests (not logged in users)
can [:index, :show], Conference do |conference|
# can view conferences
can [:index], Conference
can [:show], Conference do |conference|
conference.splashpage && conference.splashpage.public == true
end
can [:schedule], Conference do |conference|
conference.call_for_paper && conference.call_for_paper.schedule_public
end
# see commercials too
# can view confirmed Events
can :show, Event do |event|
event.state == 'confirmed'
end
can :index, :schedule # show?
# can view Commercials of confirmed Events
can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id)
# can view others
can :show, User
end
def signed_in(user)
guest # Inherits abilities of guest
# Can subscribe, unsubscribe to a conference
# subscribe, unsubscribe to a Conference
can [:create, :destroy], Subscription, user_id: user.id
# Conference Registration
# can manage their own Registration
can :manage, Registration, user_id: user.id
# can manage their own User
can :manage, User, id: user.id
can :show, User
## Proposals
# Users can manage their own proposals
# can manage their own Event
can :manage, Event, id: user.events.pluck(:id)
# Submit proposals only for conferences that are not over yet
# can submit Events for conferences that are not over yet
can :create, Event, conference_id: Conference.where('end_date >= ?', Date.today).pluck(:id)
# Users can manage their own commercials
# can manage their own commercials
can :manage, Commercial, commercialable_type: 'Event', commercialable_id: user.events.pluck(:id)
# View commercials of confirmed events
can :show, Commercial, commercialable_type: 'Event', commercialable_id: Event.where(state: 'confirmed').pluck(:id)
end
end

View file

@ -101,6 +101,7 @@ class Conference < ActiveRecord::Base
validates_format_of :short_title, with: /\A[a-zA-Z0-9_-]*\z/
before_create :generate_guid
before_create :create_event_types
before_create :create_difficulty_levels
before_create :create_email_settings
before_create :add_color
@ -897,6 +898,22 @@ class Conference < ActiveRecord::Base
true
end
##
# Creates default DifficultyLevels for this Conference. Used as before_create.
#
def create_difficulty_levels
difficulty_levels << DifficultyLevel.create(title: 'Easy',
description: 'Events are understandable for everyone without knowledge of the topic.',
color: '#70EF69')
difficulty_levels << DifficultyLevel.create(title: 'Medium',
description: 'Events require a basic understanding of the topic.',
color: '#EEEF69')
difficulty_levels << DifficultyLevel.create(title: 'Hard',
description: 'Events require expert knowledge of the topic.',
color: '#EF6E69')
true
end
##
# Creates a EmailSettings association proxy. Used as before_create.
#

View file

@ -27,7 +27,7 @@ class EmailSettings < ActiveRecord::Base
conference.short_title, host: CONFIG['url_for_emails']),
'cfp_start_date' => conference.call_for_papers.start_date,
'cfp_end_date' => conference.call_for_papers.end_date,
'schedule_link' => Rails.application.routes.url_helpers.conference_schedule_url(
'schedule_link' => Rails.application.routes.url_helpers.schedule_conference_url(
conference.short_title, host: CONFIG['url_for_emails'])
}

View file

@ -13,11 +13,18 @@ class TicketPurchase < ActiveRecord::Base
scope: :ticket_id,
message: 'already bought this ticket!'
delegate :title, to: :ticket
delegate :description, to: :ticket
delegate :price, to: :ticket
delegate :price_cents, to: :ticket
delegate :price_currency, to: :ticket
def self.purchase(conference, user, purchases)
errors = []
ActiveRecord::Base.transaction do
conference.tickets.each do |ticket|
quantity = purchases[ticket.id.to_s].to_i
# if the user bought the ticket, just update the quantity
if ticket.bought?(user)
purchase = update_quantity(conference, quantity, ticket, user)
else

View file

@ -4,6 +4,7 @@ class Track < ActiveRecord::Base
has_many :events
before_create :generate_guid
validates :name, presence: true
validates :name, presence: true

View file

@ -59,13 +59,17 @@ class User < ActiveRecord::Base
self.subscriptions.find_by(conference_id: conference.id).present?
end
# Returns the ticket purchased ticket
# Returns the purchased ticket
# ====Returns
# * +TicketUser::ActiveRecord_Relation+ -> user
def ticket(id)
ticket_purchases.where(ticket_id: id).first
end
def supports? conference
ticket_purchases.find_by(conference_id: conference.id).present?
end
def self.for_ichain_username(username, attributes)
user = find_by(username: username)

View file

@ -17,7 +17,7 @@ class Venue < ActiveRecord::Base
after_update :send_mail_notification
def address
"#{conference.venue.street}, #{conference.venue.postalcode} #{conference.venue.city}, #{conference.venue.country}"
"#{street}, #{city}, #{country_name}"
end
def country_name