tag subscriptions
This commit is contained in:
@@ -3,7 +3,7 @@ class ArtistVersionsController < ApplicationController
|
||||
|
||||
def index
|
||||
@search = ArtistVersion.search(params[:search])
|
||||
@artist_versions = @search.paginate :order => "id desc", :per_page => 25, :page => params[:page]
|
||||
@artist_versions = @search.paginate :page => params[:page]
|
||||
respond_with(@artist_versions)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -38,10 +38,10 @@ class DmailsController < ApplicationController
|
||||
redirect_to dmails_path, :notice => "Message destroyed"
|
||||
end
|
||||
|
||||
private
|
||||
def check_privilege(dmail)
|
||||
if !dmail.visible_to?(CurrentUser.user)
|
||||
raise User::PrivilegeError
|
||||
end
|
||||
private
|
||||
def check_privilege(dmail)
|
||||
if !dmail.visible_to?(CurrentUser.user)
|
||||
raise User::PrivilegeError
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,22 +1,46 @@
|
||||
class TagSubscriptionsController < ApplicationController
|
||||
before_filter :member_only, :only => [:new, :edit, :create, :update, :destroy]
|
||||
respond_to :html, :xml, :json
|
||||
rescue_from User::PrivilegeError, :with => "static/access_denied"
|
||||
|
||||
def new
|
||||
@tag_subscription = TagSubscription.new
|
||||
respond_with(@tag_subscription)
|
||||
end
|
||||
|
||||
def edit
|
||||
@tag_subscription = TagSubscription.find(params[:id])
|
||||
check_privilege(@tag_subscription)
|
||||
respond_with(@tag_subscription)
|
||||
end
|
||||
|
||||
def index
|
||||
end
|
||||
|
||||
def show
|
||||
@search = TagSubscription.search(params[:search]).visible
|
||||
@tag_subscriptions = @search.paginate(:page => params[:page])
|
||||
respond_with(@tag_subscriptions)
|
||||
end
|
||||
|
||||
def create
|
||||
@tag_subscription = TagSubscription.create(params[:tag_subscription])
|
||||
respond_with(@tag_subscription)
|
||||
end
|
||||
|
||||
def update
|
||||
@tag_subscription = TagSubscription.find(params[:id])
|
||||
check_privilege(@tag_subscription)
|
||||
@tag_subscription.update_attributes(params[:tag_subscription])
|
||||
respond_with(@tag_subscription)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@tag_subscription = TagSubscription.find(params[:id])
|
||||
check_privilege(@tag_subscription)
|
||||
@tag_subscription.destroy
|
||||
respond_with(@tag_subscription)
|
||||
end
|
||||
|
||||
private
|
||||
def check_privilege(tag_subscription)
|
||||
raise User::PrivilegeError unless (tag_subscription.owner_id == CurrentUser.id || CurrentUser.is_moderator?)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,14 +1,19 @@
|
||||
class TagSubscription < ActiveRecord::Base
|
||||
belongs_to :owner, :class_name => "User"
|
||||
before_create :initialize_post_ids
|
||||
before_validation :initialize_owner, :on => :create
|
||||
before_validation :initialize_post_ids, :on => :create
|
||||
before_save :normalize_name
|
||||
before_save :limit_tag_count
|
||||
scope :visible, :conditions => "is_visible_on_profile = TRUE"
|
||||
scope :visible, lambda {where("is_public = TRUE OR owner_id = ? OR ?", CurrentUser.id, CurrentUser.is_moderator?)}
|
||||
attr_accessible :name, :tag_query, :post_ids, :is_visible_on_profile
|
||||
|
||||
def normalize_name
|
||||
self.name = name.gsub(/\W/, "_")
|
||||
end
|
||||
|
||||
def initialize_owner
|
||||
self.owner_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def initialize_post_ids
|
||||
process
|
||||
@@ -39,6 +44,7 @@ class TagSubscription < ActiveRecord::Base
|
||||
end
|
||||
|
||||
user = User.find_by_name(user_name)
|
||||
|
||||
if user
|
||||
relation = where(["owner_id = ?", user.id])
|
||||
|
||||
@@ -63,11 +69,11 @@ class TagSubscription < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.find_posts(user_id, name = nil, limit = Danbooru.config.tag_subscription_post_limit)
|
||||
Post.where(["id in (?)", find_post_ids(user_id, name, limit)]).all(:order => "id DESC", :limit => limit)
|
||||
Post.where(["id in (?)", find_post_ids(user_id, name, limit)]).order("id DESC").limit(limit)
|
||||
end
|
||||
|
||||
def self.process_all
|
||||
all.each do |tag_subscription|
|
||||
find_each do |tag_subscription|
|
||||
if $job_task_daemon_active != false && tag_subscription.owner.is_privileged?
|
||||
begin
|
||||
tag_subscription.process
|
||||
|
||||
@@ -22,6 +22,7 @@ class User < ActiveRecord::Base
|
||||
before_create :normalize_level
|
||||
has_many :feedback, :class_name => "UserFeedback", :dependent => :destroy
|
||||
has_one :ban
|
||||
has_many :subscriptions, :class_name => "TagSubscription"
|
||||
belongs_to :inviter, :class_name => "User"
|
||||
scope :named, lambda {|name| where(["lower(name) = ?", name])}
|
||||
scope :admins, where("is_admin = TRUE")
|
||||
|
||||
Reference in New Issue
Block a user