Skip to content

Commit

Permalink
Merge branch 'develop' into add_admin_log_when_managing_area_types
Browse files Browse the repository at this point in the history
  • Loading branch information
eliegaboriau committed May 25, 2022
2 parents 10caf11 + f33421f commit 1331b86
Show file tree
Hide file tree
Showing 170 changed files with 2,122 additions and 347 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/ci_core_system.yml
Expand Up @@ -59,11 +59,14 @@ jobs:
processor_count: ${{ env.PARALLEL_TEST_PROCESSORS }}
ruby_version: ${{ env.RUBY_VERSION }}
node_version: ${{ env.NODE_VERSION }}
- run: bundle exec rake parallel:spec[^spec/system]
- run: |
sudo Xvfb -ac $DISPLAY -screen 0 1920x1084x24 > /dev/null 2>&1 & # optional
bundle exec rake parallel:spec[^spec/system]
name: RSpec
working-directory: ${{ env.DECIDIM_MODULE }}
env:
SIMPLECOV: "true"
DISPLAY: ":99"
- run: ./.github/upload_coverage.sh $DECIDIM_MODULE $GITHUB_EVENT_PATH
name: Upload coverage
- uses: actions/upload-artifact@v2
Expand Down
3 changes: 3 additions & 0 deletions .github/workflows/ci_performance_metrics_monitoring.yml
Expand Up @@ -77,6 +77,9 @@ jobs:
- run: bundle exec rails decidim:lighthouse:prepare_urls
name: Setup lighthouse urls
working-directory: ./development_app/
- run: bundle exec rails dev:cache
name: Activate Rails cache
working-directory: ./development_app/
- run: bundle exec rails server -b localhost -d
name: Run Rails server
working-directory: ./development_app/
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/lighthouse_budget.json
Expand Up @@ -4,19 +4,19 @@
"timings": [
{
"metric": "first-contentful-paint",
"budget": 10000
"budget": 2000
},
{
"metric": "speed-index",
"budget": 10000
"budget": 4000
},
{
"metric": "interactive",
"budget": 10000
"budget": 5000
},
{
"metric": "largest-contentful-paint",
"budget": 10000
"budget": 2500
}
]
}
Expand Down
5 changes: 1 addition & 4 deletions .lighthouserc.json
Expand Up @@ -7,10 +7,7 @@
"settings": {
"chromeFlags": "--disable-gpu --no-sandbox",
"throttlingMethod": "devtools",
"preset": "desktop",
"throttling": {
"cpuSlowdownMultiplier": 1
}
"preset": "desktop"
}
}
}
Expand Down
15 changes: 15 additions & 0 deletions CHANGELOG.md
Expand Up @@ -12,6 +12,10 @@ In the next version (v0.28.0) it will be fully removed from the database.

### Added


#### Push notifications
PR [\#8774] https://github.com/decidim/decidim/pull/8774 Implements push notifications. Use `rails
decidim:pwa:generate_vapid_keys` to generate the VAPID keys and copy them to your env vars file.
#### Javascript load at the bottom of the pages

PR [\#9156] https://github.com/decidim/decidim/pull/9156 moves javascript snippets to the bottom of `body` sections.
Expand Down Expand Up @@ -161,6 +165,17 @@ There are specific things that you need to change regarding your Form or `Virtus

PR [\#8645](https://github.com/decidim/decidim/pull/8645) we now only allow PNG images at Favicon so we can provide higher quality versions to mobile devices.

#### Mail Notifications digest

PR [\#8833](https://github.com/decidim/decidim/pull/8833) Users can now configure if the want to receive a real time email when they receive a notification or a periodic one with the notifications digest.


```bash
# Send notification mail digest daily
5 0 * * * cd /home/user/decidim_application && RAILS_ENV=production bundle exec rake decidim:mailers:notifications_digest_daily
# Send notification mail digest weekly on saturdays
5 0 * * 6 cd /home/user/decidim_application && RAILS_ENV=production bundle exec rake decidim:mailers:notifications_digest_weekly

### Changed

### Rename data portability to download your data
Expand Down
9 changes: 5 additions & 4 deletions Gemfile.lock
Expand Up @@ -132,7 +132,7 @@ PATH
rubocop (~> 1.28.0)
rubocop-rails (~> 2.14)
rubocop-rspec (~> 2.10)
selenium-webdriver (~> 3.142)
selenium-webdriver (~> 4.1.0)
simplecov (~> 0.19.0)
simplecov-cobertura (~> 1.3.1)
w3c_rspec_validators (~> 0.3.0)
Expand Down Expand Up @@ -324,7 +324,7 @@ GEM
charlock_holmes (0.7.7)
chef-utils (17.10.0)
concurrent-ruby
childprocess (3.0.0)
childprocess (4.1.0)
coercible (1.0.0)
descendants_tracker (~> 0.0.1)
coffee-rails (5.0.0)
Expand Down Expand Up @@ -742,8 +742,9 @@ GEM
sass-listen (4.0.0)
rb-fsevent (~> 0.9, >= 0.9.4)
rb-inotify (~> 0.9, >= 0.9.7)
selenium-webdriver (3.142.7)
childprocess (>= 0.5, < 4.0)
selenium-webdriver (4.1.0)
childprocess (>= 0.5, < 5.0)
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2)
semantic_range (3.0.0)
seven_zip_ruby (1.3.0)
Expand Down
Expand Up @@ -6,8 +6,9 @@ module Admin
# This command is executed when the user creates a Status from the admin
# panel.
class CreateStatus < Decidim::Command
def initialize(form)
def initialize(form, user)
@form = form
@user = user
end

# Creates the status if valid.
Expand All @@ -28,7 +29,9 @@ def call
attr_reader :status

def create_status
@status = Status.create!(
@status = Decidim.traceability.create!(
Status,
@user,
component: @form.current_component,
key: @form.key,
name: @form.name,
Expand Down
Expand Up @@ -10,9 +10,10 @@ class UpdateStatus < Decidim::Command
#
# form - The form from which to get the data.
# status - The current instance of the status to be updated.
def initialize(form, status)
def initialize(form, status, user)
@form = form
@status = status
@user = user
end

# Updates the status if valid.
Expand All @@ -33,7 +34,9 @@ def call
attr_reader :status, :form

def update_status
status.update!(
Decidim.traceability.update!(
status,
@user,
key: @form.key,
name: @form.name,
description: @form.description,
Expand Down
Expand Up @@ -18,7 +18,7 @@ def create

@form = form(StatusForm).from_params(params)

CreateStatus.call(@form) do
CreateStatus.call(@form, current_user) do
on(:ok) do
flash[:notice] = I18n.t("statuses.create.success", scope: "decidim.accountability.admin")
redirect_to statuses_path
Expand All @@ -42,7 +42,7 @@ def update

@form = form(StatusForm).from_params(params)

UpdateStatus.call(@form, status) do
UpdateStatus.call(@form, status, current_user) do
on(:ok) do
flash[:notice] = I18n.t("statuses.update.success", scope: "decidim.accountability.admin")
redirect_to statuses_path
Expand All @@ -58,7 +58,9 @@ def update
def destroy
enforce_permission_to :destroy, :status, status: status

status.destroy!
Decidim.traceability.perform_action!("delete", status, current_user) do
status.destroy!
end

flash[:notice] = I18n.t("statuses.destroy.success", scope: "decidim.accountability.admin")

Expand Down
Expand Up @@ -8,6 +8,7 @@ class Status < Accountability::ApplicationRecord
include Decidim::HasComponent
include Decidim::TranslatableResource
include Decidim::FilterableResource
include Decidim::Traceable

component_manifest_name "accountability"

Expand All @@ -20,6 +21,10 @@ class Status < Accountability::ApplicationRecord

# Allow ransacker to search for a key in a hstore column (`name`.`en`)
ransacker_i18n :name

def self.log_presenter_class_for(_log)
Decidim::Accountability::AdminLog::StatusPresenter
end
end
end
end
@@ -0,0 +1,38 @@
# frozen_string_literal: true

module Decidim
module Accountability
module AdminLog
# This class holds the logic to present a `Decidim::Accountability::Status`
# for the `AdminLog` log.
#
# Usage should be automatic and you shouldn't need to call this class
# directly, but here's an example:
#
# action_log = Decidim::ActionLog.last
# view_helpers # => this comes from the views
# StatusPresenter.new(action_log, view_helpers).present
class StatusPresenter < Decidim::Log::BasePresenter
private

def action_string
case action
when "create", "delete", "update"
"decidim.accountability.admin_log.status.#{action}"
else
super
end
end

def diff_fields_mapping
{
key: :string,
name: :i18n,
description: :i18n,
progress: :integer
}
end
end
end
end
end
4 changes: 4 additions & 0 deletions decidim-accountability/config/locales/en.yml
Expand Up @@ -123,6 +123,10 @@ en:
create: "%{user_name} created result %{resource_name} in %{space_name}"
delete: "%{user_name} deleted the %{resource_name} result in %{space_name}"
update: "%{user_name} updated result %{resource_name} in %{space_name}"
status:
create: "%{user_name} created the %{resource_name} status"
delete: "%{user_name} deleted the %{resource_name} status"
update: "%{user_name} updated the %{resource_name} status"
value_types:
parent_presenter:
not_found: 'The parent was not found on the database (ID: %{id})'
Expand Down
15 changes: 14 additions & 1 deletion decidim-accountability/spec/commands/admin/create_status_spec.rb
Expand Up @@ -4,9 +4,10 @@

module Decidim::Accountability
describe Admin::CreateStatus do
subject { described_class.new(form) }
subject { described_class.new(form, user) }

let(:organization) { create :organization, available_locales: [:en] }
let(:user) { create(:user, organization: organization) }
let(:participatory_process) { create :participatory_process, organization: organization }
let(:current_component) { create :component, manifest_name: "accountability", participatory_space: participatory_process }

Expand Down Expand Up @@ -61,6 +62,18 @@ module Decidim::Accountability
subject.call
expect(status.progress).to eq progress
end

it "traces the action", versioning: true do
expect(Decidim.traceability)
.to receive(:perform_action!)
.with(:create, Decidim::Accountability::Status, user, {})
.and_call_original

expect { subject.call }.to change(Decidim::ActionLog, :count)
action_log = Decidim::ActionLog.last
expect(action_log.action).to eq("create")
expect(action_log.version).to be_present
end
end
end
end
15 changes: 14 additions & 1 deletion decidim-accountability/spec/commands/admin/update_status_spec.rb
Expand Up @@ -4,9 +4,10 @@

module Decidim::Accountability
describe Admin::UpdateStatus do
subject { described_class.new(form, status) }
subject { described_class.new(form, status, user) }

let(:organization) { create :organization, available_locales: [:en] }
let(:user) { create :user, organization: organization }
let(:participatory_process) { create :participatory_process, organization: organization }
let(:current_component) { create :accountability_component, participatory_space: participatory_process }

Expand Down Expand Up @@ -56,6 +57,18 @@ module Decidim::Accountability
subject.call
expect(status.progress).to eq progress
end

it "traces the action", versioning: true do
expect(Decidim.traceability)
.to receive(:perform_action!)
.with(:update, status, user, {})
.and_call_original

expect { subject.call }.to change(Decidim::ActionLog, :count)
action_log = Decidim::ActionLog.last
expect(action_log.action).to eq("update")
expect(action_log.version).to be_present
end
end
end
end
Expand Up @@ -9,9 +9,10 @@ class CreateAttachmentCollection < Decidim::Command
#
# form - A form object with the params.
# collection_for - The ActiveRecord::Base that will hold the collection
def initialize(form, collection_for)
def initialize(form, collection_for, user)
@form = form
@collection_for = collection_for
@user = user
end

# Executes the command. Broadcasts these events:
Expand All @@ -32,12 +33,20 @@ def call
attr_reader :form

def create_attachment_collection
AttachmentCollection.create!(
Decidim.traceability.create!(
AttachmentCollection,
@user,
attributes
)
end

def attributes
{
name: form.name,
weight: form.weight,
description: form.description,
collection_for: @collection_for
)
}
end
end
end
Expand Down
7 changes: 5 additions & 2 deletions decidim-admin/app/commands/decidim/admin/create_scope_type.rb
Expand Up @@ -7,8 +7,9 @@ class CreateScopeType < Decidim::Command
# Public: Initializes the command.
#
# form - A form object with the params.
def initialize(form)
def initialize(form, user)
@form = form
@user = user
end

# Executes the command. Broadcasts these events:
Expand All @@ -29,7 +30,9 @@ def call
attr_reader :form

def create_scope_type
ScopeType.create!(
Decidim.traceability.create!(
ScopeType,
@user,
name: form.name,
organization: form.organization,
plural: form.plural
Expand Down

0 comments on commit 1331b86

Please sign in to comment.