class MonitorshipsController < ApplicationController @@hubssolib_permissions = HubSsoLib::Permissions.new({ :new => [ :admin, :webmaster, :privileged, :normal ], :create => [ :admin, :webmaster, :privileged, :normal ], :edit => [ :admin, :webmaster, :privileged, :normal ], :update => [ :admin, :webmaster, :privileged, :normal ], :destroy => [ :admin, :webmaster, :privileged, :normal ], }) def MonitorshipsController.hubssolib_permissions @@hubssolib_permissions end def create @monitorship = Monitorship.find_or_initialize_by_user_id_and_topic_id(current_user.id, params[:topic_id]) @monitorship.update_attribute :active, true respond_to do |format| format.html { redirect_to topic_path(params[:forum_id], params[:topic_id]) } format.js end end def destroy # Beast HEAD does the following, but this leaks monitorships into # the database indefinitely, merely setting "active = t" or "f" # flags everywhere. The Posts controller just checks for the row # entries that match post and user ID, but not the active flag. # To make life simpler, just delete Monitorship entries that match # the given details. # Monitorship.update_all ['active = ?', false], ['user_id = ? and topic_id = ?', current_user.id, params[:topic_id]] monitorship = Monitorship.find_by_user_id_and_topic_id(current_user.id, params[:topic_id]) monitorship.destroy() if monitorship respond_to do |format| format.html { redirect_to topic_path(params[:forum_id], params[:topic_id]) } format.js end end end