2024-06-03 15:18:14 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
|
|
|
class Admin::Config::AboutController < Admin::AdminController
|
|
|
|
def index
|
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
2024-07-01 10:40:37 +08:00
|
|
|
settings_map = {}
|
|
|
|
if general_settings = params[:general_settings]
|
|
|
|
settings_map[:title] = general_settings[:name]
|
|
|
|
settings_map[:site_description] = general_settings[:summary]
|
|
|
|
settings_map[:about_banner_image] = general_settings[:about_banner_image]
|
|
|
|
|
|
|
|
settings_map[:extended_site_description] = general_settings[:extended_description]
|
2024-10-31 15:04:31 +08:00
|
|
|
settings_map[:short_site_description] = general_settings[:community_title]
|
2024-07-01 10:40:37 +08:00
|
|
|
if settings_map[:extended_site_description].present?
|
|
|
|
settings_map[:extended_site_description_cooked] = PrettyText.markdown(
|
|
|
|
settings_map[:extended_site_description],
|
|
|
|
)
|
|
|
|
else
|
|
|
|
settings_map[:extended_site_description_cooked] = ""
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if contact_information = params[:contact_information]
|
|
|
|
settings_map[:community_owner] = contact_information[:community_owner]
|
|
|
|
settings_map[:contact_email] = contact_information[:contact_email]
|
|
|
|
settings_map[:contact_url] = contact_information[:contact_url]
|
|
|
|
settings_map[:site_contact_username] = contact_information[:contact_username]
|
|
|
|
settings_map[:site_contact_group_name] = contact_information[:contact_group_name]
|
|
|
|
end
|
|
|
|
|
|
|
|
if your_organization = params[:your_organization]
|
|
|
|
settings_map[:company_name] = your_organization[:company_name]
|
|
|
|
settings_map[:governing_law] = your_organization[:governing_law]
|
|
|
|
settings_map[:city_for_disputes] = your_organization[:city_for_disputes]
|
|
|
|
end
|
|
|
|
|
|
|
|
settings_map.each do |name, value|
|
2024-10-18 17:13:34 +08:00
|
|
|
SiteSetting::Update.call(
|
|
|
|
guardian:,
|
DEV: Provide user input to services using `params` key
Currently in services, we don’t make a distinction between input
parameters, options and dependencies.
This can lead to user input modifying the service behavior, whereas it
was not the developer intention.
This patch addresses the issue by changing how data is provided to
services:
- `params` is now used to hold all data coming from outside (typically
user input from a controller) and a contract will take its values from
`params`.
- `options` is a new key to provide options to a service. This typically
allows changing a service behavior at runtime. It is, of course,
totally optional.
- `dependencies` is actually anything else provided to the service (like
`guardian`) and available directly from the context object.
The `service_params` helper in controllers has been updated to reflect
those changes, so most of the existing services didn’t need specific
changes.
The options block has the same DSL as contracts, as it’s also based on
`ActiveModel`. There aren’t any validations, though. Here’s an example:
```ruby
options do
attribute :allow_changing_hidden, :boolean, default: false
end
```
And here’s an example of how to call a service with the new keys:
```ruby
MyService.call(params: { key1: value1, … }, options: { my_option: true }, guardian:, …)
```
2024-10-18 23:45:47 +08:00
|
|
|
params: {
|
|
|
|
setting_name: name,
|
|
|
|
new_value: value,
|
|
|
|
},
|
|
|
|
options: {
|
|
|
|
allow_changing_hidden: %i[
|
|
|
|
extended_site_description
|
|
|
|
extended_site_description_cooked
|
|
|
|
about_banner_image
|
|
|
|
community_owner
|
|
|
|
].include?(name),
|
|
|
|
},
|
2024-07-01 10:40:37 +08:00
|
|
|
)
|
|
|
|
end
|
|
|
|
render json: success_json
|
2024-06-03 15:18:14 +08:00
|
|
|
end
|
|
|
|
end
|