Skip to content
This repository has been archived by the owner on Jan 25, 2021. It is now read-only.

Added an option to unauthorize all previously authotized users. #18

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
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
Expand Up @@ -12,6 +12,7 @@ def show
def create
authorize! :create, CensusDatum
if params[:file]
remove_all_authorizations if params[:unverify]
data = CsvData.new(params[:file].path)
CensusDatum.insert_all(current_organization, data.values)
RemoveDuplicatesJob.perform_later(current_organization)
Expand All @@ -26,6 +27,18 @@ def destroy
CensusDatum.clear(current_organization)
redirect_to censuses_path, notice: t(".success")
end

def delete_authorizations
authorize! :update, CensusDatum
remove_all_authorizations
redirect_to censuses_path, notice: t(".success")
end

private

def remove_all_authorizations
Authorization.where(organization: current_organization, name: "file_authorization_handler").destroy_all
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,18 @@
<% end %>
</div>
</div>


<div class="card">
<div class="card-divider">
<h2 class="card-title">
<%= t('admin.update.title', scope: 'decidim.file_authorization_handler') %>
</h2>
</div>
<div class="card-section">
<p><%= t('admin.update.info', scope: 'decidim.file_authorization_handler') %></p>
<%= form_tag controller: "censuses", action: "delete_authorizations",multipart: false, class: 'form', method: :post do %>
<%= submit_tag t('admin.update.submit', scope: 'decidim.file_authorization_handler'), class: 'button' %>
<% end %>
</div>
</div>
7 changes: 7 additions & 0 deletions config/locales/ca.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ ca:
success: S'han importat amb èxit %{count} elements (%{errors} errors)
destroy:
success: S'han esborrat totes les dades censals
delete_authorizations:
success: Autoritzacions eliminades
menu:
census: Pujar cens
show:
Expand All @@ -43,3 +45,8 @@ ca:
title: Pujar un nou cens
file: Arxiu excel .csv amb les dades del cens
submit: Carrega
update:
title: Neteja autoritzacions
info: "Elimina totes les autoritzacions existents (atenció: tots els usuaris hauran de tornar a autoritzar-se)"
submit: Elimina

46 changes: 23 additions & 23 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,44 @@ en:
activemodel:
attributes:
file_authorization_handler:
id_document: Identification document (DNI, NIF, Password or Residence Card)
birthdate: Date of birth
census_authorization:
form:
date_select:
day: Day
month: Month
year: Year
id_document: Identification document (DNI, NIF, Password or Residence Card)
decidim:
authorization_handlers:
file_authorization_handler:
name: Municipality Census
explanation: Authorize your user account against the Municipality Census
type: Excel
name: Organization's Census
explanation: Authorize your user account against Organization's Census
type: CSV
fields:
birthdate: Birthdate
name: Municipality Census
file_authorization_handler:
errors:
messages:
not_censed: We could not find your document ID matching with this birthdate in our Census. If the data entered is correct and the problem persists, please, contact an administrator.
younger_than_minimum_age: You should be older than %{age} years
admin:
destroy:
title: Delete all census data
confirm: Delete all the census can not be undone. Are you sure you want to continue?
censuses:
create:
success: Successfully imported %{count} items (%{errors} errors)
destroy:
success: All census data have been deleted
delete_authorizations:
success: Removed authorizations
destroy:
confirm: Delete all the census can not be undone. Are you sure you want to continue?
title: Delete all census data
menu:
census: Upload census
show:
title: Current census data
data: There are %{count} records loaded in total. Last upload date was on %{due_date}
empty: There are no census data. Use the form below to import it using a CSV file.
new:
info: 'Must be a file generated by excel and exported with CSV format with two columns: identity document and date of birth'
title: Upload a new census
file: Excel .csv file with census data
info: 'Must be a file generated by excel and exported with CSV format with two columns: identity document and date of birth'
submit: Upload file
title: Upload a new census
show:
data: There are %{count} records loaded in total. Last upload date was on %{due_date}
empty: There are no census data. Use the form below to import it using a CSV file.
title: Current census data
update:
title: Remove authorizations
info: 'Remove all existing authorizations (attention: all users must be re-authorized)'
submit: Remove
errors:
messages:
not_censed: We could not find your document ID matching with this birthdate in our Census. If the data entered is correct and the problem persists, please, contact an administrator.
6 changes: 6 additions & 0 deletions config/locales/es.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ es:
success: Se han importado con éxito %{count} elementos (%{errors} errores)
destroy:
success: Se han borrado todos los datos censales
delete_authorizations:
success: Se han borrado todas las autorizaciones
menu:
census: Subir censo
show:
Expand All @@ -43,3 +45,7 @@ es:
title: Subir un nuevo censo
file: Archivo excel .csv con los datos del censo
submit: Subir archivo
update:
title: Limpiar autorizaciones
info: "Elimina todas las autorizaciones existentes (atención: todos los usuarios deberan volver a autorizarse)"
submit: Eliminar
5 changes: 5 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# frozen_string_literal: true

Decidim::FileAuthorizationHandler::AdminEngine.routes.draw do
post "/delete_authorizations" => "censuses#delete_authorizations"
end
9 changes: 5 additions & 4 deletions decidim-file_authorization_handler.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ Gem::Specification.new do |s|
s.files = Dir["{app,config,db,lib}/**/*", "MIT-LICENSE", "Rakefile", "README.md"]
s.test_files = Dir["spec/**/*"]

s.add_dependency "decidim", Decidim::FileAuthorizationHandler::VERSION
s.add_dependency "decidim-admin", Decidim::FileAuthorizationHandler::VERSION
s.add_dependency "rails", "~> 5.1.4"
s.add_dependency "decidim", ">= #{Decidim::FileAuthorizationHandler::VERSION}"
s.add_dependency "decidim-admin", ">= #{Decidim::FileAuthorizationHandler::VERSION}"
s.add_dependency "rails", ">= 5.2"

s.add_development_dependency "decidim-dev", Decidim::FileAuthorizationHandler::VERSION
s.add_development_dependency "decidim-dev", ">= #{Decidim::FileAuthorizationHandler::VERSION}"
s.add_development_dependency "faker"
s.add_development_dependency "letter_opener_web", "~> 1.3.3"
s.add_development_dependency "listen"
end
2 changes: 1 addition & 1 deletion lib/decidim/file_authorization_handler/admin_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class AdminEngine < ::Rails::Engine
isolate_namespace Decidim::FileAuthorizationHandler::Admin

routes do
resource :censuses, only: [:show, :create, :destroy]
resource :censuses, only: [:show, :create, :destroy, :delete_authorizations]
end

initializer "decidim_file_authorization.add_admin_authorizations" do |_app|
Expand Down