diff --git a/.env.example b/.env.example index 80ab17aa5..f98c69fb8 100644 --- a/.env.example +++ b/.env.example @@ -12,6 +12,7 @@ AMBER_CLIENT_SECRET= FROM_EMAIL=noreply@societeitflux.nl ICT_EMAIL=ict@csvalpha.nl ADMIN_EMAIL=streepsysteem@societeitflux.nl +TREASURER_TITLE=penningmeester TREASURER_EMAIL=penningmeester@societeitflux.nl TREASURER_NAME= TREASURER_PHONE= @@ -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 diff --git a/.github/workflows/continuous-delivery.yml b/.github/workflows/continuous-delivery.yml index 441795fa2..738ed981c 100644 --- a/.github/workflows/continuous-delivery.yml +++ b/.github/workflows/continuous-delivery.yml @@ -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 }} @@ -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 @@ -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 @@ -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 @@ -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" diff --git a/.rubocop.yml b/.rubocop.yml index 29bf50a25..7e692d4f3 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -22,6 +22,7 @@ AllCops: Rails/UnknownEnv: Environments: - production + - luxproduction - development - test - staging diff --git a/Dockerfile b/Dockerfile index fa8dec243..c43ecb67e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -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'; \ @@ -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 \ diff --git a/app/controllers/credit_mutations_controller.rb b/app/controllers/credit_mutations_controller.rb index 17bba8bbf..4ed43df97 100644 --- a/app/controllers/credit_mutations_controller.rb +++ b/app/controllers/credit_mutations_controller.rb @@ -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 } } diff --git a/app/controllers/payments_controller.rb b/app/controllers/payments_controller.rb index 0be81a169..4f6ed90e6 100644 --- a/app/controllers/payments_controller.rb +++ b/app/controllers/payments_controller.rb @@ -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 @@ -39,7 +45,9 @@ 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 @@ -47,8 +55,8 @@ def callback # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/Pe 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? diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 48481299e..7255bf066 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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}) "\ diff --git a/app/jobs/credit_insufficient_notification_job.rb b/app/jobs/credit_insufficient_notification_job.rb index ad3ab2d6e..74b26728b 100644 --- a/app/jobs/credit_insufficient_notification_job.rb +++ b/app/jobs/credit_insufficient_notification_job.rb @@ -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 "\ diff --git a/app/jobs/payment_poll_job.rb b/app/jobs/payment_poll_job.rb index 4ecee9bd2..de1e5e1cb 100644 --- a/app/jobs/payment_poll_job.rb +++ b/app/jobs/payment_poll_job.rb @@ -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 diff --git a/app/mailers/invoice_mailer.rb b/app/mailers/invoice_mailer.rb index 83f7775ca..b22410cf3 100644 --- a/app/mailers/invoice_mailer.rb +++ b/app/mailers/invoice_mailer.rb @@ -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') diff --git a/app/models/product.rb b/app/models/product.rb index c01cb05c1..8082251ac 100644 --- a/app/models/product.rb +++ b/app/models/product.rb @@ -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 @@ -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 diff --git a/app/models/role.rb b/app/models/role.rb index afb6680fa..a607b2075 100644 --- a/app/models/role.rb +++ b/app/models/role.rb @@ -7,7 +7,7 @@ class Role < ApplicationRecord def name if treasurer? - 'Penningmeester' + Rails.application.config.x.treasurer_title elsif main_bartender? 'Hoofdtapper' end diff --git a/app/policies/payment_policy.rb b/app/policies/payment_policy.rb index 9d3036a15..aba51a76d 100644 --- a/app/policies/payment_policy.rb +++ b/app/policies/payment_policy.rb @@ -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 diff --git a/app/views/activities/_cannot_order_modal.html.erb b/app/views/activities/_cannot_order_modal.html.erb index df30baef1..ad6e47f39 100644 --- a/app/views/activities/_cannot_order_modal.html.erb +++ b/app/views/activities/_cannot_order_modal.html.erb @@ -7,7 +7,7 @@