-
Notifications
You must be signed in to change notification settings - Fork 124
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
838 Rename Form to CustomForm::Form and Question to CustomForm::Quest…
…ion (#864) * Added module custom_form for Form and Question Controller and Views * Fix test cases for custom_form module for Form and Question * Nested modules * Modularize Form model and its related test cases * Modularize Question Module with CustomForm * Lint Fix * Fix seed file * Modulaize Question policy code and fix link in question form
- Loading branch information
1 parent
8974f4c
commit 3613dda
Showing
40 changed files
with
1,147 additions
and
1,093 deletions.
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
app/controllers/organizations/staff/custom_form/forms_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
module Organizations | ||
module Staff | ||
module CustomForm | ||
class FormsController < ApplicationController | ||
before_action :context_authorize! | ||
before_action :set_form, only: %i[show edit update destroy] | ||
|
||
layout "dashboard" | ||
|
||
def index | ||
@forms = authorized_scope(::CustomForm::Form.all) | ||
end | ||
|
||
def new | ||
@form = ::CustomForm::Form.new | ||
end | ||
|
||
def create | ||
@form = organization.forms.new(form_params) | ||
|
||
if @form.save | ||
redirect_to staff_custom_form_forms_path, notice: t(".success") | ||
else | ||
flash.now[:alert] = t(".error") | ||
|
||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def show | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
if @form.update(form_params) | ||
redirect_to staff_custom_form_forms_path, notice: t(".success") | ||
else | ||
render :edit, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@form.destroy | ||
|
||
redirect_to staff_custom_form_forms_path, notice: t(".success") | ||
end | ||
|
||
private | ||
|
||
def organization | ||
current_user.organization | ||
end | ||
|
||
def set_form | ||
@form = organization.forms.find(params[:id]) | ||
authorize! @form | ||
rescue ActiveRecord::RecordNotFound | ||
redirect_to staff_custom_form_forms_path, alert: t(".not_found") | ||
end | ||
|
||
def form_params | ||
params.require(:custom_form_form).permit(:name, :description, :title, :instructions) | ||
end | ||
|
||
def context_authorize! | ||
authorize! ::CustomForm::Form, context: {organization: Current.organization} | ||
end | ||
end | ||
end | ||
end | ||
end |
80 changes: 80 additions & 0 deletions
80
app/controllers/organizations/staff/custom_form/questions_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
module Organizations | ||
module Staff | ||
module CustomForm | ||
class QuestionsController < ApplicationController | ||
before_action :context_authorize! | ||
before_action :set_form | ||
before_action :set_question, only: %i[show edit update destroy] | ||
|
||
layout "dashboard" | ||
|
||
def index | ||
@questions = authorized_scope(@form.questions) | ||
end | ||
|
||
def new | ||
@question = @form.questions.new | ||
end | ||
|
||
def create | ||
@question = @form.questions.new(question_params) | ||
|
||
if @question.save | ||
redirect_to staff_custom_form_form_path(@form), notice: t(".success") | ||
else | ||
flash.now[:alert] = t(".error") | ||
|
||
render :new, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def edit | ||
end | ||
|
||
def update | ||
if @question.update(question_params) | ||
redirect_to staff_custom_form_form_path(@form), notice: t(".success") | ||
else | ||
flash.now[:alert] = t(".error") | ||
|
||
render :edit, status: :unprocessable_entity | ||
end | ||
end | ||
|
||
def destroy | ||
@question.destroy | ||
|
||
redirect_to staff_custom_form_form_path(@form), notice: t(".success") | ||
end | ||
|
||
private | ||
|
||
def organization | ||
current_user.organization | ||
end | ||
|
||
def set_form | ||
@form = organization.forms.find(params[:form_id]) | ||
authorize! @form | ||
rescue ActiveRecord::RecordNotFound | ||
redirect_to staff_custom_form_forms_path, alert: t("organizations.staff.custom_form.forms.not_found") | ||
end | ||
|
||
def set_question | ||
@question = @form.questions.find(params[:id]) | ||
authorize! @question | ||
rescue ActiveRecord::RecordNotFound | ||
redirect_to staff_custom_form_form_path(@form), alert: t(".not_found") | ||
end | ||
|
||
def question_params | ||
params.require(:custom_form_question).permit(:name, :description, :label, :help_text, :required, :input_type, :options) | ||
end | ||
|
||
def context_authorize! | ||
authorize! ::CustomForm::Question, context: {organization: Current.organization} | ||
end | ||
end | ||
end | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.
74 changes: 0 additions & 74 deletions
74
app/controllers/organizations/staff/questions_controller.rb
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Organizations | ||
module CustomForm | ||
class FormPolicy < ApplicationPolicy | ||
pre_check :verify_organization! | ||
pre_check :verify_active_staff! | ||
|
||
alias_rule :new?, :create?, :index?, to: :manage? | ||
|
||
def manage? | ||
permission?(:manage_forms) | ||
end | ||
end | ||
end | ||
end |
Oops, something went wrong.