docbrown/app/controllers/admin/creator_settings_controller.rb
Ridhwana e250b46ed2
Using a Form Object that will persist for the Creator Settings Form (#15684)
* WIP: add a creatore settings form

* WIP: updat the controller to use the Creator Settings FOREM

* feat: use the creator settings form for the new action

* feat: add some default values for the new action

* a note about form data

* update the initiaize function to set some default values

* feat: update the form to use the model data

* feat: permit adn use the attributes within creator_settings_form

* update the flash error

* refactor: require and permit parameters

* chore: use booleans, set defaults and validate the form

* spec: update all the creator_settings tests

* chore: remove comment

* refactor: use self

* feat: aggregate failures'

* chore: remove the logo uploader in the controller

* refactor: update error handling

* feat: update the wasy the controller handles success and error

* chore: remove the resource errors

* feat: show flash message on new line

* fix: use a redirect so that we can get back to /new

* refactor: pass these values through as they seem to be caching whne setting them as default

* chore: change default values

* spec: update tests

* Fix CreatorSettingsForm specs

* fix: use a boolean for public

* spec: add another test for the success var

* fix: radio button labels to correspond + cyress specs

* spec: update based on new changes

* spec: update the params and the expected output

* spec: update the comments and status

* feat: no need for the initialize as we use Active Record Attributes

* feat: update the tac and coc to be persisted when ticked

* fix: amend spec

* blank space

* Message

Co-authored-by: Michael Kohl <me@citizen428.net>
2021-12-10 17:07:40 +02:00

49 lines
1.8 KiB
Ruby

module Admin
class CreatorSettingsController < Admin::ApplicationController
ALLOWED_PARAMS = %i[checked_code_of_conduct checked_terms_and_conditions community_name
invite_only_mode logo primary_brand_color_hex public].freeze
def new
@creator_settings_form = CreatorSettingsForm.new(
community_name: ::Settings::Community.community_name,
public: ::Settings::UserExperience.public,
invite_only_mode: ::Settings::Authentication.invite_only_mode,
primary_brand_color_hex: ::Settings::UserExperience.primary_brand_color_hex,
checked_code_of_conduct: current_user.checked_code_of_conduct,
checked_terms_and_conditions: current_user.checked_terms_and_conditions,
)
@max_file_size = LogoUploader::MAX_FILE_SIZE
@logo_allowed_types = (LogoUploader::CONTENT_TYPE_ALLOWLIST +
LogoUploader::EXTENSION_ALLOWLIST.map { |extension| ".#{extension}" }).join(",")
end
def create
extra_authorization
@creator_settings_form = CreatorSettingsForm.new(settings_params)
current_user.update!(
checked_code_of_conduct: @creator_settings_form.checked_code_of_conduct,
checked_terms_and_conditions: @creator_settings_form.checked_terms_and_conditions,
)
@creator_settings_form.save
if @creator_settings_form.success
current_user.update!(saw_onboarding: true)
redirect_to root_path
else
flash[:error] = @creator_settings_form.errors.full_messages
redirect_to new_admin_creator_setting_path
end
end
private
def extra_authorization
not_authorized unless current_user.has_role?(:creator)
end
def settings_params
params.require(:creator_settings_form).permit(ALLOWED_PARAMS)
end
end
end