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

List imported authorizations #4

Merged
merged 5 commits into from
Oct 23, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
<%= stylesheet_link_tag "decidim/direct_verifications/authorizations" %>

<div class="card">
<div class="card-divider">
<h2 class="card-title">
<%= 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" %>
</h2>
</div>
<div class="card-section">
<div class="table-scroll">
<table class="table-list">
<thead>
<tr>
<th><%= t('.name') %></th>
<th><%= t('.metadata') %></th>
<th><%= t('.user_name') %></th>
<th><%= t('.created_at') %></th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody>
<% @authorizations.each do |authorization| %>
<tr data-authorization-id="<%= authorization.id %>">
<td><%= authorization.name %></td>
<td class="metadata">
<span class="code"><%= authorization.metadata %></span>
</td>
<td><%= authorization.user.name %></td>
<td><%= authorization.created_at %></td>

<td class="table-list__actions">
<%= 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") } %>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<h2 class="card-title">
<%= 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" %>
</h2>
</div>
<div class="card-section">
Expand Down
9 changes: 9 additions & 0 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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:
Expand Down
11 changes: 11 additions & 0 deletions lib/decidim/direct_verifications/tests/factories.rb
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion spec/factories.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
# frozen_string_literal: true

require "decidim/core/test/factories"
require "decidim/direct_verifications/tests/factories"
Original file line number Diff line number Diff line change
@@ -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