Skip to content

Commit

Permalink
Redirect user to where she was after verification (#21)
Browse files Browse the repository at this point in the history
* FEAT: Redirect user to where she was after verification

* Rubocopify

* FEAT: Autosubmit form

* Enable this Authorization to appear in the Admin/Participants menu option

* I18N: Add catalan translations

* Update doc

* I18N: Fix :es translation
  • Loading branch information
tramuntanal committed Apr 24, 2023
1 parent 2074fe9 commit 081ac7e
Show file tree
Hide file tree
Showing 32 changed files with 279 additions and 293 deletions.
13 changes: 9 additions & 4 deletions .rubocop.yml
@@ -1,15 +1,14 @@
---
require: rubocop-rspec

AllCops:
Exclude:
- "development_app/**/*"
- "spec/decidim_dummy_app/**/*"

NewCops: enable
DisplayCopNames: true

DisplayStyleGuide: true

TargetRubyVersion: 2.3
TargetRubyVersion: 2.7

Metrics:
Enabled: false
Expand All @@ -23,6 +22,9 @@ Layout/ExtraSpacing:
Lint/InterpolationCheck:
Enabled: false

RSpec/NestedGroups:
Max: 4

Style/AsciiComments:
Enabled: false

Expand Down Expand Up @@ -52,3 +54,6 @@ Style/SafeNavigation:

Style/StringLiterals:
EnforcedStyle: double_quotes

Style/SlicingWithRange:
Enabled: false
7 changes: 7 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,12 @@
= CHANGELOG

== 0.1.0 MINOR (2023-04-24)
- Redirect user to where she was after verification.
- Refactor: Internal refactoring to simplify code, remove unneeded code.
- Refactor: Rename form to CsvEmailAuthorizationHandler.
- Translate to Catalan.
- Make verification form to auto fill and auto submit.

== 0.0.11 PATCH (2023-01-24)
- Fix params in create action in AuthorizationsController because last upgrade changes was missing.
- Add the unique_id method to handler to avoid conflicts with others verificators.
Expand Down
22 changes: 7 additions & 15 deletions Gemfile
Expand Up @@ -7,24 +7,16 @@ ruby RUBY_VERSION
gemspec

group :development, :test do
gem "actionview", ">= 6.0.4.8"
gem "actionpack", ">= 6.0.4.8"
gem "activestorage", ">= 6.0.4.7"
gem "bootsnap"
gem "byebug", ">= 10.0", platform: :mri
gem "decidim"
gem "faker", ">= 1"
gem "image_processing", ">= 1.12.2"
gem "byebug", ">= 10.0", platform: :mri
gem 'bootsnap'
gem 'listen'
gem 'social-share-button'
gem "railties", ">= 6.0.4.8"
gem "puma", ">= 5.6.4"
gem "doc2text", ">=0.4.5"
gem "nokogiri",">= 1.13.4"
gem "rails",">= 6.0.4.8"
gem "letter_opener_web"
gem "listen"
gem "rails", ">= 6.0.4.8"
end

group :development do
gem "letter_opener_web", "~> 1.3"
gem "web-console", "~> 3.5"
gem "rubocop" # , "~> 1.28.0"
gem "rubocop-rails" # , "~> 1.28.0"
end
24 changes: 5 additions & 19 deletions Gemfile.lock
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
decidim-verifications-csv_email (0.0.11)
decidim-verifications-csv_email (0.1.0)
decidim (>= 0.25.2)
decidim-admin (>= 0.25.2)
decidim-verifications (>= 0.25.2)
Expand Down Expand Up @@ -96,7 +96,6 @@ GEM
html_tokenizer (~> 0.0.6)
parser (>= 2.4)
smart_properties
bindex (0.8.1)
bootsnap (1.10.1)
msgpack (~> 1.2)
browser (2.7.1)
Expand Down Expand Up @@ -757,11 +756,6 @@ GEM
rexml (~> 3.2)
warden (1.2.9)
rack (>= 2.0.9)
web-console (3.7.0)
actionview (>= 5.0)
activemodel (>= 5.0)
bindex (>= 0.4.0)
railties (>= 5.0)
webmock (3.14.0)
addressable (>= 2.8.0)
crack (>= 0.3.2)
Expand All @@ -787,28 +781,20 @@ PLATFORMS
ruby

DEPENDENCIES
actionpack (>= 6.0.4.8)
actionview (>= 6.0.4.8)
activestorage (>= 6.0.4.7)
bootsnap
byebug (>= 10.0)
decidim
decidim-dev (>= 0.25.2)
decidim-verifications-csv_email!
doc2text (>= 0.4.5)
faker (>= 1)
image_processing (>= 1.12.2)
letter_opener_web (~> 1.3)
letter_opener_web
listen
nokogiri (>= 1.13.4)
puma (>= 5.6.4)
rails (>= 6.0.4.8)
railties (>= 6.0.4.8)
social-share-button
web-console (~> 3.5)
rubocop
rubocop-rails

RUBY VERSION
ruby 2.7.5p203

BUNDLED WITH
2.3.4
2.3.6
4 changes: 3 additions & 1 deletion README.md
Expand Up @@ -7,7 +7,7 @@ real users parameterised.

This module provides a model `Decidim::Verifications::CsvEmail` to store users informations (email).

It has an admin controller to upload CSV files with the information. When importing files all records are inserted and the duplicates are removed in a background job for performance reasons.
It has an admin controller to upload CSV files with emails. When importing files all records are inserted and the duplicates are removed in a background job for performance reasons.

## Installation

Expand All @@ -25,6 +25,8 @@ bin/rails decidim_verifications_csv_email:install:migrations
bin/rails db:migrate
```

Enable the CsvEmail verifier in the desired organization's `system/` panel.

## Run tests

Create a dummy app in your application (if not present):
Expand Down

This file was deleted.

This file was deleted.

10 changes: 10 additions & 0 deletions app/decorators/lib/decidim/verifications/adapter_decorator.rb
@@ -0,0 +1,10 @@
# frozen_string_literal: true

Decidim::Verifications::Adapter.class_eval do
#
# Administrational entry point for the verification engine
#
def admin_root_path
admin_engine.send(:root_path, redirect_params)
end
end
1 change: 1 addition & 0 deletions app/decorators/models/decidim/user_decorator.rb
Expand Up @@ -8,6 +8,7 @@ def after_confirmation
.search_user_email(organization, email)

return if @census_for_user.blank?

@authorization = Decidim::Authorization.create(user: self, name: "csv_email_authorization_handler")
@authorization.grant!
end
Expand Down
43 changes: 43 additions & 0 deletions app/forms/csv_email_authorization_handler.rb
@@ -0,0 +1,43 @@
# frozen_string_literal: true

# A form object to be used when public users want to get verified by
# CsvEmail verificator
class CsvEmailAuthorizationHandler < Decidim::AuthorizationHandler
# This is the input (from the user) to validate against
attribute :email, String

# This is the validation to perform
# If passed, an authorization is created
validates :email, presence: true
validate :censed

def unique_id
Digest::SHA256.hexdigest(
"#{user&.decidim_organization_id}-#{user.email}-#{handler_name}-#{Rails.application.secrets.secret_key_base}"
)
end

# Checks if the email belongs to the census
def censed
return if (email == user.email) && (census_for_user&.email == email)

if email != user.email
errors.add(:email, I18n.t("decidim.verifications.csv_email.errors.messages.not_same_email"))
else
errors.add(:email, I18n.t("decidim.verifications.csv_email.errors.messages.not_in_csv"))
end
end

def authorized?
return true if census_for_user
end

def census_for_user
@census_for_user ||= Decidim::Verifications::CsvEmail::CsvEmailDatum
.search_user_email(organization, email)
end

def organization
current_organization || user&.organization
end
end
49 changes: 0 additions & 49 deletions app/forms/decidim/verifications/csv_email/csv_email_form.rb

This file was deleted.

4 changes: 1 addition & 3 deletions app/models/decidim/verifications/csv_email/csv_data.rb
Expand Up @@ -22,9 +22,7 @@ def initialize(file)

def process_row(row)
user_email = row[0]
if user_email.present?
values << row
end
values << row if user_email.present?
end
end
end
Expand Down
1 change: 0 additions & 1 deletion app/models/decidim/verifications/csv_email/status.rb
@@ -1,4 +1,3 @@

# frozen_string_literal: true

module Decidim
Expand Down
Expand Up @@ -8,10 +8,10 @@ module Admin
class Permissions < Decidim::DefaultPermissions
def permissions
return permission_action if permission_action.scope != :admin
if user.organization.available_authorizations.include?("csv_email_authorization_handler")
allow! if permission_action.subject == Decidim::Verifications::CsvEmail::CsvEmailDatum
permission_action
end
return unless user.organization.available_authorizations.include?("csv_email_authorization_handler")

allow! if permission_action.subject == Decidim::Verifications::CsvEmail::CsvEmailDatum
permission_action
end
end
end
Expand Down

0 comments on commit 081ac7e

Please sign in to comment.