diff --git a/.github/workflows/build_deploy_staging.yml b/.github/workflows/build_deploy_staging.yml index aa67fd252..e68a4e102 100644 --- a/.github/workflows/build_deploy_staging.yml +++ b/.github/workflows/build_deploy_staging.yml @@ -32,6 +32,7 @@ jobs: SHORT_SHA=$(echo $GITHUB_SHA | cut -c 1-7) #pr-s test commit of merged state echo "TAG=ghcr.io/internetee/auction_center:RC-$SHORT_SHA" >> $GITHUB_ENV echo "STATIC_TAG=ghcr.io/internetee/auction_center:STATIC_RC-$SHORT_SHA" >> $GITHUB_ENV + echo "REGISTRY_TAG=ghcr.io/internetee/auction_center:REGISTRY_RC-$SHORT_SHA" >> $GITHUB_ENV echo "SHORT_TAG=RC-$SHORT_SHA" >> $GITHUB_ENV - name: Set config files for build @@ -55,10 +56,27 @@ jobs: docker cp rails:/opt/webapps/app/public/ ./public/ docker build -t $STATIC_TAG -f Dockerfile.generic-static . + - name: Clone registry project + run: | + git clone https://github.com/internetee/registry.git + + - name: Build registry image + env: + KEY_BASE: ${{ secrets.KEY_BASE}} + ST_APP: ${{ secrets.ST_REGISTRY_APPLICATION_YML}} + run: | + cd registry + mkdir log + echo $ST_APP | base64 -di > config/application.yml + cp config/database.yml.sample config/database.yml + sed -i -e 's/LABEL org.opencontainers.image.source=https:\/\/github.com\/internetee\/registry/LABEL org.opencontainers.image.source=https:\/\/github.com\/internetee\/auction_center/' Dockerfile.preinstalled_gems + docker build -t $REGISTRY_TAG --build-arg RAILS_ENV=staging --build-arg SECRET_KEY_BASE="$KEY_BASE" -f Dockerfile.preinstalled_gems . + - name: Push Docker images to gh container registry run: | docker push $TAG docker push $STATIC_TAG + docker push $REGISTRY_TAG - name: Get pull request reference number run: | @@ -115,11 +133,13 @@ jobs: export KUBECONFIG=./kubeconfig helm repo add eisrepo https://internetee.github.io/helm-charts/ helm repo update - helm upgrade --install auction-st-"$PR_REF" --set image.tag="$SHORT_TAG",reference="$PR_REF" eisrepo/auction -n auction-staging + helm upgrade --install auction-st-"$PR_REF" --set image.tag="$SHORT_TAG",reference="$PR_REF",scheduler.enabled="true" eisrepo/auction -n auction-staging + helm upgrade --install auction-reg-api-"$PR_REF" --set nameOverride="reg-api-auction",image.repository="ghcr.io/internetee/auction_center",image.tag="REGISTRY_"$SHORT_TAG"",reference="$PR_REF" eisrepo/registry-api -n reg-api rm kubeconfig echo "server obs.tld.ee zone pilv.tld.ee update add auction-"$PR_REF".pilv.tld.ee. 3600 CNAME riigi.pilv.tld.ee. + update add reg-api-auction-"$PR_REF".pilv.tld.ee. 3600 CNAME riigi.pilv.tld.ee. send " | nsupdate -k ~/Kgh-runner.infra.tld.ee.+165+27011.key if [ "$?" -eq "0" ]; then @@ -140,4 +160,5 @@ jobs: |:-----------|:----------------------:|:------------------------------------------:| | **'$REPO'**|'${{ github.head_ref }}'| https://auction-'$PR_REF'.pilv.tld.ee | " - }' $NOTIFICATION_URL \ No newline at end of file + }' $NOTIFICATION_URL + \ No newline at end of file diff --git a/.github/workflows/remove_st_after_pr.yml b/.github/workflows/remove_st_after_pr.yml index 9fc662ee8..cf58e1e04 100644 --- a/.github/workflows/remove_st_after_pr.yml +++ b/.github/workflows/remove_st_after_pr.yml @@ -71,10 +71,12 @@ jobs: cd "$REPO"/"$PR_REF" export KUBECONFIG=./kubeconfig helm delete auction-st-"$PR_REF" -n auction-staging + helm delete auction-reg-api-"$PR_REF" -n reg-api rm kubeconfig echo "server obs.tld.ee zone pilv.tld.ee update delete auction-"$PR_REF".pilv.tld.ee. + update delete reg-api-auction-"$PR_REF".pilv.tld.ee. send " | nsupdate -k ~/Kgh-runner.infra.tld.ee.+165+27011.key if [ "$?" -eq "0" ]; then diff --git a/.github/workflows/ruby.yml b/.github/workflows/ruby.yml index 231bfb3f7..ceaa571c0 100644 --- a/.github/workflows/ruby.yml +++ b/.github/workflows/ruby.yml @@ -85,7 +85,7 @@ jobs: - name: Save coverage run: ./cc-test-reporter format-coverage --output coverage/codeclimate.${{ matrix.ruby }}.json - - uses: actions/upload-artifact@v2.2.4 + - uses: actions/upload-artifact@v2.3.0 with: name: coverage-${{ matrix.ruby }} path: coverage/codeclimate.${{ matrix.ruby }}.json @@ -110,7 +110,7 @@ jobs: - name: Give test coverage reporter executable permissions run: chmod +x cc-test-reporter - - uses: actions/download-artifact@v2.0.10 + - uses: actions/download-artifact@v2.1.0 with: name: coverage-${{ matrix.ruby }} path: coverage diff --git a/CHANGELOG.md b/CHANGELOG.md index a6dfe170b..d583b44be 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +25.11.2021 +* unsubscribe link to daily auction broadcast emails [#845](https://github.com/internetee/auction_center/issues/845) + 06.10.2021 * Invoice nr is now used as order ref for linkpay payments [#836](https://github.com/internetee/auction_center/issues/836) * Improved error handling and logging for linkpay payments [#838](https://github.com/internetee/auction_center/pull/838) diff --git a/Dockerfile.generic b/Dockerfile.generic index e0ac2a986..47a9971ec 100644 --- a/Dockerfile.generic +++ b/Dockerfile.generic @@ -1,17 +1,16 @@ -FROM internetee/ruby:2.7 +FROM internetee/ruby_base:3.0 LABEL org.opencontainers.image.source=https://github.com/internetee/auction_center -ARG YARN_VER='1.22.10' ARG RAILS_ENV ARG SECRET_KEY_BASE ENV RAILS_ENV "$RAILS_ENV" ENV SECRET_KEY_BASE "$SECRET_KEY_BASE" -RUN npm install -g yarn@"$YARN_VER" COPY Gemfile Gemfile.lock ./ RUN gem install bundler && bundle config set without 'development test' && bundle install --jobs 20 --retry 5 RUN yarn install --check-files + COPY . . RUN bundle exec rails assets:precompile diff --git a/app/controllers/unsubscribe_controller.rb b/app/controllers/unsubscribe_controller.rb new file mode 100644 index 000000000..262427fa4 --- /dev/null +++ b/app/controllers/unsubscribe_controller.rb @@ -0,0 +1,23 @@ +class UnsubscribeController < ApplicationController + def unsubscribe + user = Rails.application.message_verifier(:unsubscribe).verify(params[:id]) + @user = User.find(user) + end + + def update + @user = User.find(params[:id]) + if @user.update(user_params) + flash[:notice] = 'Subscription Cancelled' + redirect_to root_url + else + flash[:alert] = 'Something wrong' + render :unsubscribe + end + end + + private + + def user_params + params.require(:user).permit(:daily_summary) + end +end diff --git a/app/jobs/daily_broadcast_auctions_job.rb b/app/jobs/daily_broadcast_auctions_job.rb index 077462a0c..39bfe074b 100644 --- a/app/jobs/daily_broadcast_auctions_job.rb +++ b/app/jobs/daily_broadcast_auctions_job.rb @@ -2,9 +2,11 @@ class DailyBroadcastAuctionsJob < ApplicationJob def perform User.subscribed_to_daily_summary.each do |user| I18n.with_locale(user.locale) do + unsubscribe = Rails.application.message_verifier(:unsubscribe).generate(user.id) NotificationMailer.daily_auctions_broadcast_email( recipient: user.email, - auctions: active_auctions + auctions: active_auctions, + unsubscribe: unsubscribe ).deliver_later end end diff --git a/app/mailers/notification_mailer.rb b/app/mailers/notification_mailer.rb index 71beef817..683cfc8c4 100644 --- a/app/mailers/notification_mailer.rb +++ b/app/mailers/notification_mailer.rb @@ -12,8 +12,9 @@ def daily_summary_email(addressee, summary_report = nil) mail(to: addressee.email, subject: t('.subject', date: Date.yesterday)) end - def daily_auctions_broadcast_email(recipient:, auctions:) + def daily_auctions_broadcast_email(recipient:, auctions:, unsubscribe: nil) @auctions = auctions + @unsubscribe = unsubscribe mail(to: recipient) end diff --git a/app/views/notification_mailer/daily_auctions_broadcast_email.html.erb b/app/views/notification_mailer/daily_auctions_broadcast_email.html.erb index 6128b4367..5e9228df7 100644 --- a/app/views/notification_mailer/daily_auctions_broadcast_email.html.erb +++ b/app/views/notification_mailer/daily_auctions_broadcast_email.html.erb @@ -17,3 +17,4 @@ <%= t('common_mailer.footer_html') %> +<%= link_to t('unsubscribe_mailer_text'), unsubscribe_unsubscribe_url(id: @unsubscribe) %> diff --git a/app/views/unsubscribe/unsubscribe.html.erb b/app/views/unsubscribe/unsubscribe.html.erb new file mode 100644 index 000000000..1680e447b --- /dev/null +++ b/app/views/unsubscribe/unsubscribe.html.erb @@ -0,0 +1,16 @@ +<% content_for :hero do %> +
+

<%= t('header_text') %>

+
+<% end %> + +
+
+ <%= form_for(@user, url: unsubscribe_update_path(id: @user.id)) do |f| %> +

<%= t('unsubscribe_text') %>

+ <%= f.hidden_field(:daily_summary, value: false) %> + <%= f.submit t('unsubscribe_btn'), class: "ui button big primary red" %> + <%= link_to t('cancel_btn'), root_url, class: "ui button big secondary" %> + <% end %> +
+
diff --git a/config/locales/en.yml b/config/locales/en.yml index e35559ae7..c9a883789 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -42,6 +42,8 @@ en: errors_name: "Errors" statistics_name: "Statistics" + unsubscribe_mailer_text: "I do not wish to receive daily summary about currently auctioned domains any more" + user: "User" deleted_user: "User was deleted" banned: | diff --git a/config/locales/et.yml b/config/locales/et.yml index ee73a7a10..00f50be95 100644 --- a/config/locales/et.yml +++ b/config/locales/et.yml @@ -40,6 +40,8 @@ et: bans_name: "Keelud" errors_name: "Vead" + unsubscribe_mailer_text: "Ei soovi enam saada oksjonil olevate domeenide nimekirja meilile" + user: "Kasutaja" deleted_user: "Kasutaja kustutatud" banned: | diff --git a/config/locales/unsubscribe.en.yml b/config/locales/unsubscribe.en.yml new file mode 100644 index 000000000..e8568d8b6 --- /dev/null +++ b/config/locales/unsubscribe.en.yml @@ -0,0 +1,5 @@ +en: + header_text: "Unsubscribe" + unsubscribe_text: "Please confirm that you no longer wish to receive daily summary" + unsubscribe_btn: "Unsubscribe" + cancel_btn: "Cancel" diff --git a/config/locales/unsubscribe.et.yml b/config/locales/unsubscribe.et.yml new file mode 100644 index 000000000..1cca6bd5c --- /dev/null +++ b/config/locales/unsubscribe.et.yml @@ -0,0 +1,5 @@ +et: + header_text: "Tellimusest loobumine" + unsubscribe_text: "Palun kinnita et Sa ei soovi enam saada oksjonil olevate domeenide nimekirja" + unsubscribe_btn: "Loobun nimekirjast" + cancel_btn: "Mõtlesin ümber" diff --git a/config/routes.rb b/config/routes.rb index 59f06fd2b..6205be491 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -7,6 +7,8 @@ end Rails.application.routes.draw do + get 'unsubscribe/unsubscribe' + patch 'unsubscribe/update' root to: 'auctions#index' concern :auditable do diff --git a/test/system/unsubscribe_test.rb b/test/system/unsubscribe_test.rb new file mode 100644 index 000000000..8b4d58294 --- /dev/null +++ b/test/system/unsubscribe_test.rb @@ -0,0 +1,24 @@ +require 'application_system_test_case' + +class UnsubscribeTest < ApplicationSystemTestCase + def setup + @participant = users(:participant) + @unsubscribe = Rails.application.message_verifier(:unsubscribe).generate(@participant.id) + end + + def test_unsubscribe_user + @participant.daily_summary = true + @participant.save + + assert_equal(@participant.daily_summary, true) + + visit(unsubscribe_unsubscribe_url(id: @unsubscribe)) + assert_text 'Please confirm that you no longer wish to receive daily summary' + + click_link_or_button('Unsubscribe') + assert_text 'Subscription Cancelled' + + @participant.reload + assert_equal(@participant.daily_summary, false) + end +end