diff --git a/app/assets/stylesheets/decidim/direct_verifications/authorizations.scss b/app/assets/stylesheets/decidim/direct_verifications/authorizations.scss new file mode 100644 index 0000000..dcbad04 --- /dev/null +++ b/app/assets/stylesheets/decidim/direct_verifications/authorizations.scss @@ -0,0 +1,23 @@ +// Copied from "decidim/admin/utils/settings". We better import the file + +$black: #1a181d; +$font-family-monospace: Consolas, 'Liberation Mono', Courier, monospace; +$global-weight-normal: normal; +$light-gray: #eee; +$medium-gray: #adadad; + +$code-color: $black; +$code-font-family: $font-family-monospace; +$code-font-weight: $global-weight-normal; +$code-background: $light-gray; +$code-border: 1px solid $medium-gray; +$code-padding: rem-calc(2 5 1); + +.code { + background: $code-background; + color: $code-color; + font-family: $code-font-family; + font-weight: $code-font-weight; + border: $code-border; + padding: $code-padding; +} diff --git a/app/controllers/decidim/direct_verifications/verification/admin/authorizations_controller.rb b/app/controllers/decidim/direct_verifications/verification/admin/authorizations_controller.rb new file mode 100644 index 0000000..9c92666 --- /dev/null +++ b/app/controllers/decidim/direct_verifications/verification/admin/authorizations_controller.rb @@ -0,0 +1,35 @@ +# frozen_string_literal: true + +module Decidim + module DirectVerifications + module Verification + module Admin + class AuthorizationsController < Decidim::Admin::ApplicationController + layout "decidim/admin/users" + + def index + enforce_permission_to :index, :authorization + @authorizations = collection + end + + def destroy + if authorization.destroy + flash[:notice] = "successfully" + redirect_to authorizations_path + end + end + + private + + def collection + Decidim::Authorization.where(name: "direct_verifications").includes(:user) + end + + def authorization + @authorization ||= collection.find_by(id: params[:id]) + end + end + end + end + end +end diff --git a/app/views/decidim/direct_verifications/verification/admin/authorizations/index.html.erb b/app/views/decidim/direct_verifications/verification/admin/authorizations/index.html.erb new file mode 100644 index 0000000..e9e8f39 --- /dev/null +++ b/app/views/decidim/direct_verifications/verification/admin/authorizations/index.html.erb @@ -0,0 +1,42 @@ +<%= stylesheet_link_tag "decidim/direct_verifications/authorizations" %> + +
+
+

+ <%= t('.title') %> + <%= link_to t("admin.index.stats", scope: 'decidim.direct_verifications.verification'), stats_path, class: "button tiny button--title" %> + <%= link_to t(".new_import"), direct_verifications_path, class: "button tiny button--title" %> +

+
+
+
+ + + + + + + + + + + + <% @authorizations.each do |authorization| %> + + + + + + + + + <% end %> + +
<%= t('.name') %><%= t('.metadata') %><%= t('.user_name') %><%= t('.created_at') %> 
<%= authorization.name %><%= authorization.user.name %><%= authorization.created_at %> + <%= icon_link_to "circle-x", authorization_path(authorization), t("actions.destroy", scope: "decidim.admin"), class: "action-icon--remove", method: :delete, data: { confirm: t("actions.confirm_destroy", scope: "decidim.admin") } %> +
+
+
+
diff --git a/app/views/decidim/direct_verifications/verification/admin/direct_verifications/index.html.erb b/app/views/decidim/direct_verifications/verification/admin/direct_verifications/index.html.erb index ef4a22b..307464c 100644 --- a/app/views/decidim/direct_verifications/verification/admin/direct_verifications/index.html.erb +++ b/app/views/decidim/direct_verifications/verification/admin/direct_verifications/index.html.erb @@ -3,6 +3,7 @@

<%= t('admin.index.title', scope: 'decidim.direct_verifications.verification') %> <%= link_to t("admin.index.stats", scope: 'decidim.direct_verifications.verification'), stats_path, class: "button tiny button--title" %> + <%= link_to t("admin.index.authorizations", scope: "decidim.direct_verifications.verification"), authorizations_path, class: "button tiny button--title" %>

diff --git a/config/locales/en.yml b/config/locales/en.yml index e9ef8ef..695f652 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -21,6 +21,14 @@ en: direct_verifications: verification: admin: + authorizations: + index: + created_at: Created at + metadata: Metadata + name: Name + title: Authorizations + user_name: User name + new_import: New import direct_verifications: create: authorized: "%{authorized} users have been successfully verified using @@ -35,6 +43,7 @@ en: need to have explicit consent from your users in order to register them. Otherwise you will be infringing the GDPR regulation in EU countries. index: + authorizations: Authorized users stats: User stats title: Register and authorize users new: diff --git a/lib/decidim/direct_verifications/tests/factories.rb b/lib/decidim/direct_verifications/tests/factories.rb new file mode 100644 index 0000000..5cbf669 --- /dev/null +++ b/lib/decidim/direct_verifications/tests/factories.rb @@ -0,0 +1,11 @@ +# frozen_string_literal: true + +require "decidim/core/test/factories" + +FactoryBot.modify do + factory :authorization do + trait :direct_verification do + name { "direct_verifications" } + end + end +end diff --git a/lib/decidim/direct_verifications/verification/admin_engine.rb b/lib/decidim/direct_verifications/verification/admin_engine.rb index 22af2b2..838476e 100644 --- a/lib/decidim/direct_verifications/verification/admin_engine.rb +++ b/lib/decidim/direct_verifications/verification/admin_engine.rb @@ -10,6 +10,7 @@ class AdminEngine < ::Rails::Engine routes do resources :direct_verifications, only: [:index, :create, :stats] resources :stats, only: [:index] + resources :authorizations, only: [:index, :destroy] root to: "direct_verifications#index" end diff --git a/spec/controllers/decidim/direct_verifications/verification/admin/authorizations_controller_spec.rb b/spec/controllers/decidim/direct_verifications/verification/admin/authorizations_controller_spec.rb new file mode 100644 index 0000000..a298629 --- /dev/null +++ b/spec/controllers/decidim/direct_verifications/verification/admin/authorizations_controller_spec.rb @@ -0,0 +1,30 @@ +# frozen_string_literal: true + +require "spec_helper" + +module Decidim::DirectVerifications::Verification::Admin + describe AuthorizationsController, type: :controller do + routes { Decidim::DirectVerifications::Verification::AdminEngine.routes } + + let(:organization) { create(:organization) } + let(:user) { create(:user, :admin, :confirmed, organization: organization) } + + before do + request.env["decidim.current_organization"] = organization + sign_in user + end + + describe "#index" do + it "authorizes the action" do + expect(controller).to receive(:allowed_to?).with(:index, :authorization, {}) + + get :index + end + + it "renders the decidim/admin/users layout" do + get :index + expect(response).to render_template("layouts/decidim/admin/users") + end + end + end +end diff --git a/spec/factories.rb b/spec/factories.rb index 0e6d87b..0dcb8dd 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -1,3 +1,3 @@ # frozen_string_literal: true -require "decidim/core/test/factories" +require "decidim/direct_verifications/tests/factories" diff --git a/spec/system/decidim/direct_verifications/admin/admin_manages_imported_authorizations_spec.rb b/spec/system/decidim/direct_verifications/admin/admin_manages_imported_authorizations_spec.rb new file mode 100644 index 0000000..3ca8563 --- /dev/null +++ b/spec/system/decidim/direct_verifications/admin/admin_manages_imported_authorizations_spec.rb @@ -0,0 +1,57 @@ +# frozen_string_literal: true + +require "spec_helper" + +describe "Admin manages imported authorizations", type: :system do + let(:organization) { create(:organization) } + let(:user) { create(:user, :admin, :confirmed, organization: organization) } + + let!(:authorization) { create(:authorization, :direct_verification) } + let!(:non_direct_authorization) { create(:authorization) } + + let(:scope) { "decidim.direct_verifications.verification.admin" } + + before do + switch_to_host(organization.host) + login_as user, scope: :user + + visit decidim_admin_direct_verifications.direct_verifications_path + click_link I18n.t("index.authorizations", scope: scope) + end + + context "when listing authorizations" do + it "lists authorizations imported through direct_verifications" do + within "table thead" do + expect(page).to have_content(I18n.t("authorizations.index.name", scope: scope).upcase) + expect(page).to have_content(I18n.t("authorizations.index.metadata", scope: scope).upcase) + expect(page).to have_content(I18n.t("authorizations.index.user_name", scope: scope).upcase) + expect(page).to have_content(I18n.t("authorizations.index.created_at", scope: scope).upcase) + end + + within "tr[data-authorization-id=\"#{authorization.id}\"]" do + expect(page).to have_content(authorization.name) + expect(page).to have_content(authorization.metadata) + expect(page).to have_content(authorization.user.name) + expect(page).to have_content(authorization.created_at) + end + + expect(page).not_to have_content(non_direct_authorization.name) + end + + it "lets users navigate to stats and new import" do + expect(page).to have_link(t("decidim.direct_verifications.verification.admin.index.stats")) + expect(page).to have_link(t("decidim.direct_verifications.verification.admin.authorizations.index.new_import")) + end + end + + context "when destroying an authorization" do + it "destroys the authorizations" do + within "tr[data-authorization-id=\"#{authorization.id}\"]" do + accept_confirm { click_link "Delete" } + end + + expect(page).not_to have_content("tr[data-authorization-id=\"#{authorization.id}\"]") + expect(page).to have_admin_callout("successfully") + end + end +end