Allow searching for subscriptions from other users (public only)
Related to #1323
This commit is contained in:
@@ -15,8 +15,8 @@ class TagSubscriptionsController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@user = CurrentUser.user
|
@user = CurrentUser.user
|
||||||
@search = TagSubscription.owned_by(@user).order("name").search(params[:search])
|
@query = TagSubscription.order("name").search(params[:search])
|
||||||
@tag_subscriptions = @search.paginate(params[:page], :limit => params[:limit])
|
@tag_subscriptions = @query.paginate(params[:page], :limit => params[:limit])
|
||||||
respond_with(@tag_subscriptions)
|
respond_with(@tag_subscriptions)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -66,28 +66,34 @@ class TagSubscription < ActiveRecord::Base
|
|||||||
post_ids.split(/,/)
|
post_ids.split(/,/)
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.search(params)
|
module SearchMethods
|
||||||
q = scoped
|
def visible_to(user)
|
||||||
return q if params.blank?
|
where("(is_public = TRUE OR creator_id = ? OR ?)", user.id, user.is_moderator?)
|
||||||
|
|
||||||
if params[:creator_id]
|
|
||||||
q = q.where("creator_id = ?", params[:creator_id].to_i)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if params[:creator_name]
|
def owned_by(user)
|
||||||
q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].mb_chars.downcase.strip.tr(" ", "_"))
|
where("creator_id = ?", user.id)
|
||||||
end
|
end
|
||||||
|
|
||||||
q
|
def search(params)
|
||||||
|
q = scoped
|
||||||
|
params = {} if params.blank?
|
||||||
|
|
||||||
|
if params[:creator_id]
|
||||||
|
q = q.where("creator_id = ?", params[:creator_id].to_i)
|
||||||
|
elsif params[:creator_name]
|
||||||
|
q = q.where("creator_id = (select _.id from users _ where lower(_.name) = ?)", params[:creator_name].mb_chars.downcase.strip.tr(" ", "_"))
|
||||||
|
else
|
||||||
|
q = q.where("creator_id = ?", CurrentUser.user.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
q = q.visible_to(CurrentUser.user)
|
||||||
|
|
||||||
|
q
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def self.visible_to(user)
|
extend SearchMethods
|
||||||
where("(is_public = TRUE OR creator_id = ? OR ?)", user.id, user.is_moderator?)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.owned_by(user)
|
|
||||||
where("creator_id = ?", user.id)
|
|
||||||
end
|
|
||||||
|
|
||||||
def self.find_tags(subscription_name)
|
def self.find_tags(subscription_name)
|
||||||
if subscription_name =~ /^(.+?):(.+)$/
|
if subscription_name =~ /^(.+?):(.+)$/
|
||||||
|
|||||||
Reference in New Issue
Block a user