fixed tag subscription tests
This commit is contained in:
@@ -15,8 +15,9 @@ class TagSubscriptionsController < ApplicationController
|
||||
end
|
||||
|
||||
def index
|
||||
@search = TagSubscription.visible.search(params[:search])
|
||||
@tag_subscriptions = @search.paginate(:page => params[:page])
|
||||
@user = CurrentUser.user
|
||||
@search = TagSubscription.visible_to(@user).search(params[:search])
|
||||
@tag_subscriptions = @search.paginate(params[:page])
|
||||
respond_with(@tag_subscriptions)
|
||||
end
|
||||
|
||||
@@ -41,6 +42,6 @@ class TagSubscriptionsController < ApplicationController
|
||||
|
||||
private
|
||||
def check_privilege(tag_subscription)
|
||||
raise User::PrivilegeError unless (tag_subscription.owner_id == CurrentUser.id || CurrentUser.is_moderator?)
|
||||
raise User::PrivilegeError unless tag_subscription.editable_by?(CurrentUser.user)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -31,7 +31,11 @@ class CurrentUser
|
||||
end
|
||||
|
||||
def self.id
|
||||
user.id
|
||||
if user.nil?
|
||||
nil
|
||||
else
|
||||
user.id
|
||||
end
|
||||
end
|
||||
|
||||
def self.name
|
||||
|
||||
@@ -1,18 +1,18 @@
|
||||
class TagSubscription < ActiveRecord::Base
|
||||
belongs_to :owner, :class_name => "User"
|
||||
before_validation :initialize_owner, :on => :create
|
||||
belongs_to :creator, :class_name => "User"
|
||||
before_validation :initialize_creator, :on => :create
|
||||
before_validation :initialize_post_ids, :on => :create
|
||||
before_save :normalize_name
|
||||
before_save :limit_tag_count
|
||||
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
|
||||
validates_presence_of :name, :tag_query, :is_public, :creator_id
|
||||
|
||||
def normalize_name
|
||||
self.name = name.gsub(/\W/, "_")
|
||||
end
|
||||
|
||||
def initialize_owner
|
||||
self.owner_id = CurrentUser.id
|
||||
def initialize_creator
|
||||
self.creator_id = CurrentUser.id
|
||||
end
|
||||
|
||||
def initialize_post_ids
|
||||
@@ -33,6 +33,14 @@ class TagSubscription < ActiveRecord::Base
|
||||
end
|
||||
self.post_ids = post_ids.sort.reverse.slice(0, Danbooru.config.tag_subscription_post_limit).join(",")
|
||||
end
|
||||
|
||||
def editable_by?(user)
|
||||
user.is_moderator? || creator_id == user.id
|
||||
end
|
||||
|
||||
def self.visible_to(user)
|
||||
where("(is_public = TRUE OR creator_id = ? OR ?)", user.id, user.is_moderator?)
|
||||
end
|
||||
|
||||
def self.find_tags(subscription_name)
|
||||
if subscription_name =~ /^(.+?):(.+)$/
|
||||
@@ -46,7 +54,7 @@ class TagSubscription < ActiveRecord::Base
|
||||
user = User.find_by_name(user_name)
|
||||
|
||||
if user
|
||||
relation = where(["owner_id = ?", user.id])
|
||||
relation = where(["creator_id = ?", user.id])
|
||||
|
||||
if sub_group
|
||||
relation = relation.where(["name ILIKE ? ESCAPE E'\\\\'", sub_group.to_escaped_for_sql_like])
|
||||
@@ -59,7 +67,7 @@ class TagSubscription < ActiveRecord::Base
|
||||
end
|
||||
|
||||
def self.find_post_ids(user_id, name = nil, limit = Danbooru.config.tag_subscription_post_limit)
|
||||
relation = where(["owner_id = ?", user_id])
|
||||
relation = where(["creator_id = ?", user_id])
|
||||
|
||||
if name
|
||||
relation = relation.where(["name ILIKE ? ESCAPE E'\\\\'", name.to_escaped_for_sql_like])
|
||||
@@ -74,7 +82,7 @@ class TagSubscription < ActiveRecord::Base
|
||||
|
||||
def self.process_all
|
||||
find_each do |tag_subscription|
|
||||
if $job_task_daemon_active != false && tag_subscription.owner.is_privileged?
|
||||
if $job_task_daemon_active != false && tag_subscription.creator.is_privileged?
|
||||
begin
|
||||
tag_subscription.process
|
||||
tag_subscription.save
|
||||
|
||||
6
app/views/tag_subscriptions/_form.html.erb
Normal file
6
app/views/tag_subscriptions/_form.html.erb
Normal file
@@ -0,0 +1,6 @@
|
||||
<%= simple_form_for(@tag_subscription) do |f| %>
|
||||
<%= f.input :name %>
|
||||
<%= f.input :tag_query %>
|
||||
<%= f.input :is_public %>
|
||||
<%= f.button :submit %>
|
||||
<% end %>
|
||||
14
app/views/tag_subscriptions/_secondary_links.html.erb
Normal file
14
app/views/tag_subscriptions/_secondary_links.html.erb
Normal file
@@ -0,0 +1,14 @@
|
||||
<% content_for(:secondary_links) do %>
|
||||
<menu>
|
||||
<li><%= link_to "Listing", tag_subscriptions_path %></li>
|
||||
<li><%= link_to "New", new_tag_subscription_path %></li>
|
||||
<li><%= link_to "Help", wiki_pages_path(:title => "help:tag_subscriptions") %></li>
|
||||
|
||||
<% if @tag_subscription && !@tag_subscription.new_record? && @tag_subscription.editable_by?(CurrentUser.user) %>
|
||||
<li>|</li>
|
||||
<li><%= link_to "Show", tag_subscription_path(@tag_subscription) %></li>
|
||||
<li><%= link_to "Edit", edit_tag_subscription_path(@tag_subscription) %></li>
|
||||
<li><%= link_to "Delete", tag_subscription_path(@tag_subscription, :method => :delete, :confirm => "Are you sure you want to delete this tag subscription?") %></li>
|
||||
<% end %>
|
||||
</menu>
|
||||
<% end %>
|
||||
@@ -0,0 +1,6 @@
|
||||
<div id="c-tag-subscriptions">
|
||||
<div id="a-edit">
|
||||
<h1>Edit Tag Subscription</h1>
|
||||
<%= render "form" %>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,14 +1,25 @@
|
||||
<% form_tag(:action => "update") do %>
|
||||
<h4>Edit Tag Subscriptions</h4>
|
||||
<div style="margin-bottom: 1em;">
|
||||
You can only create up to <%= CONFIG["max_tag_subscriptions"] %> groups and each group can have up to 20 tags.
|
||||
<div id="c-tag-subscriptions">
|
||||
<div id="a-index">
|
||||
<h1>Tag Subscriptions</h1>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Creator</th>
|
||||
<th>Name</th>
|
||||
<th>Tag Query</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<% @tag_subscriptions.each do |tag_subscription| %>
|
||||
<tr>
|
||||
<td><%= tag_subscription.creator.name %></td>
|
||||
<td><%= link_to tag_subscription.name, tag_subscription_path(tag_subscription.id) %></td>
|
||||
<td><%= link_to tag_subscription.tag_query, posts_path(:tags => "sub:#{@user.name}:#{tag_subscription.name}") %></td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
<table width="100%" class="highlightable">
|
||||
<%= render :partial => "listing", :locals => {:tag_subscriptions => @tag_subscriptions} %>
|
||||
</table>
|
||||
<% end %>
|
||||
</div>
|
||||
|
||||
<% content_for("subnavbar") do %>
|
||||
<li><%= link_to "Help", :controller => "help", :action => "tag_subscriptions" %></li>
|
||||
<% end %>
|
||||
<%= render "secondary_links" %>
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
<div id="c-tag-subscriptions">
|
||||
<div id="a-new">
|
||||
<h1>New Tag Subscription</h1>
|
||||
<%= render "form" %>
|
||||
</div>
|
||||
</div>
|
||||
Reference in New Issue
Block a user