mirror of
https://github.com/codeninjasllc/discourse.git
synced 2024-12-11 00:02:05 -05:00
2322586131
until you edited it.
40 lines
975 B
Ruby
40 lines
975 B
Ruby
class Admin::UserFieldsController < Admin::AdminController
|
|
|
|
def self.columns
|
|
[:name, :field_type, :editable, :description, :required]
|
|
end
|
|
|
|
def create
|
|
field = UserField.new(params.require(:user_field).permit(*Admin::UserFieldsController.columns))
|
|
field.required = params[:required] == "true"
|
|
json_result(field, serializer: UserFieldSerializer) do
|
|
field.save
|
|
end
|
|
end
|
|
|
|
def index
|
|
render_serialized(UserField.all, UserFieldSerializer, root: 'user_fields')
|
|
end
|
|
|
|
def update
|
|
field_params = params.require(:user_field)
|
|
|
|
field = UserField.where(id: params.require(:id)).first
|
|
|
|
Admin::UserFieldsController.columns.each do |col|
|
|
field.send("#{col}=", field_params[col] || false)
|
|
end
|
|
|
|
json_result(field, serializer: UserFieldSerializer) do
|
|
field.save
|
|
end
|
|
end
|
|
|
|
def destroy
|
|
field = UserField.where(id: params.require(:id)).first
|
|
field.destroy if field.present?
|
|
render nothing: true
|
|
end
|
|
|
|
end
|
|
|