Skip to content

Commit

Permalink
RUBY-3433: Tech Debt : remove devise and cancancan gems + remove fron…
Browse files Browse the repository at this point in the history
…t-office users from wcr engine (#1583)

* [RUBY-3433] Remove devise gem and dependencies + refactor tests to accommodate these changes

* [RUBY-3433] moving TransientRegistrationsController from engine to back-office

* [RUBY-3433] removing cancacan gem and permission check code associated with user permissions

* [RUBY-3433] Moving email tracking analyics tests to back-office

* [RUBY-3433] refactoring prepare_for_payment method not to require user object to be passed in

* [RUBY-3433] refactoring FlowPermissionChecksService not to require user object to be passed in

* [RUBY-3433] refactoring front-office related services not to require user object to be passed in

* [RUBY-3433] removing front-office user model

* [RUBY-3433] moving conviction sign-offs related tests to back-office

* [RUBY-3433] refactoring permission check not to check on front-office user permissions

* [RUBY-3433] refactoring CertificateGeneratorService to make requester parameter optional

* [RUBY-3433] Refactor permission check to make user parameter optional

* [RUBY-3433] updating readme

* [RUBY-3433] Refactor payment setup in controllers to include current user parameter

* [RUBY-3433] code styling adjustments

* [RUBY-3433] adding nocov tags to the code that does not get executed

* [RUBY-3433] Refactor current_user method in application_controller.rb

* [RUBY-3433] deleting redundant user factory

* [RUBY-3433] removing redundant method
  • Loading branch information
brujeo authored Oct 25, 2024
1 parent 41f08ab commit 218201b
Show file tree
Hide file tree
Showing 53 changed files with 248 additions and 1,386 deletions.
6 changes: 0 additions & 6 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,6 @@ gem "defra_ruby_template", "~> 5.0"

gem "mongo_session_store"

# Use CanCanCan for user roles and permissions
gem "cancancan", "~> 3.5.0"

# Use Devise for user authentication
gem "devise", "~> 4.9.2"

gem "matrix", "~> 0.4.2"

gem "secure_headers", "~> 6.5.0"
Expand Down
16 changes: 0 additions & 16 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,10 @@ GEM
async-pool (0.4.0)
async (>= 1.25)
base64 (0.2.0)
bcrypt (3.1.20)
bindex (0.8.1)
bson (4.15.0)
builder (3.3.0)
byebug (11.1.3)
cancancan (3.5.0)
coderay (1.1.3)
concurrent-ruby (1.3.4)
console (1.23.2)
Expand Down Expand Up @@ -163,12 +161,6 @@ GEM
rest-client (~> 2.0)
uk_postcode
validates_email_format_of
devise (4.9.4)
bcrypt (~> 3.0)
orm_adapter (~> 0.1)
railties (>= 4.1.0)
responders
warden (~> 1.2.3)
diff-lcs (1.5.0)
docile (1.4.0)
domain_name (0.6.20231109)
Expand Down Expand Up @@ -274,7 +266,6 @@ GEM
octokit (4.25.1)
faraday (>= 1, < 3)
sawyer (~> 0.9)
orm_adapter (0.5.0)
os_map_ref (0.5.0)
parallel (1.23.0)
parser (3.2.2.4)
Expand Down Expand Up @@ -335,9 +326,6 @@ GEM
rake (13.2.1)
rbtree3 (0.7.1)
regexp_parser (2.8.2)
responders (3.1.1)
actionpack (>= 5.2)
railties (>= 5.2)
rest-client (2.1.0)
http-accept (>= 1.7.0, < 2.0)
http-cookie (>= 1.0.2, < 2.0)
Expand Down Expand Up @@ -443,8 +431,6 @@ GEM
validates_email_format_of (1.7.2)
i18n
vcr (6.2.0)
warden (1.2.9)
rack (>= 2.0.9)
web-console (4.2.1)
actionview (>= 6.0.0)
activemodel (>= 6.0.0)
Expand All @@ -465,11 +451,9 @@ PLATFORMS
ruby

DEPENDENCIES
cancancan (~> 3.5.0)
database_cleaner-mongoid (~> 2.0.1)
defra_ruby_style (~> 0.3.0)
defra_ruby_template (~> 5.0)
devise (~> 4.9.2)
dotenv-rails (~> 2.8.1)
factory_bot_rails (~> 6.2.0)
faker (~> 3.2.0)
Expand Down
7 changes: 0 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,6 @@ Make sure you already have:
- [Bundler](http://bundler.io/) – for installing Ruby gems
- MongoDb 3.6

The engine also expects these gems to be installed in the application in which it is mounted:

- [Devise](https://github.com/plataformatec/devise/) >= 4.4.3
- [CanCanCan](https://github.com/CanCanCommunity/cancancan) ~> 1.10

And for a User model to be in place. See the [dummy testing app](https://github.com/DEFRA/waste-carriers-engine/tree/master/spec/dummy) for an example of how this might be implemented.

## Mounting the engine

Add the engine to your Gemfile:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,14 @@ class ApplicationController < ActionController::Base
redirect_to page_path("system_error")
end

def current_user
return unless defined?(super)

# :nocov:
super
# :nocov:
end

protected

def record_user_journey
Expand Down

This file was deleted.

2 changes: 1 addition & 1 deletion app/models/waste_carriers_engine/renewing_registration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ def pending_payment?
renewal_application_submitted? && super
end

def prepare_for_payment(mode, user)
def prepare_for_payment(mode, user = nil)
BuildRenewalFinanceDetailsService.run(transient_registration: self, payment_method: mode, user:)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class BaseRegistrationPermissionChecksService < BaseService

attr_reader :transient_registration, :user, :permission_check_result

def run(transient_registration:, user:)
def run(transient_registration:, user: nil)
@transient_registration = transient_registration
@user = user
@permission_check_result = PermissionChecksResult.new
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class MissingFlowPermissionChecksService < StandardError; end

attr_reader :transient_registration, :user

def run(transient_registration:, user:)
def run(transient_registration:, user: nil)
@transient_registration = transient_registration
@user = user

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
module WasteCarriersEngine
class GovpayPaymentService

def initialize(transient_registration, order, current_user)
def initialize(transient_registration, order, current_user = nil)
@transient_registration = transient_registration
@order = order
@current_user = current_user
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ def all_checks_pass?
end

def user_has_permission?
# user permission checks apply only to the back office
return true unless WasteCarriersEngine.configuration.host_is_back_office?

return true if transient_registration.from_magic_link
return true if can?(:update, transient_registration)

Expand Down
7 changes: 0 additions & 7 deletions app/views/devise/mailer/email_changed.html.erb

This file was deleted.

3 changes: 0 additions & 3 deletions app/views/devise/mailer/password_change.html.erb

This file was deleted.

8 changes: 0 additions & 8 deletions app/views/devise/mailer/reset_password_instructions.html.erb

This file was deleted.

7 changes: 0 additions & 7 deletions app/views/devise/mailer/unlock_instructions.html.erb

This file was deleted.

45 changes: 0 additions & 45 deletions app/views/devise/passwords/edit.html.erb

This file was deleted.

22 changes: 0 additions & 22 deletions app/views/devise/passwords/new.html.erb

This file was deleted.

32 changes: 0 additions & 32 deletions app/views/devise/sessions/new.html.erb

This file was deleted.

35 changes: 0 additions & 35 deletions app/views/devise/shared/_links.html.erb

This file was deleted.

22 changes: 0 additions & 22 deletions app/views/devise/unlocks/new.html.erb

This file was deleted.

15 changes: 15 additions & 0 deletions config/locales/activemodel.en.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Additional translations at https://github.com/plataformatec/devise/wiki/I18n

en:
activemodel:
errors:
models:
waste_carriers_engine/renewal_lookup_validatable:
already_confirmed: "Email was already confirmed, please try signing in"
confirmation_period_expired: "Email needs to be confirmed within %{period}, please request a new one"
expired: "Password reset token has expired, please request a new one"
not_found: "Password reset token not found"
not_locked: "Account was not locked"
not_saved:
one: "1 error prohibited this %{resource} from being saved:"
other: "%{count} errors prohibited this %{resource} from being saved:"
Loading

0 comments on commit 218201b

Please sign in to comment.