docbrown/app/controllers/admin/application_controller.rb
Julianna Tetreault 24a3b50d4a
Add the Ability to Remove Badge Achievements From Users (#9896) [deploy]
* Moves badge_achievement-related code from /admin/bagdes to /admin/badge_achievements
  - Adds an Admin::BadgeAchievements::Controller
  - Moves #award and #award_badges to Admin::BadgeAchievements::Controller
  - Removes #award and #award_badges from Admin::Badges::Controller
  - Moves award.html.erb from /admin/badges to /admin/badge_achievements
  - Removes badge_achievement routes from /admin/badges
  - Adds a redirect for /admin/badges/badge_achievements to routes.rb
  - Cleans up and refactors code in controllers, views, and routes

* Add more actions to Admin::BadgeAchievements::Controller and matching routes
  - Adds an #index and #destory action to the BadgeAchievements::Controller
  - Adds destroy to the badge_achievements routes
  - Adjusts redirects for badge_achievements in routes.rb
  - Removes dead code from the index view for Badges
  - Refactors the existing code in the index view for BadgeAchievements

* Adds an /admin/badge_achievements_spec and cleans up the /admin/badges_spec
  - Removes the badge_achievement-related tests from badges_spec.rb
  - Adds an additional test around deleting badge_achievements

* Add pagination to badge_achievements index view

* Adds badge_achievements to Admin menu items and add comment to routes.rb
  -Add badge_achievements to the Admin nav bar
  -Add a comment regarding redirects for badge_achievements

* Resolve JS console stacktrace notices and change wording on deletion buttons

* Add a Back to Badge Achievements button to the badge award form

* Adjust styling to fix failing /admin/badges_spec.rb

* Uses SQL paging to optimize scalibility and adds search functionality to index.html.erb
  - Use SQL paging in Admin::BadgeAchievements::Controller in #index and #award
  - Add a search by user ID to Badge Achievements index view
  - Add a limit of 15 badges to be shown on the Badge Achievement index view
  - Add a User ID column to the Badge Achievement index view

* Add Award Badge button back to Badge Achievement index.html.erb

* Change @badge to be more explicit and reword warning around badge deletion

* Adds award badge button back, rewords success message, and adjusts SQL paging
2020-08-25 11:14:47 -06:00

48 lines
2.3 KiB
Ruby

module Admin
class ApplicationController < ApplicationController
before_action :authorize_admin
after_action :verify_authorized
# This is used in app/views/admin/shared/_navbar.html.erb to build the
# side navbar in alphabetical order.
MENU_ITEMS = [
{ name: "articles", controller: "articles" },
{ name: "broadcasts", controller: "broadcasts" },
{ name: "badges", controller: "badges" },
{ name: "badge_achievements", controller: "badge_achievements" },
{ name: "chat_channels", controller: "chat_channels" },
{ name: "comments", controller: "comments" },
{ name: "config", controller: "config" },
{ name: "events", controller: "events" },
{ name: "growth", controller: "growth" },
{ name: "listings", controller: "listings" },
{ name: "moderator_actions", controller: "moderator_actions" },
{ name: "mods", controller: "mods" },
{ name: "privileged_reactions", controller: "privileged_reactions" },
{ name: "organizations", controller: "organizations" },
{ name: "pages", controller: "pages" },
{ name: "permissions", controller: "permissions" },
{ name: "podcasts", controller: "podcasts" },
{ name: "profile setup", controller: "profile_fields" },
{ name: "reports", controller: "reports" },
{ name: "response_templates", controller: "response_templates" },
{ name: "sponsorships", controller: "sponsorships" },
{ name: "tags", controller: "tags" },
{ name: "tools", controller: "tools" },
{ name: "users", controller: "users" },
{ name: "vault secrets", controller: "secrets" },
{ name: "webhooks", controller: "webhook_endpoints" },
{ name: "welcome", controller: "welcome" },
].sort_by { |menu_item| menu_item[:name] }.freeze
private
def authorization_resource
self.class.name.demodulize.sub("Controller", "").singularize.constantize
end
def authorize_admin
authorize(authorization_resource, :access?, policy_class: InternalPolicy)
end
end
end