Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rc: Release 3.1.1 #43

Open
wants to merge 9 commits into
base: release/v3
Choose a base branch
from
117 changes: 33 additions & 84 deletions .github/workflows/ci_cleaner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,7 @@ jobs:
if: "github.ref != 'refs/heads/develop'"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- uses: actions/[email protected]
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- name: Run Rubocop
run: bundle exec rubocop -P
- uses: OpenSourcePolitics/lint-action@master
tests:
name: Tests
runs-on: ubuntu-latest
Expand All @@ -51,86 +44,42 @@ jobs:
if: "github.ref != 'refs/heads/develop'"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- uses: actions/[email protected]
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
with:
bundler-cache: true
- uses: actions/setup-node@v1
- uses: OpenSourcePolitics/rspec-action@master
with:
node-version: ${{ env.NODE_VERSION }}
- name: Get npm cache directory path
id: npm-cache-dir-path
run: echo "::set-output name=dir::$(npm get cache)-cleaner"
- uses: actions/cache@v2
id: npm-cache
with:
path: ${{ steps.npm-cache-dir-path.outputs.dir }}
key: npm-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
npm-
- run: bundle exec rake test_app
name: Create test app
- run: mkdir -p ./spec/decidim_dummy_app/tmp/screenshots
name: Create the screenshots folder
- uses: nanasess/[email protected]
- name: Run precompile if needed
run: |
if [[ -d "app/views" ]] || [[ -d "spec/mailers" ]] || [[ -d "spec/system" ]]; then
cd "spec/decidim_dummy_app"
bundle exec rails assets:precompile
else
echo "No need to precompile assets since system folder is empty"
fi
- run: bundle exec rspec
name: RSpec
- uses: codecov/codecov-action@v1
- uses: actions/upload-artifact@v2
if: always()
with:
name: screenshots
path: ./spec/decidim_dummy_app/tmp/screenshots
if-no-files-found: ignore
release:
if: "github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release' )"
needs: [tests, lint]
command: "bundle exec rspec --exclude-pattern 'spec/system/**/*_spec.rb'"
system_tests:
name: System tests
runs-on: ubuntu-latest
timeout-minutes: 30
services:
postgres:
image: postgres:11
ports: ["5432:5432"]
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
POSTGRES_PASSWORD: postgres
env:
DATABASE_USERNAME: postgres
DATABASE_PASSWORD: postgres
DATABASE_HOST: localhost
steps:
- uses: actions/[email protected]
with:
fetch-depth: 1
- uses: ruby/setup-ruby@v1
- uses: rokroskar/[email protected]
if: "github.ref != 'refs/heads/develop'"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- uses: OpenSourcePolitics/rspec-action@master
with:
bundler-cache: true
- name: Setup git and gh
run: |
git config user.name "${GITHUB_ACTOR}"
git config user.email "${GITHUB_ACTOR}@users.noreply.github.com"
echo ${{ secrets.GITHUB_TOKEN }} | gh auth login --with-token
- run: gem install parse_gemspec-cli
name: Intall gem parser
- run: echo "::set-output name=tag::$(parse-gemspec-cli *.gemspec | jq .'version')"
name: Set tag version
id: set_tag
- name: Add tag and push
run: |
git tag
git push --tags
- name: Create release
run: gh release create ${{ steps.set_tag.outputs.tag }} --generate-notes
command: "bundle exec rspec spec/system"
publish:
needs: release
if: "github.ref == 'refs/heads/master' || github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/heads/release' )"
needs: [tests, system_tests, lint]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Publish to RubyGems
run: |
mkdir -p $HOME/.gem
touch $HOME/.gem/credentials
chmod 0600 $HOME/.gem/credentials
printf -- "---\n:rubygems_api_key: ${GEM_HOST_API_KEY}\n" > $HOME/.gem/credentials
gem build *.gemspec
gem push *.gem
env:
GEM_HOST_API_KEY: "${{secrets.RUBYGEMS_API_KEY}}"
- uses: OpenSourcePolitics/publish-gem-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
rubygems_api_key: ${{ secrets.RUBYGEMS_API_KEY }}
4 changes: 2 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ source "https://rubygems.org"

ruby RUBY_VERSION

gem "decidim"
gem "decidim", "~> 0.27.0"
gem "decidim-cleaner", path: "."

gem "bootsnap", "~> 1.4"
gem "puma", ">= 4.3"

group :development, :test do
gem "byebug", "~> 11.0", platform: :mri
gem "decidim-dev"
gem "decidim-dev", "~> 0.27.0"
gem "rubocop-faker"
end

Expand Down
7 changes: 4 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
decidim-cleaner (3.1.0)
decidim-cleaner (3.1.1)
decidim-core (~> 0.27.0)

GEM
Expand Down Expand Up @@ -794,15 +794,16 @@ GEM

PLATFORMS
arm64-darwin-21
arm64-darwin-22
x86_64-darwin-21
x86_64-linux

DEPENDENCIES
bootsnap (~> 1.4)
byebug (~> 11.0)
decidim
decidim (~> 0.27.0)
decidim-cleaner!
decidim-dev
decidim-dev (~> 0.27.0)
faker (~> 2.14)
letter_opener_web (~> 2.0)
listen (~> 3.1)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ You can then add to your 'config/sidekiq.yml' file:
## Available tasks

- [ ] **Delete inactive users**
- Cron task that checks for user accounts where `last_sign_in_at` is superior to environment variable `CLEANER_USER_INACTIVITY_LIMIT`. If true, deletes inactive user from the database.
- Cron task that checks for user accounts where `current_sign_in_at` is superior to environment variable `CLEANER_USER_INACTIVITY_LIMIT`. If true, deletes inactive user from the database.

- [ ] **Delete old admin logs**
- Cron task that checks for admin logs where `created_at` is anterior to the time you configured in the back office. If true, deletes old admin logs from the database.
Expand Down
3 changes: 3 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ def install_module(path)
Dir.chdir(path) do
system("bundle exec rake decidim_cleaner:install:migrations")
system("bundle exec rake db:migrate")
system("npm install --save-dev @babel/plugin-proposal-private-methods")
system("npm install --save-dev @babel/plugin-proposal-private-property-in-object")
system("bundle exec rake assets:precompile")
end
end

Expand Down
19 changes: 12 additions & 7 deletions app/jobs/decidim/cleaner/clean_inactive_users_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@
Decidim::Organization.find_each do |organization|
next unless organization.delete_inactive_users?

send_warning(Decidim::User.where(organization: organization)
send_warning(Decidim::User.unscoped.where(organization: organization)
.not_deleted
.where.not(email: "")
.where("last_sign_in_at < ?", email_inactive_before_date(organization)))
delete_user_and_send_email(Decidim::User.where(organization: organization)
.where("current_sign_in_at < ?", email_inactive_before_date(organization)))
delete_user_and_send_email(Decidim::User.unscoped.where(organization: organization)
.not_deleted
.where.not(email: "")
.where("warning_date < ?", delete_inactive_before_date(organization)))
Expand All @@ -24,15 +24,20 @@
users.find_each do |user|
next if user.warning_date.present?

user.update!(warning_date: Time.zone.now) if InactiveUsersMailer.warning_inactive(user).deliver_now
Rails.logger.info "Inactive warning sent to #{user.email}"
if InactiveUsersMailer.warning_inactive(user).deliver_now
user.warning_date = Time.zone.now
user.save(validate: false)
else
Rails.logger.info "Inactive warning sent to #{user.email}"

Check warning on line 31 in app/jobs/decidim/cleaner/clean_inactive_users_job.rb

View check run for this annotation

Codecov / codecov/patch

app/jobs/decidim/cleaner/clean_inactive_users_job.rb#L31

Added line #L31 was not covered by tests
end
end
end

def delete_user_and_send_email(users)
users.find_each do |user|
if user.last_sign_in_at > user.warning_date
user.update!(warning_date: nil)
if user.current_sign_in_at > user.warning_date
user.warning_date = nil
user.save(validate: false)
Rails.logger.info "User with id #{user.id} has logged in again, warning date reset"
next
end
Expand Down
40 changes: 40 additions & 0 deletions config/locales/fi.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
fi:
activemodel:
attributes:
organization:
delete_admin_logs: Ota käyttöön hallintatoimintojen lokien poistaminen
delete_admin_logs_after: Hallintatoimintojen lokien säilytysaika (päivää, oletusarvo 365)
delete_inactive_users: Ota käyttöön passiivisten käyttäjätilien poisto
delete_inactive_users_after: Passiivisten käyttäjätilien säilytysaika varoitusviestin lähetyksen jälkeen (päivää, oletusarvo 30)
delete_inactive_users_email_after: Käyttäjätilin poiston varoitusviestin lähetysaika käyttäjätilin ollessa passiivinen (päivää, oletusarvo 365)
decidim:
admin:
menu:
clean: Tietojen puhdistus
organization:
update:
error: Organisaation päivitys epäonnistui.
success: Organisaation päivitys onnistui.
cleaner:
admin:
organization_cleaner:
edit:
update: Päivitä
form:
admin_log_cleaner_title: Hallintatoimintojen lokitiedot
inactive_users_cleaner_title: Passiiviset käyttäjät
delete_reason: Käyttäjä poistettiin käyttäjätilin passiivisuuden takia
inactive_users_mailer:
warning_deletion:
body_1: Käyttäjätilisi on ollut passiivisena %{days} päivää palvelussa <a href="%{organization_url}">%{organization_name} </a>.
body_2: Tämän takia käyttäjätilisi on nyt poistettu palvelusta.
greetings: Terveisin,<br/>%{organization_name}<br/><a href="%{organization_url}">%{organization_url}</a>
hello: Hei,
subject: Käyttäjätilisi on nyt poistettu
warning_inactive:
body_1: Käyttäjätilisi on ollut passiivisena %{days} päivää palvelussa %{organization_name}.
body_2: Mikäli et <a href="%{organization_url}">kirjaudu alustalle %{remaining_days} päivän aikana</a>, käyttäjätilisi poistetaan.
greetings: Terveisin,<br/>%{organization_name}<br/><a href="%{organization_url}">%{organization_url}</a>
hello: Hei,
subject: Käyttäjätilisi on ollut passiivisena pitkään
1 change: 1 addition & 0 deletions lib/decidim/cleaner.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "decidim/cleaner/admin"
require "decidim/cleaner/engine"
require "decidim/cleaner/admin_engine"
require "decidim/cleaner/extends/commands/decidim/destroy_account"

module Decidim
# This namespace holds the logic of the `Cleaner` module.
Expand Down
4 changes: 4 additions & 0 deletions lib/decidim/cleaner/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ module Cleaner
# This is the engine that runs on the public interface of cleaner.
class Engine < ::Rails::Engine
isolate_namespace Decidim::Cleaner

config.to_prepare do
Decidim::DestroyAccount.include(Decidim::Cleaner::Extends::DestroyAccount)
end
end
end
end
31 changes: 31 additions & 0 deletions lib/decidim/cleaner/extends/commands/decidim/destroy_account.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

module Decidim
module Cleaner
module Extends
# This command destroys the user's account.
module DestroyAccount
extend ActiveSupport::Concern

included do
private

# Invalidate all sessions after cleaning Decidim::User record to prevent Active Record error
def destroy_user_account!
@user.name = ""
@user.nickname = ""
@user.email = ""
@user.delete_reason = @form.delete_reason
@user.admin = false if @user.admin?
@user.deleted_at = Time.current
@user.skip_reconfirmation!
@user.avatar.purge
@user.save!

@user.invalidate_all_sessions!
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion lib/decidim/cleaner/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module Decidim
# This holds the decidim-meetings version.
module Cleaner
def self.version
"3.1.0"
"3.1.1"
end

def self.compatible_decidim_version
Expand Down
Loading
Loading