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

bump version 0.11.3 #344

Open
wants to merge 17 commits into
base: main
Choose a base branch
from
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
CHANGELOG
=========

Current
v0.11.3
-------
Compatibility:
- Decidim v0.28.x

Features:
- Added user time zones in account settings
- Added custom styles for the admin panel
- Added Verification tweaks
- Added Admin manual verifications

v0.11.2
-------
Expand Down
4 changes: 2 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
decidim-decidim_awesome (0.11.2)
decidim-decidim_awesome (0.11.3)
decidim-admin (>= 0.28.0, < 0.29)
decidim-core (>= 0.28.0, < 0.29)
deface (>= 1.5)
Expand Down Expand Up @@ -749,7 +749,7 @@ GEM
uber (0.1.0)
unicode-display_width (2.6.0)
uniform_notifier (1.16.0)
uri (0.13.1)
uri (1.0.2)
valid_email2 (4.0.6)
activemodel (>= 3.2)
mail (~> 2.5)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,11 @@ module ProposalLCellOverride
alias_method :decidim_original_cache_hash, :cache_hash

def metadata_cell
awesome_voting_manifest_for(resource&.component)&.proposal_metadata_cell.presence || "decidim/proposals/proposal_metadata"
@metadata_cell ||= awesome_voting_manifest_for(resource&.component)&.proposal_metadata_cell.presence || "decidim/proposals/proposal_metadata"
end

def cache_hash
extra_hash = model.extra_fields&.reload&.vote_weight_totals
"#{decidim_original_cache_hash}#{Decidim.cache_key_separator}#{extra_hash}"
@cache_hash ||= "#{decidim_original_cache_hash}#{Decidim.cache_key_separator}#{model.extra_fields&.vote_weight_totals}"
end
end
end
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
# frozen_string_literal: true

require "decidim/decidim_awesome/awesome_helpers"

module Decidim
module DecidimAwesome
module NeedsAwesomeConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module Admin
class AdminAuthorizationsController < DecidimAwesome::Admin::ApplicationController
include NeedsAwesomeConfig

layout false
layout "layouts/decidim/decidim_awesome/admin/admin_authorizations"
helper_method :user, :authorization, :workflow, :handler, :conflict
# overwrite original rescue_from to ensure we print messages from ajax methods
rescue_from Decidim::ActionForbidden, with: :json_error
Expand All @@ -23,16 +23,16 @@ def update
if conflict
message = render_to_string("conflict")
else
message = render_to_string(partial: "callout", locals: { i18n_key: "user_authorized", klass: "success" })
message = render_to_string("callout", locals: { i18n_key: "user_authorized", klass: "success" })
Decidim::Verifications::AuthorizeUser.call(handler, current_organization) do
on(:transferred) do |transfer|
message += render_to_string(partial: "callout", locals: { i18n_key: "authorization_transferred", klass: "success" }) if transfer.records.any?
message += render_to_string("callout", locals: { i18n_key: "authorization_transferred", klass: "success" }) if transfer.records.any?
end
on(:invalid) do
if force_verification.present?
create_forced_authorization
else
message = render_to_string(partial: "callout", locals: { i18n_key: "user_not_authorized", klass: "alert" })
message = render_to_string("callout", locals: { i18n_key: "user_not_authorized", klass: "alert" })
message += render_to_string("edit", locals: { with_override: true })
end
end
Expand All @@ -52,9 +52,9 @@ def update

def destroy
message = if destroy_authorization
render_to_string(partial: "callout", locals: { i18n_key: "authorization_destroyed", klass: "success" })
render_to_string("callout", locals: { i18n_key: "authorization_destroyed", klass: "success" })
else
render_to_string(partial: "callout", locals: { i18n_key: "authorization_not_destroyed", klass: "alert" })
render_to_string("callout", locals: { i18n_key: "authorization_not_destroyed", klass: "alert" })
end

render json: {
Expand All @@ -80,7 +80,7 @@ def destroy_authorization
end

def json_error(exception)
render json: render_to_string(partial: "callout", locals: { message: exception.message, klass: "alert" }), status: :unprocessable_entity
render plain: render_to_string("callout", locals: { message: exception.message, klass: "alert" }), status: :unprocessable_entity
end

def user
Expand Down
20 changes: 8 additions & 12 deletions app/packs/src/decidim/decidim_awesome/admin/verifications.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ document.addEventListener("DOMContentLoaded", () => {
if (!dialog) {
return;
}
const title = dialog.querySelector("[data-dialog-title]");
const content = dialog.querySelector("[data-dialog-content]");

const container = dialog.querySelector("[data-dialog-container]");

dialog.addEventListener("open.dialog", async (el) => {
const modal = window.Decidim.currentDialogs[el.target.id];
const button = modal.openingTrigger;
const url = button.dataset.verificationUrl;
const user = button.dataset.verificationUser;
title.innerText = title.innerText.replace("{{user}}", user);
content.innerHTML = '<br><br><span class="loading-spinner"></span>';
// console.log("open.dialog", el, "content", content, "button", button, "url", url);
container.innerHTML = '<br><br><span class="loading-spinner"></span>';
// console.log("open.dialog", el, "container", container, "button", button, "url", url);
fetch(url).then((res) => res.text()).then((html) => {
content.innerHTML = html;
container.innerHTML = html;
});
});

Expand All @@ -24,17 +21,16 @@ document.addEventListener("DOMContentLoaded", () => {
const response = JSON.parse(responseText.detail[0].response)
const button = document.querySelector(`[data-verification-handler="${response.handler}"][data-verification-user-id="${response.userId}"]`);
// console.log("ajax:complete", responseText, "response", response, "button", button);
content.innerHTML = response.message;
container.innerHTML = response.message;

if (response.granted) {
button.classList.add("granted");
} else {
button.classList.remove("granted");
const forceVerificationCheck = content.querySelector("#force_verification_check");
const forceVerification = content.querySelector("#force_verification");
const forceVerificationCheck = container.querySelector("#force_verification_check");
const forceVerification = container.querySelector("#force_verification");

if (forceVerificationCheck) {
console.log(forceVerificationCheck);
forceVerificationCheck.addEventListener("change", function() {
forceVerification.disabled = !forceVerification.disabled;
if (forceVerificationCheck.checked) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
&-td:not(:first-child) {
@apply text-left;

button {
a {
@apply text-sm font-normal block;

&:hover {
@apply text-secondary underline;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
data[:dialog_open] = "awesome-verification-modal"
end
%>
<%= content_tag(auth[:managed] ? "button" : "div", class: classes, data:) do %>
<%= content_tag(auth[:managed] ? "a" : "div", href: "#", class: classes, data:) do %>
<%= icon "check-line", class: "checked" %>
<%= icon "time-line", class: "undeterminated" %>
<%= icon "close-line", class: "unchecked" %>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
<%= decidim_modal id: "awesome-verification-modal", class:"reveal awesome_participants-modal" do %>
<div data-dialog-container>
<%= icon "lock-line" %>
<h3 tabindex="-1" data-dialog-title>
<%= t(".authorizations_for", user: "{{user}}") %>
</h3>
<div data-dialog-content>
</div>
</div>
<div data-dialog-actions>
<button data-dialog-close="awesome-verification-modal" class="button button__lg button__transparent-secondary">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<%= icon "lock-line" %>
<h3 tabindex="-1" data-dialog-title>
<%= t("decidim.decidim_awesome.admin.officializations.verification_modal.authorizations_for", user: user.name) %>
</h3>
<div data-dialog-content>
<%= yield %>
</div>
2 changes: 1 addition & 1 deletion lib/decidim/decidim_awesome/admin_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AdminEngine < ::Rails::Engine
end
# submenus
Decidim::DecidimAwesome::Menu.register_custom_fields_submenu!
Decidim::DecidimAwesome::Menu.register_custom__styles_submenu!
Decidim::DecidimAwesome::Menu.register_custom_styles_submenu!
Decidim::DecidimAwesome::Menu.register_menu_hacks_submenu!
Decidim::DecidimAwesome::Menu.register_maintenance_admin_menu!
Decidim::DecidimAwesome::Menu.register_awesome_admin_menu!
Expand Down
2 changes: 2 additions & 0 deletions lib/decidim/decidim_awesome/awesome.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module Decidim
module DecidimAwesome
include ActiveSupport::Configurable

autoload :AwesomeHelpers, "decidim/decidim_awesome/awesome_helpers"
autoload :RequestMemoizer, "decidim/decidim_awesome/request_memoizer"
autoload :Config, "decidim/decidim_awesome/config"
autoload :SystemChecker, "decidim/decidim_awesome/system_checker"
autoload :ContextAnalyzers, "decidim/decidim_awesome/context_analyzers"
Expand Down
61 changes: 39 additions & 22 deletions lib/decidim/decidim_awesome/awesome_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,27 @@ module Decidim
# add a global helper with awesome configuration
module DecidimAwesome
module AwesomeHelpers
include RequestMemoizer

# Returns the normalized config for an Organization and the current url
def awesome_config_instance
return @awesome_config_instance if @awesome_config_instance

# if already created in the middleware, reuse it as it might have additional constraints
@awesome_config_instance = request.env["decidim_awesome.current_config"]
unless @awesome_config_instance.is_a? Config
@awesome_config_instance = Config.new request.env["decidim.current_organization"]
@awesome_config_instance.context_from_request request
memoize("current_config") do
config = Config.new(request.env["decidim.current_organization"])
config.context_from_request(request)
config
end
@awesome_config_instance
end

def awesome_config
@awesome_config ||= awesome_config_instance.config
memoize("awesome_config") do
awesome_config_instance.config
end
end

def javascript_config_vars
awesome_config.slice(:allow_images_in_proposals, :allow_images_in_editors, :allow_videos_in_editors, :auto_save_forms).to_json.html_safe
memoize("javascript_config_vars") do
awesome_config.slice(:allow_images_in_proposals, :allow_images_in_editors, :allow_videos_in_editors, :auto_save_forms).to_json.html_safe
end
end

def show_public_intergram?
Expand All @@ -35,11 +37,15 @@ def show_public_intergram?
end

def unfiltered_awesome_config
@unfiltered_awesome_config ||= awesome_config_instance.unfiltered_config
memoize("unfiltered_awesome_config") do
awesome_config_instance.unfiltered_config
end
end

def organization_awesome_config
@organization_awesome_config ||= awesome_config_instance.organization_config
memoize("organization_awesome_config") do
awesome_config_instance.organization_config
end
end

def awesome_version
Expand All @@ -48,40 +54,51 @@ def awesome_version

# Collects all CSS that is applied in the current URL context
def awesome_scoped_styles
@awesome_scoped_styles ||= awesome_config_instance.collect_sub_configs_values("scoped_style")
memoize("awesome_scoped_styles") do
awesome_config_instance.collect_sub_configs_values("scoped_style")
end
end

# Collects all CSS that is applied in the current URL context
def awesome_scoped_admin_styles
@awesome_scoped_admin_styles ||= awesome_config_instance.collect_sub_configs_values("scoped_admin_style")
memoize("awesome_scoped_admin_styles") do
awesome_config_instance.collect_sub_configs_values("scoped_admin_style")
end
end

# Collects all proposal custom fields that is applied in the current URL context
def awesome_scoped_admins
@awesome_scoped_admins ||= awesome_config_instance.collect_sub_configs_values("scoped_admin")
memoize("awesome_scoped_admins") do
awesome_config_instance.collect_sub_configs_values("scoped_admin")
end
end

# Collects all proposal custom fields that is applied in the current URL context
def awesome_proposal_custom_fields
@awesome_proposal_custom_fields ||= awesome_config_instance.collect_sub_configs_values("proposal_custom_field")
memoize("awesome_proposal_custom_fields") do
awesome_config_instance.collect_sub_configs_values("proposal_custom_field")
end
end

def awesome_proposal_private_custom_fields
@awesome_proposal_private_custom_fields ||= awesome_config_instance.collect_sub_configs_values("proposal_private_custom_field")
memoize("awesome_proposal_private_custom_fields") do
awesome_config_instance.collect_sub_configs_values("proposal_private_custom_field")
end
end

# this will check if the current component has been configured to use a custom voting manifest
def awesome_voting_manifest_for(component)
return nil unless component.settings.respond_to? :awesome_voting_manifest

DecidimAwesome.voting_registry.find(component.settings.awesome_voting_manifest)
memoize("awesome_voting_manifest_for_#{component.id}") do
DecidimAwesome.voting_registry.find(component.settings.try(:awesome_voting_manifest))
end
end

# Retrives all the "admins_available_authorizations" for the user along with other possible authorizations
# returns an instance of Decidim::DecidimAwesome::Authorizator
def awesome_authorizations_for(user)
@awesome_authorizations_for ||= {}
@awesome_authorizations_for[user.id] ||= Authorizator.new(user, awesome_config[:admins_available_authorizations])
memoize("awesome_authorizations_for_#{user.id}") do
Authorizator.new(user, awesome_config[:admins_available_authorizations])
end
end

def version_prefix
Expand Down
4 changes: 0 additions & 4 deletions lib/decidim/decidim_awesome/engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ class Engine < ::Rails::Engine
# https://edgeguides.rubyonrails.org/engines.html#overriding-models-and-controllers
# overrides
config.to_prepare do
# activate Decidim LayoutHelper for the overriden views
ActiveSupport.on_load :action_controller do
helper Decidim::LayoutHelper if respond_to?(:helper)
end
# Include additional helpers globally
ActiveSupport.on_load(:action_view) { include Decidim::DecidimAwesome::AwesomeHelpers }
# Also for cells
Expand Down
2 changes: 1 addition & 1 deletion lib/decidim/decidim_awesome/menu.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def register_custom_fields_submenu!
end
end

def register_custom__styles_submenu!
def register_custom_styles_submenu!
Decidim.menu :custom_styles_submenu do |menu|
menu.add_item :scoped_styles,
I18n.t("menu.title", scope: "decidim.decidim_awesome.admin.scoped_styles"),
Expand Down
14 changes: 14 additions & 0 deletions lib/decidim/decidim_awesome/request_memoizer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# frozen_string_literal: true

module Decidim
module DecidimAwesome
module RequestMemoizer
# memoize a piece of code in the global request instead of the helper instance (helpers are initialized for each view)
def memoize(key)
return yield unless defined?(request) && request.env["decidim.current_organization"]&.id

request.env["decidim_awesome.#{key}"] ||= yield
end
end
end
end
2 changes: 1 addition & 1 deletion lib/decidim/decidim_awesome/version.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
module Decidim
# This holds the decidim-decidim_awesome version.
module DecidimAwesome
VERSION = "0.11.2"
VERSION = "0.11.3"
COMPAT_DECIDIM_VERSION = [">= 0.28.0", "< 0.29"].freeze
end
end
3 changes: 3 additions & 0 deletions spec/cells/proposal_l_cell_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ module Proposals
let!(:component) { create(:proposal_component, :with_votes_enabled, organization:, settings: { awesome_voting_manifest: manifest }) }
let!(:extra_fields) { create(:awesome_proposal_extra_fields, proposal:) }
let(:proposal) { create(:proposal, component:) }
let(:request) { double(host: "example.org", env: {}) }

before do
allow(subject).to receive(:request).and_return(request)
Decidim::DecidimAwesome.voting_registry.register(:another_voting_system) do |voting|
voting.show_vote_button_view = ""
voting.show_votes_count_view = ""
Expand Down Expand Up @@ -41,6 +43,7 @@ module Proposals
extra_fields.update_column(:vote_weight_totals, 100)
# rubocop:enable Rails/SkipsModelValidations
proposal.reload
subject.instance_variable_set(:@cache_hash, nil)
expect(cache1).not_to eq(subject.send(:cache_hash))
end
end
Expand Down
Loading
Loading