Add a Restricted user level. Restricted users are level 10, below Members. New users start out as Restricted if they sign up from a proxy or an IP recently used by another user. Restricted users can't update or edit any public content on the site until they verify their email address, at which point they're promoted to Member. Restricted users are only allowed to do personal actions like keep favorites, keep favgroups and saved searches, mark dmails as read or deleted, or mark forum posts as read. The restricted state already existed before, the only change here is that now it's an actual user level instead of a hidden state. Before it was based on two hidden flags on the user, the `requires_verification` flag (set when a user signs up from a proxy, etc), and the `is_verified` flag (set after the user verifies their email). Making it a user level means that now the Restricted status will be shown publicly. Introducing a new level below Member means that we have to change every `is_member?` check to `!is_anonymous` for every place where we used `is_member?` to check that the current user is logged in.
44 lines
1.2 KiB
Ruby
44 lines
1.2 KiB
Ruby
class FavoritesController < ApplicationController
|
|
respond_to :html, :xml, :json, :js
|
|
skip_before_action :api_check
|
|
rescue_with Favorite::Error, status: 422
|
|
|
|
def index
|
|
authorize Favorite
|
|
if !request.format.html?
|
|
@favorites = Favorite.visible(CurrentUser.user).paginated_search(params)
|
|
respond_with(@favorites)
|
|
elsif params[:user_id].present?
|
|
user = User.find(params[:user_id])
|
|
redirect_to posts_path(tags: "ordfav:#{user.name}", format: request.format.symbol)
|
|
elsif !CurrentUser.is_anonymous?
|
|
redirect_to posts_path(tags: "ordfav:#{CurrentUser.name}", format: request.format.symbol)
|
|
else
|
|
redirect_to posts_path(format: request.format.symbol)
|
|
end
|
|
end
|
|
|
|
def create
|
|
authorize Favorite
|
|
@post = Post.find(params[:post_id])
|
|
@post.add_favorite!(CurrentUser.user)
|
|
flash.now[:notice] = "You have favorited this post"
|
|
|
|
respond_with(@post)
|
|
end
|
|
|
|
def destroy
|
|
authorize Favorite
|
|
@post = Post.find_by_id(params[:id])
|
|
|
|
if @post
|
|
@post.remove_favorite!(CurrentUser.user)
|
|
else
|
|
Favorite.remove(post_id: params[:id], user: CurrentUser.user)
|
|
end
|
|
|
|
flash.now[:notice] = "You have unfavorited this post"
|
|
respond_with(@post)
|
|
end
|
|
end
|