Skip to content

Commit

Permalink
Merge branch 'master' into error_opening_link_to_difficulty_level
Browse files Browse the repository at this point in the history
  • Loading branch information
bear454 authored Nov 3, 2017
2 parents 77d8bfe + f0016cb commit ae0538e
Show file tree
Hide file tree
Showing 16 changed files with 88 additions and 52 deletions.
14 changes: 12 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ RUN cd /usr/bin && \
tar -xf dockerize.tar.gz && \
rm dockerize.tar.gz

# dumb-init for a proper PID 1
RUN cd /tmp && \
wget https://github.com/Yelp/dumb-init/releases/download/v1.2.0/dumb-init_1.2.0_amd64.deb && \
dpkg -i dumb-init_1.2.0_amd64.deb && \
rm dumb-init_1.2.0_amd64.deb

# explicitly add Gemfile and install dependencies using bundler to make use of
# Docker's caching
WORKDIR /osem/
Expand All @@ -25,12 +31,13 @@ RUN bundle install --without test development

# add OSEM files and prepare them for use inside a Docker container
COPY . /osem/
RUN chown osem.osem /osem/ -R && \
RUN chown -R osem.root /osem/ && \
chmod -R g=u /osem/ && \
mv /osem/config/database.yml.docker /osem/config/database.yml

# data directory is used to cache the secret key in a file
ENV DATA_DIR /data
RUN install -d -m 0700 -o osem $DATA_DIR
RUN install -d -m 0770 -o osem -g root $DATA_DIR
VOLUME ["$DATA_DIR"]

USER osem
Expand All @@ -42,4 +49,7 @@ COPY docker/init.sh /init.sh
# from a webserver
ENV RAILS_SERVE_STATIC_FILES 1

# Runs "/usr/bin/dumb-init -- /my/script --with --args"
ENTRYPOINT ["/usr/bin/dumb-init", "--"]

CMD ["bash", "/init.sh"]
2 changes: 1 addition & 1 deletion app/assets/javascripts/osem-tickets.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function update_price($this){
$('.total_row').each(function( index ) {
total += parseFloat($(this).text());
});
$('#total_price').text(total);
$('#total_price').text(total.toFixed(2));
}

$( document ).ready(function() {
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/conference_registrations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ def new
end

def show
@total_price = Ticket.total_price(@conference, current_user, paid: true)
@total_price = Ticket.total_price_user(@conference, current_user, paid: true)
@tickets = current_user.ticket_purchases.by_conference(@conference).paid
@total_price_per_ticket = @tickets.group(:ticket_id).sum('amount_paid * quantity')
@ticket_payments = @tickets.group_by(&:ticket_id)
@total_quantity = @tickets.group(:ticket_id).sum(:quantity)
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/conference.rb
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ def tickets_turnover_distribution
if tickets && ticket_purchases
tickets.each do |ticket|
result[ticket.title] = {
'value' => ApplicationController.helpers.humanized_money(ticket.tickets_turnover).delete(',').to_i,
'value' => ApplicationController.helpers.humanized_money(ticket.tickets_turnover_total(ticket.id)).delete(',').to_i,
'color' => "\##{Digest::MD5.hexdigest(ticket.title)[0..5]}"
}
end
Expand Down
14 changes: 10 additions & 4 deletions app/models/ticket.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,18 @@ def self.total_price(conference, user, paid: false)
result ? result : Money.new(0, 'USD')
end

def tickets_sold
ticket_purchases.paid.sum(:quantity)
def self.total_price_user(conference, user, paid: false)
tickets = TicketPurchase.where(conference: conference, user: user, paid: paid)
tickets.inject(0){ |sum, ticket| sum + (ticket.amount_paid * ticket.quantity) }
end

def tickets_turnover_total(id)
tickets = TicketPurchase.where(ticket_id: id)
tickets.inject(0){ |sum, ticket| sum + (ticket.amount_paid * ticket.quantity) }
end

def tickets_turnover
tickets_sold * price
def tickets_sold
ticket_purchases.paid.sum(:quantity)
end

private
Expand Down
3 changes: 2 additions & 1 deletion app/models/ticket_purchase.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ def self.purchase_ticket(conference, quantity, ticket, user)
purchase = new(ticket_id: ticket.id,
conference_id: conference.id,
user_id: user.id,
quantity: quantity)
quantity: quantity,
amount_paid: ticket.price)
purchase.pay(nil) if ticket.price_cents.zero?
end
purchase
Expand Down
16 changes: 16 additions & 0 deletions app/views/admin/physical_tickets/_physical_ticket.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
%tr
%td= physical_ticket.id
%td= physical_ticket.ticket.title
%td= physical_ticket.user.email
%td= humanized_money_with_symbol physical_ticket.ticket_purchase.amount_paid
%td
.btn-group
= link_to 'Show',
conference_physical_ticket_path(conference.short_title,
physical_ticket.token),
class: 'btn btn-primary'
= link_to 'Generate PDF',
conference_physical_ticket_path(conference.short_title,
physical_ticket.token,
format: :pdf),
class: 'button btn btn-default btn-info'
18 changes: 3 additions & 15 deletions app/views/admin/physical_tickets/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -21,23 +21,11 @@
%th ID
%th Type
%th User
%th Paid
%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.token),
class: 'btn btn-primary'
= link_to 'Generate PDF',
conference_physical_ticket_path(@conference.short_title,
physical_ticket.token,
format: :pdf),
class: 'button btn btn-default btn-info'
= render "physical_ticket", physical_ticket: physical_ticket,
conference: @conference
- else
%h5 No Tickets sold!
2 changes: 1 addition & 1 deletion app/views/admin/tickets/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
%td
= ticket.tickets_sold
%td
= humanized_money_with_symbol ticket.tickets_turnover
= humanized_money_with_symbol ticket.tickets_turnover_total(ticket.id)
%td
= ticket.registration_ticket? ? 'Yes' : 'No'
%td
Expand Down
2 changes: 1 addition & 1 deletion app/views/conference_registrations/show.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@
= word_pluralize(@total_quantity[ticket_id], 'Ticket')
for
= tickets.first.price.symbol
= humanized_money tickets.first.price
= humanized_money @total_price_per_ticket[ticket_id]
%br
- if @tickets.any?
= link_to 'Get more tickets', conference_tickets_path(@conference.short_title), class: "btn btn-default"
Expand Down
13 changes: 7 additions & 6 deletions app/views/proposals/_tooltip.html.haml
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
- progress_status = event.progress_status
%ul.list-unstyled
%li{'class'=>class_for_todo(progress_status['registered'])}
%span{'class'=>icon_for_todo(progress_status['registered'])}
- if progress_status['registered']
Speaker(s) registered to the conference
- else
= link_to 'Speaker(s) not registered to the conference', new_conference_conference_registration_path(event.program.conference.short_title)
- if can? :create, @conference.registrations.new
%li{'class'=>class_for_todo(progress_status['registered'])}
%span{'class'=>icon_for_todo(progress_status['registered'])}
- if progress_status['registered']
Speaker(s) registered to the conference
- else
= link_to 'Speaker(s) not registered to the conference', new_conference_conference_registration_path(event.program.conference.short_title)
%li{'class'=>class_for_todo(progress_status['biographies'])}
%span{'class'=>icon_for_todo(progress_status['biographies'])}
- if progress_status['biographies']
Expand Down
35 changes: 21 additions & 14 deletions app/views/proposals/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@
The more information you add to your proposal, the more likely it is that the conference organizers accept your proposal.
%br
It will also be more likely that visitors find your proposal interesting enough to attend.

%p
%strong
Why do I need to register to the conference?
%p
Knowing the number of visitors for the conference helps the organizers plan better.
- if can? :create, @conference.registrations.new
%p
%strong
Why do I need to register to the conference?
%p
Knowing the number of visitors for the conference helps the organizers plan better.

%table.table.table-striped#events
- @events.each do |event|
Expand All @@ -67,20 +67,27 @@
%small.text-muted
= event.event_type.title
= "(#{event.event_type.length} min)"
= "in #{event.track.name}" if event.track
= "in #{event.traistck.name}" if event.track
- if event.require_registration
%br
= link_to registered_text(event), registrations_conference_program_proposal_path(@conference.short_title, event), class: 'btn btn-xs btn-danger'

%td.col-md-2{style: "padding:20px 8px 20px 8px;"}
= link_to 'Complete your proposal', 'javascript: void(0)', "type"=>"button", "data-trigger"=>"focus", "data-toggle"=>"popover", "title"=>"Your todo list", "data-content"=>"#{render partial: 'tooltip', locals: { event: event} }"

- progress_percentage = event.calculate_progress
.progress
%div{class: "progress-bar #{event_progress_color(progress_percentage)}", style: "width:#{progress_percentage}%;"}
= event.progress_status.reject{ |_key, value| value || value.nil? }.length
left

- if can? :create, @conference.registrations.new
- progress_percentage = event.calculate_progress
.progress
%div{class: "progress-bar #{event_progress_color(progress_percentage)}", style: "width:#{progress_percentage}%;"}
= event.progress_status.reject{ |_key, value| value || value.nil? }.length
left
- else
:ruby
progress_list = event.progress_status
progress_percentage = (100 * progress_list.values.count(true) / (progress_list.values.compact.count-1)).to_s
.progress
%div{class: "progress-bar #{event_progress_color(progress_percentage)}", style: "width:#{progress_percentage}%;"}
= event.progress_status.reject{ |_key, value| value || value.nil? }.length-1
left
%td.col-md-3{style: "padding:20px 0px 20px 0px;"}
.pull-right
- if event.transition_possible? :confirm
Expand Down
4 changes: 2 additions & 2 deletions config/deploy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
require 'mina/git'

set :domain, 'proxy-opensuse.suse.de'
set :port, 2214
set :port, 2252
set :user, 'osem'
set :deploy_to, '/srv/www/vhosts/opensuse.org/events'
set :repository, 'https://github.com/openSUSE/osem.git'
Expand Down Expand Up @@ -42,7 +42,7 @@
#invoke :notify_errbit

to :launch do
queue "sudo /etc/init.d/apache2 restart"
queue "sudo /usr/bin/systemctl restart apache2"
queue "cd #{deploy_to}/current && RAILS_ENV=production bin/delayed_job start"
end

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddAmountPaidToTicketPurchases < ActiveRecord::Migration
def change
add_column :ticket_purchases, :amount_paid, :float, default: 0
end
end
3 changes: 2 additions & 1 deletion db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema.define(version: 20170816203325) do
ActiveRecord::Schema.define(version: 20170924190528) do

create_table "ahoy_events", force: :cascade do |t|
t.uuid "visit_id", limit: 16
Expand Down Expand Up @@ -504,6 +504,7 @@
t.integer "user_id"
t.integer "payment_id"
t.integer "week"
t.float "amount_paid"
end

create_table "ticket_scannings", force: :cascade do |t|
Expand Down
4 changes: 2 additions & 2 deletions spec/controllers/conference_registration_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@
end

it 'does not assign price of purchased tickets to total_price and purchased tickets to tickets without payment' do
expect(assigns(:total_price)).to eq Money.new(0, 'USD')
expect(assigns(:total_price)).to eq 0
end
end

Expand All @@ -262,7 +262,7 @@
end

it 'assigns 0 dollars to total_price and empty array to tickets variables' do
expect(assigns(:total_price)).to eq Money.new(0, 'USD')
expect(assigns(:total_price)).to eq 0
expect(assigns(:tickets)).to match_array []
end
end
Expand Down

0 comments on commit ae0538e

Please sign in to comment.