docbrown/app/controllers/admin/spaces_controller.rb
Jeremy Friesen e2940e75ca
Adding :internal auditing for admin/spaces#update (#17010)
There are two existing listeners for the `Audit::Logger`: `:moderator`
and `:internal`.  (Note: during tests we ignore the :moderator and
:internal logs as defined in [config/initializers/audit_events.rb][1].)

Using `rg "Audit::Logger\.log\(:internal," --files-with-matches`, the
`:internal` listener is found in:

- app/controllers/admin/secrets_controller.rb
- app/controllers/admin/settings/base_controller.rb
- app/controllers/admin/settings/general_settings_controller.rb

Using `rg "Audit::Logger\.log\(:moderator," --files-with-matches`, the
`:moderator` listener is used in:

- app/controllers/rating_votes_controller.rb
- app/controllers/comments_controller.rb
- app/controllers/stories/pinned_articles_controller.rb
- app/controllers/admin/response_templates_controller.rb
- app/controllers/admin/tags_controller.rb
- app/controllers/admin/articles_controller.rb
- app/controllers/admin/users_controller.rb
- app/controllers/admin/reactions_controller.rb
- app/controllers/admin/tags/moderators_controller.rb
- app/controllers/tag_adjustments_controller.rb
- app/controllers/reactions_controller.rb

The `admin/spaces#update` action is most similar to the `admin#settings`
actions, which is why I chose `:internal`.  I am looking for further
guidance on documenting this little area of the application (in
particular providing a data dictionary of :internal and :moderator).

Closes forem/forem#16957

[1]:https://github.com/forem/forem/blob/main/config/initializers/audit_events.rb#L9-L11
2022-03-25 14:25:13 -04:00

48 lines
1.5 KiB
Ruby

module Admin
# @note The ./config/routes/admin.rb file has a constraint around this controller
#
# @see https://github.com/orgs/forem/projects/46/views/1 project
class SpacesController < Admin::ApplicationController
layout "admin"
after_action only: %i[update] do
Audit::Logger.log(:internal, current_user, params.dup)
end
# @note I'm instantiating the @space because in the index view I'm rendering a form that then
# PUTs to the update action.
def index
authorize(Space)
@space = Space.new
end
# @note The initial implementation of Spaces is simply exposing a means of toggling on or off a
# feature flag. Further, the Space model is an ApplicationRecord model, but instead is
# the bare bones for a quick yet verbose implementation of the [Authorization System: use
# case 1-1](see https://github.com/orgs/forem/projects/46/views/1)
def update
# NOTE: We're not trying to find a space, we simply are treating this as a singleton type
# resource.
@space = Space.new(space_params)
authorize(@space)
# NOTE: As of <2022-03-16 Wed> we don't have validation on a space.
@space.save
respond_to do |wants|
wants.html do
redirect_to admin_spaces_path
end
wants.json do
render json: @space, status: :ok
end
end
end
private
def space_params
params.fetch(:space).permit(:limit_post_creation_to_admins)
end
end
end