diff --git a/app/controllers/decidim/file_authorization_handler/admin/censuses_controller.rb b/app/controllers/decidim/file_authorization_handler/admin/censuses_controller.rb index db48229..c199cbd 100644 --- a/app/controllers/decidim/file_authorization_handler/admin/censuses_controller.rb +++ b/app/controllers/decidim/file_authorization_handler/admin/censuses_controller.rb @@ -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) @@ -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 diff --git a/app/views/decidim/file_authorization_handler/admin/censuses/show.html.erb b/app/views/decidim/file_authorization_handler/admin/censuses/show.html.erb index 67f4df2..1c81ce7 100644 --- a/app/views/decidim/file_authorization_handler/admin/censuses/show.html.erb +++ b/app/views/decidim/file_authorization_handler/admin/censuses/show.html.erb @@ -37,3 +37,18 @@ <% end %> + + +
+
+

+ <%= t('admin.update.title', scope: 'decidim.file_authorization_handler') %> +

+
+
+

<%= t('admin.update.info', scope: 'decidim.file_authorization_handler') %>

+ <%= 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 %> +
+
diff --git a/config/locales/ca.yml b/config/locales/ca.yml index 65a6059..1f39eb6 100644 --- a/config/locales/ca.yml +++ b/config/locales/ca.yml @@ -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: @@ -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 + diff --git a/config/locales/en.yml b/config/locales/en.yml index 07910c1..14e03ad 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -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. diff --git a/config/locales/es.yml b/config/locales/es.yml index bee9280..16acc98 100644 --- a/config/locales/es.yml +++ b/config/locales/es.yml @@ -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: @@ -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 diff --git a/config/routes.rb b/config/routes.rb new file mode 100644 index 0000000..f9ba532 --- /dev/null +++ b/config/routes.rb @@ -0,0 +1,5 @@ +# frozen_string_literal: true + +Decidim::FileAuthorizationHandler::AdminEngine.routes.draw do + post "/delete_authorizations" => "censuses#delete_authorizations" +end diff --git a/decidim-file_authorization_handler.gemspec b/decidim-file_authorization_handler.gemspec index 1afb243..454e536 100644 --- a/decidim-file_authorization_handler.gemspec +++ b/decidim-file_authorization_handler.gemspec @@ -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 diff --git a/lib/decidim/file_authorization_handler/admin_engine.rb b/lib/decidim/file_authorization_handler/admin_engine.rb index 95aea78..f982110 100644 --- a/lib/decidim/file_authorization_handler/admin_engine.rb +++ b/lib/decidim/file_authorization_handler/admin_engine.rb @@ -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|