Skip to content

Commit efd1b56

Browse files
committed
Add FormsController base controller
Move form-specific methods from WebController into a new FormsController which all controllers that handle ations related to an individual form inherit from. We need to add a new form-specific after_action and don't want to further pollute WebController with form-specific code. Move the verify_authorized after_action to the FormsController to avoid duplication and to ensure that all form-related controllers have authorisation checks.
1 parent c8556cb commit efd1b56

27 files changed

+72
-99
lines changed

app/controllers/forms/archive_form_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Forms
2-
class ArchiveFormController < WebController
2+
class ArchiveFormController < FormsController
33
before_action :check_user_has_permission
4-
after_action :verify_authorized
54

65
def archive
76
return redirect_to path_to_form unless current_form.is_live?

app/controllers/forms/archive_welsh_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Forms
2-
class ArchiveWelshController < WebController
2+
class ArchiveWelshController < FormsController
33
before_action :check_user_has_permission
4-
after_action :verify_authorized
54

65
def show
76
return redirect_to path_to_form unless has_live_welsh_translation?

app/controllers/forms/archived_controller.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
module Forms
2-
class ArchivedController < WebController
3-
after_action :verify_authorized
4-
2+
class ArchivedController < FormsController
53
def show_form
64
authorize current_form, :can_view_form?
75

app/controllers/forms/change_name_controller.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
module Forms
2-
class ChangeNameController < WebController
3-
after_action :verify_authorized
4-
2+
class ChangeNameController < FormsController
53
def edit
64
authorize current_form, :can_view_form?
75
@name_input = NameInput.new(form: current_form).assign_form_values

app/controllers/forms/contact_details_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module Forms
2-
class ContactDetailsController < WebController
3-
after_action :verify_authorized
2+
class ContactDetailsController < FormsController
43
def new
54
authorize current_form, :can_view_form?
65
@contact_details_input = ContactDetailsInput.new(form: current_form).assign_form_values

app/controllers/forms/copy_controller.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
module Forms
2-
class CopyController < WebController
3-
after_action :verify_authorized
4-
2+
class CopyController < FormsController
53
def copy
64
authorize current_form, :copy?
75

app/controllers/forms/daily_submission_batch_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module Forms
2-
class DailySubmissionBatchController < WebController
2+
class DailySubmissionBatchController < FormsController
33
before_action :check_feature_flag
4-
after_action :verify_authorized
54

65
def new
76
authorize current_form, :can_edit_form?

app/controllers/forms/declaration_controller.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
module Forms
2-
class DeclarationController < WebController
3-
after_action :verify_authorized
2+
class DeclarationController < FormsController
43
def new
54
authorize current_form, :can_view_form?
65
@declaration_input = DeclarationInput.new(form: current_form).assign_form_values

app/controllers/forms/delete_confirmation_controller.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
module Forms
2-
class DeleteConfirmationController < WebController
3-
after_action :verify_authorized
4-
2+
class DeleteConfirmationController < FormsController
53
def delete
64
authorize current_form
75

app/controllers/forms/draft_controller.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
class Forms::DraftController < WebController
2-
after_action :verify_authorized
3-
1+
class Forms::DraftController < FormsController
42
def show
53
authorize current_form, :can_view_form?
64
task_service = FormTaskListService.call(form: current_form, current_user:)

0 commit comments

Comments
 (0)