Skip to content

Commit

Permalink
Merge branch 'staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
wilco375 committed Jan 4, 2024
2 parents ac27a5b + 7b1df95 commit bc33ba2
Show file tree
Hide file tree
Showing 39 changed files with 180 additions and 91 deletions.
4 changes: 4 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ AMBER_CLIENT_SECRET=
FROM_EMAIL=[email protected]
ICT_EMAIL=[email protected]
ADMIN_EMAIL=[email protected]
TREASURER_TITLE=penningmeester
TREASURER_EMAIL=[email protected]
TREASURER_NAME=
TREASURER_PHONE=
Expand All @@ -28,12 +29,15 @@ COMPANY_KVK=41 032 169

SITE_NAME=S.O.F.I.A.
SITE_SHORT_NAME=SOFIA
SITE_LONG_NAME=Streepsysteem voor de Ordentelijke Festiviteiten van Inleggend Alpha
SITE_ASSOCIATION=C.S.V. Alpha

CODE_BEER=8010
CODE_LOW_ALCOHOL_BEER=8011
CODE_CRAFT_BEER=8015
CODE_NON_ALCOHOLIC=8020
CODE_DISTILLED=8030
CODE_WHISKEY=8035
CODE_WINE=8040
CODE_FOOD=8050
CODE_TOBACCO=8060
Expand Down
26 changes: 24 additions & 2 deletions .github/workflows/continuous-delivery.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@ on:
description: Merge staging into master first? (y/N)
required: false
default: 'n'
target_env:
type: choice
description: Target environment
options:
- csvalpha
- luxadmosam
default: 'csvalpha'

concurrency:
group: cd-${{ github.ref_name }}
Expand All @@ -20,11 +27,17 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Validate branch
env:
TARGET_ENV: ${{ github.event.inputs.target_env }}
run: |
if [ "$GITHUB_REF_NAME" != 'staging' ] && [ "$GITHUB_REF_NAME" != 'master' ]; then
echo 'This workflow can only be run on branches staging and master.'
exit 1
fi
if [ "$TARGET_ENV" == 'luxadmosam' ] && [ "$GITHUB_REF_NAME" != 'master' ]; then
echo 'Only the master branch can be deployed to Lux ad Mosam.'
exit 1
fi
metadata:
name: Metadata
Expand All @@ -41,6 +54,7 @@ jobs:
id: get_metadata
env:
INPUT_MERGE: ${{ github.event.inputs.merge }}
TARGET_ENV: ${{ github.event.inputs.target_env }}
run: |
if [ "$GITHUB_REF_NAME" = 'master' ]; then
if [ "${INPUT_MERGE,,}" = 'y' ]; then
Expand All @@ -52,7 +66,11 @@ jobs:
fi
fi
echo 'stage=production' >> "$GITHUB_OUTPUT"
if [ "$TARGET_ENV" == 'luxadmosam' ]; then
echo 'stage=luxproduction' >> "$GITHUB_OUTPUT"
else
echo 'stage=production' >> "$GITHUB_OUTPUT"
fi
else
echo 'stage=staging' >> "$GITHUB_OUTPUT"
fi
Expand Down Expand Up @@ -130,8 +148,12 @@ jobs:
steps:
- name: Get environment URL
id: get_url
env:
TARGET_ENV: ${{ github.event.inputs.target_env }}
run: |
if [ "$GITHUB_REF_NAME" = 'master' ]; then
if [ "$TARGET_ENV" == 'luxadmosam' ] && [ "$GITHUB_REF_NAME" = 'master' ]; then
echo 'environment_url=https://luxstreep.csvalpha.nl' >> "$GITHUB_OUTPUT"
elif [ "$GITHUB_REF_NAME" = 'master' ]; then
echo 'environment_url=https://streep.csvalpha.nl' >> "$GITHUB_OUTPUT"
else
echo 'environment_url=https://stagingstreep.csvalpha.nl' >> "$GITHUB_OUTPUT"
Expand Down
1 change: 1 addition & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ AllCops:
Rails/UnknownEnv:
Environments:
- production
- luxproduction
- development
- test
- staging
Expand Down
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ ARG RAILS_MASTER_KEY

# Pre-install gems, so that they can be cached.
COPY Gemfile* /app/
RUN if [ "$RAILS_ENV" = 'production' ] || [ "$RAILS_ENV" = 'staging' ]; then \
RUN if [ "$RAILS_ENV" = 'production' ] || [ "$RAILS_ENV" = 'staging' ] || [ "$RAILS_ENV" = 'luxproduction' ]; then \
bundle config set --local without 'development test'; \
else \
bundle config set --local without 'development'; \
Expand All @@ -44,7 +44,7 @@ COPY . /app/

# Precompile assets after copying app because whole Rails pipeline is needed.
RUN --mount=type=secret,id=rails_master_key \
if [ "$RAILS_ENV" = 'production' ] || [ "$RAILS_ENV" = 'staging' ]; then \
if [ "$RAILS_ENV" = 'production' ] || [ "$RAILS_ENV" = 'staging' ] || [ "$RAILS_ENV" = 'luxproduction' ]; then \
# Use secret if RAILS_MASTER_KEY build arg is not set.
RAILS_MASTER_KEY="${RAILS_MASTER_KEY:-$(cat /run/secrets/rails_master_key)}" bundle exec rails assets:precompile; \
else \
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/credit_mutations_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ def create # rubocop:disable Metrics/MethodLength, Metrics/AbcSize

respond_to do |format|
if @mutation.save
NewCreditMutationNotificationJob.perform_later(@mutation) if Rails.env.production? || Rails.env.staging?
NewCreditMutationNotificationJob.perform_later(@mutation) if Rails.env.production? || Rails.env.staging? || Rails.env.luxproduction?
format.html { redirect_to which_redirect?, flash: { success: 'Inleg of mutatie aangemaakt' } }
format.json do
render json: @mutation, include: { user: { methods: User.orderscreen_json_includes } }
Expand Down
16 changes: 12 additions & 4 deletions app/controllers/payments_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,15 @@ def create # rubocop:disable Metrics/AbcSize
end
end

def add
def add # rubocop:disable Metrics/AbcSize
authorize :payment

if Rails.application.config.x.mollie_api_key.blank?
flash[:error] = 'iDEAL is niet beschikbaar'
redirect_to users_path
return
end

@user = current_user
@payment = Payment.new

Expand All @@ -39,16 +45,18 @@ def callback # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/Pe
end

if payment.completed?
flash[:error] = 'Deze betaling is al gesloten. Mocht het bedrag niet bij uw inleg staan neem dan contact op met de penningmeester.'
flash[:error] =
"Deze betaling is al gesloten. Mocht het bedrag niet bij uw inleg staan
neem dan contact op met de #{Rails.application.config.x.treasurer_title}"
else
tries = 3
begin
payment.update(status: payment.mollie_payment.status)
if payment.mollie_payment.paid?
flash[:success] = 'iDEAL betaling geslaagd'
else
flash[:error] = 'Uw iDEAL betaling is mislukt.
Mocht het bedrag wel van uw rekening zijn gegaan neem dan contact op met de penningmeester'
flash[:error] = "Uw iDEAL betaling is mislukt. Mocht het bedrag wel van uw rekening zijn gegaan
neem dan contact op met de #{Rails.application.config.x.treasurer_title}"
end
rescue ActiveRecord::StaleObjectError => e
raise e unless (tries -= 1).positive?
Expand Down
2 changes: 1 addition & 1 deletion app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def activities # rubocop:disable Metrics/AbcSize
private

def send_slack_users_refresh_notification
return unless Rails.env.production? || Rails.env.staging?
return unless Rails.env.production? || Rails.env.staging? || Rails.env.luxproduction?

# :nocov:
SlackMessageJob.perform_later("User ##{current_user.id} (#{current_user.name}) "\
Expand Down
4 changes: 2 additions & 2 deletions app/jobs/credit_insufficient_notification_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ def users_with_insufficient_credit
User.all.select { |user| user.credit.negative? }
end

def send_notification_delivery_reports(success_count, unnotifyable_users)
def send_notification_delivery_reports(success_count, unnotifyable_users) # rubocop:disable Metrics/AbcSize
User.treasurer.each do |treasurer|
UserCreditMailer.credit_delivery_report_mail(
treasurer, success_count, unnotifyable_users
).deliver_later
end

return unless Rails.env.production? || Rails.env.staging?
return unless Rails.env.production? || Rails.env.staging? || Rails.env.luxproduction?

SlackMessageJob.perform_later("Er is voor #{Rails.application.config.x.amber_api_host} een saldomail "\
"verstuurd naar #{success_count} mensen, en #{unnotifyable_users.count} saldomail(s) kon(den) niet "\
Expand Down
2 changes: 1 addition & 1 deletion app/jobs/payment_poll_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def perform
# it will be checked again the next time this poll job runs
end

return unless Rails.env.production? || Rails.env.staging?
return unless Rails.env.production? || Rails.env.staging? || Rails.env.luxproduction?

HealthCheckJob.perform_later('payment_poll')
end
Expand Down
10 changes: 7 additions & 3 deletions app/mailers/invoice_mailer.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
class InvoiceMailer < ApplicationMailer
def invoice_mail(invoice) # rubocop:disable Metrics/AbcSize
def invoice_mail(invoice) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength
@user = Struct.new(:name).new(invoice.name)
@invoice = invoice
@cab_link = url_for(controller: 'invoices', action: 'show', id: invoice.token)
@cab_text = 'iDeal betaling'
if Rails.application.config.x.mollie_api_key.present?
@cab_link = url_for(controller: 'invoices', action: 'show', id: invoice.token)
@cab_text = 'iDeal betaling'
else
@cab_disabled = true
end

attachments["#{invoice.human_id}.pdf"] = WickedPdf.new.pdf_from_string(
render_to_string(pdf: invoice.human_id.to_s, template: 'invoices/show', layout: 'pdf')
Expand Down
5 changes: 3 additions & 2 deletions app/models/product.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
class Product < ApplicationRecord
enum category: { beer: 0, craft_beer: 6, non_alcoholic: 1, distilled: 2, wine: 3, food: 4, tobacco: 5, donation: 7 }
enum category: { beer: 0, low_alcohol_beer: 9, craft_beer: 6, non_alcoholic: 1, distilled: 2, whiskey: 8, wine: 3, food: 4, tobacco: 5,
donation: 7 }

has_many :product_prices, dependent: :destroy
has_many :price_lists, through: :product_prices, dependent: :restrict_with_error
Expand All @@ -10,7 +11,7 @@ class Product < ApplicationRecord
accepts_nested_attributes_for :product_prices, allow_destroy: true

def requires_age
%w[beer craft_beer distilled wine tobacco].include? category
%w[beer craft_beer distilled whiskey wine tobacco].include? category
end

def t_category
Expand Down
2 changes: 1 addition & 1 deletion app/models/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Role < ApplicationRecord

def name
if treasurer?
'Penningmeester'
Rails.application.config.x.treasurer_title
elsif main_bartender?
'Hoofdtapper'
end
Expand Down
12 changes: 8 additions & 4 deletions app/policies/payment_policy.rb
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
class PaymentPolicy < ApplicationPolicy
def index?
user.treasurer?
mollie_enabled? && user.treasurer?
end

def create?
user
mollie_enabled? && user
end

def add?
user
mollie_enabled? && user
end

def invoice_callback?
record && !record.completed?
mollie_enabled? && record && !record.completed?
end

def mollie_enabled?
Rails.application.config.x.mollie_api_key.present?
end
end
2 changes: 1 addition & 1 deletion app/views/activities/_cannot_order_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
</div>
<div class="modal-body" v-if="this.selectedUser">
{{this.selectedUser.name}} staat <b class="text-danger">{{this.doubleToCurrency(-this.selectedUser.credit)}}</b> negatief en moet eerst inleggen om te kunnen bestellen!
Vraag de gebruiker om zijn of haar saldo op te waarderen via iDEAL of contante inleg.
Vraag de gebruiker om zijn of haar saldo op te waarderen.
</div>
<div class="modal-footer">
<button class="btn btn-secondary me-1" data-bs-dismiss="modal" type="button">
Expand Down
28 changes: 15 additions & 13 deletions app/views/activities/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,17 @@
</thead>
<tbody class="table-group-divider">
<% Product.categories.each do |category| %>
<tr>
<td><%= t(category.first).capitalize %>
</td>
<td><%= t("codes.#{category.first}") %>
</td>
<td class="text-end">
<%= number_to_currency(@revenue_by_category[category[0]] || 0, unit: '€') %>
</td>
</tr>
<% if Rails.application.config.x.codes[category.first.to_sym] != nil %>
<tr>
<td><%= t(category.first).capitalize %>
</td>
<td><%= Rails.application.config.x.codes[category.first.to_sym] %>
</td>
<td class="text-end">
<%= number_to_currency(@revenue_by_category[category[0]] || 0, unit: '€') %>
</td>
</tr>
<% end %>
<% end %>
<tr>
<th class="ps-4" scope="row">Totaal opbrengsten</th>
Expand All @@ -175,7 +177,7 @@
<tbody class="table-group-divider">
<tr>
<td>Inleg Zatladder Inlegsysteem</td>
<td><%= t('codes.credit_mutation') %> </td>
<td><%= Rails.application.config.x.codes[:credit_mutation] %></td>
<td></td>
<td class="text-end">
<%= number_to_currency(@credit_mutations_total, unit: '€') %>
Expand All @@ -193,19 +195,19 @@
Totaal kas
</strong>
</td>
<td><%= t('codes.cash') %></td>
<td><%= Rails.application.config.x.codes[:cash] %></td>
<td class="text-end"><%= number_to_currency(@cash_total, unit: '€') %></td>
<td></td>
</tr>
<tr>
<td>Omzet Pin</td>
<td><%= t('codes.pin') %></td>
<td><%= Rails.application.config.x.codes[:pin] %></td>
<td class="text-end"><%= number_to_currency(@revenue_with_pin, unit: '€') %></td>
<td></td>
</tr>
<tr>
<td>Omzet Zatladder Inlegsysteem</td>
<td><%= t('codes.credit_mutation') %></td>
<td><%= Rails.application.config.x.codes[:credit_mutation] %></td>
<td class="text-end"><%= number_to_currency(@revenue_with_credit, unit: '€') %></td>
<td></td>
</tr>
Expand Down
3 changes: 2 additions & 1 deletion app/views/invoice_mailer/invoice_mail.erb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@

Wij verzoeken u dit bedrag binnen <b>14 dagen</b> te voldoen. Dit kan door het over te maken op rekeningnummer
<b><%= Rails.application.config.x.company_iban %></b> ten name van <b><%= Rails.application.config.x.company_name %></b>, met vermelding van het
factuurnummer <%= @invoice.human_id %>. U kunt ook gebruik maken van de blauwe knop om direct te betalen via iDeal.
factuurnummer <%= @invoice.human_id %>.
<% if Rails.application.config.x.mollie_api_key.present? %>U kunt ook gebruik maken van de blauwe knop om direct te betalen via iDeal.<% end %>
<br/><br/>

Mocht u hier vragen over hebben kunt u antwoorden op deze e-mail, of zelf contact opnemen met
Expand Down
14 changes: 8 additions & 6 deletions app/views/invoices/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<% content_for :title, "Factuur #{@invoice.human_id} - #{Rails.application.config.x.site_name}" %>

<% show_flux_image = Rails.application.config.x.company_name == "Stichting Sociëteit Flux" %>

<div id="activity" class="container footer-padding">
<div class="row justify-content-between">
<div class="col-sm-4">
<%= image_tag '/images/flux_logo.png', class: 'col-4 offset-4 col-sm-12 offset-sm-0 col-lg-8 offset-lg-2' %>
</div>
<div class="col-sm-8 py-2">
<% if show_flux_image %>
<div class="col-sm-4">
<%= image_tag '/images/flux_logo.png', class: 'col-4 offset-4 col-sm-12 offset-sm-0 col-lg-8 offset-lg-2' %>
</div>
<% end %>
<div class="<%= if show_flux_image then 'col-sm-8' else 'col-12' end %> flex-grow-1 py-2">
<h3><%= Rails.application.config.x.company_name %></h3>
<b>
<%= Rails.application.config.x.company_website %> <br/>
Expand Down Expand Up @@ -172,7 +174,7 @@

Hoogachtend,<br/>
<%= Rails.application.config.x.treasurer_name %><br/>
h.t. Penningmeester der <%= Rails.application.config.x.company_name %><br/>
h.t. <%= Rails.application.config.x.treasurer_title.capitalize %> der <%= Rails.application.config.x.company_name %><br/>
</p>
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/views/layouts/mailer.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,7 @@ a[x-apple-data-detectors=true] {
<div style="font-size:12px;line-height:14px;font-family:inherit;color:#888;text-align:left;">
<p style="margin: 0;font-size: 14px;line-height: 17px;text-align: center">
<span style="font-size: 14px; line-height: 17px;">
® C.S.V. Alpha - 2018
® <%= Rails.application.config.x.site_association %> - <%= Time.now.year %>
</span>
<br>
</p>
Expand Down
Loading

0 comments on commit bc33ba2

Please sign in to comment.