forked from e621ng/e621ng
added approval step for aliases/implications
This commit is contained in:
parent
34ae712be0
commit
f94b65f5d5
@ -1,5 +1,6 @@
|
|||||||
class TagAliasesController < ApplicationController
|
class TagAliasesController < ApplicationController
|
||||||
before_filter :admin_only, :only => [:new, :create, :destroy]
|
before_filter :admin_only, :only => [:approve, :destroy]
|
||||||
|
before_filter :member_only, :only => [:create]
|
||||||
respond_to :html, :xml, :json, :js
|
respond_to :html, :xml, :json, :js
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@ -9,13 +10,12 @@ class TagAliasesController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@search = TagAlias.search(params[:search])
|
@search = TagAlias.search(params[:search])
|
||||||
@tag_aliases = @search.paginate(params[:page])
|
@tag_aliases = @search.order("(case status when 'pending' then 0 when 'queued' then 1 else 2 end), antecedent_name, consequent_name").paginate(params[:page])
|
||||||
respond_with(@tag_aliases)
|
respond_with(@tag_aliases)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@tag_alias = TagAlias.create(params[:tag_alias])
|
@tag_alias = TagAlias.create(params[:tag_alias])
|
||||||
@tag_alias.delay.process!
|
|
||||||
respond_with(@tag_alias, :location => tag_aliases_path(:search => {:id_eq => @tag_alias.id}))
|
respond_with(@tag_alias, :location => tag_aliases_path(:search => {:id_eq => @tag_alias.id}))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -25,6 +25,13 @@ class TagAliasesController < ApplicationController
|
|||||||
respond_with(@tag_alias, :location => tag_aliases_path)
|
respond_with(@tag_alias, :location => tag_aliases_path)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def approve
|
||||||
|
@tag_alias = TagAlias.find(params[:id])
|
||||||
|
@tag_alias.update_column(:status, "queued")
|
||||||
|
@tag_alias.delay.process!
|
||||||
|
respond_with(@tag_alias, :location => tag_alias_path(@tag_alias))
|
||||||
|
end
|
||||||
|
|
||||||
def cache
|
def cache
|
||||||
@tag_alias = TagAlias.find(params[:id])
|
@tag_alias = TagAlias.find(params[:id])
|
||||||
@tag_alias.clear_cache
|
@tag_alias.clear_cache
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
class TagImplicationsController < ApplicationController
|
class TagImplicationsController < ApplicationController
|
||||||
before_filter :admin_only, :only => [:new, :create, :destroy]
|
before_filter :admin_only, :only => [:approve, :destroy]
|
||||||
|
before_filter :member_only, :only => [:create]
|
||||||
respond_to :html, :xml, :json, :js
|
respond_to :html, :xml, :json, :js
|
||||||
|
|
||||||
def new
|
def new
|
||||||
@ -9,13 +10,12 @@ class TagImplicationsController < ApplicationController
|
|||||||
|
|
||||||
def index
|
def index
|
||||||
@search = TagImplication.search(params[:search])
|
@search = TagImplication.search(params[:search])
|
||||||
@tag_implications = @search.paginate(params[:page])
|
@tag_implications = @search.order("(case status when 'pending' then 0 when 'queued' then 1 else 2 end), antecedent_name, consequent_name").paginate(params[:page])
|
||||||
respond_with(@tag_implicationes)
|
respond_with(@tag_implicationes)
|
||||||
end
|
end
|
||||||
|
|
||||||
def create
|
def create
|
||||||
@tag_implication = TagImplication.create(params[:tag_implication])
|
@tag_implication = TagImplication.create(params[:tag_implication])
|
||||||
@tag_implication.delay.process!
|
|
||||||
respond_with(@tag_implication, :location => tag_implications_path(:search => {:id_eq => @tag_implication.id}))
|
respond_with(@tag_implication, :location => tag_implications_path(:search => {:id_eq => @tag_implication.id}))
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -24,4 +24,11 @@ class TagImplicationsController < ApplicationController
|
|||||||
@tag_implication.destroy
|
@tag_implication.destroy
|
||||||
respond_with(@tag_implication)
|
respond_with(@tag_implication)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def approve
|
||||||
|
@tag_implication = TagImplication.find(params[:id])
|
||||||
|
@tag_implication.update_column(:status, "queued")
|
||||||
|
@tag_implication.delay.process!
|
||||||
|
respond_with(@tag_implication, :location => tag_implication_path(@tag_implication))
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
@ -11,7 +11,7 @@ class TagAlias < ActiveRecord::Base
|
|||||||
def self.to_aliased(names)
|
def self.to_aliased(names)
|
||||||
alias_hash = Cache.get_multi(names.flatten, "ta") do |name|
|
alias_hash = Cache.get_multi(names.flatten, "ta") do |name|
|
||||||
ta = TagAlias.find_by_antecedent_name(name)
|
ta = TagAlias.find_by_antecedent_name(name)
|
||||||
if ta
|
if ta && ta.is_active?
|
||||||
ta.consequent_name
|
ta.consequent_name
|
||||||
else
|
else
|
||||||
name
|
name
|
||||||
@ -29,6 +29,14 @@ class TagAlias < ActiveRecord::Base
|
|||||||
update_column(:status, "error: #{e}")
|
update_column(:status, "error: #{e}")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_pending?
|
||||||
|
status == "pending"
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_active?
|
||||||
|
status == "active"
|
||||||
|
end
|
||||||
|
|
||||||
def initialize_creator
|
def initialize_creator
|
||||||
self.creator_id = CurrentUser.user.id
|
self.creator_id = CurrentUser.user.id
|
||||||
self.creator_ip_addr = CurrentUser.ip_addr
|
self.creator_ip_addr = CurrentUser.ip_addr
|
||||||
|
@ -13,7 +13,7 @@ class TagImplication < ActiveRecord::Base
|
|||||||
module ClassMethods
|
module ClassMethods
|
||||||
# assumes names are normalized
|
# assumes names are normalized
|
||||||
def with_descendants(names)
|
def with_descendants(names)
|
||||||
(names + where("antecedent_name in (?)", names).map(&:descendant_names_array)).flatten.uniq
|
(names + where("antecedent_name in (?) and status = ?", names, "active").map(&:descendant_names_array)).flatten.uniq
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -24,7 +24,7 @@ class TagImplication < ActiveRecord::Base
|
|||||||
|
|
||||||
until children.empty?
|
until children.empty?
|
||||||
all.concat(children)
|
all.concat(children)
|
||||||
children = self.class.where(["antecedent_name IN (?)", children]).all.map(&:consequent_name)
|
children = self.class.where(["antecedent_name IN (?) and status = ?", children, "active"]).all.map(&:consequent_name)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -103,6 +103,14 @@ class TagImplication < ActiveRecord::Base
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def is_pending?
|
||||||
|
status == "pending"
|
||||||
|
end
|
||||||
|
|
||||||
|
def is_active?
|
||||||
|
status == "active"
|
||||||
|
end
|
||||||
|
|
||||||
def reload(options = {})
|
def reload(options = {})
|
||||||
super
|
super
|
||||||
clear_parent_cache
|
clear_parent_cache
|
||||||
|
1
app/views/tag_aliases/approve.js.erb
Normal file
1
app/views/tag_aliases/approve.js.erb
Normal file
@ -0,0 +1 @@
|
|||||||
|
$("#tag-alias-status-for-<%= @tag_alias.id %>").html("queued");
|
@ -11,10 +11,11 @@
|
|||||||
<table width="100%" class="striped">
|
<table width="100%" class="striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th width="20%">From</th>
|
<th width="30%">From</th>
|
||||||
<th width="20%">To</th>
|
<th width="30%">To</th>
|
||||||
<th width="20%">Reference</th>
|
<th width="10%">Reference</th>
|
||||||
<th width="40%"></th>
|
<th width="10%">Status</th>
|
||||||
|
<th width="20%"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -27,9 +28,16 @@
|
|||||||
<%= link_to tag_alias.forum_topic_id, forum_topic_path(tag_alias.forum_topic_id) %>
|
<%= link_to tag_alias.forum_topic_id, forum_topic_path(tag_alias.forum_topic_id) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
|
<td id="tag-alias-status-for-<%= tag_alias.id %>">
|
||||||
|
<%= tag_alias.status %>
|
||||||
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<% if CurrentUser.is_admin? %>
|
<% if CurrentUser.is_admin? %>
|
||||||
<%= link_to "Delete", tag_alias_path(tag_alias), :remote => true, :method => :delete, :confirm => "Are you sure you want to delete this alias?" %>
|
<%= link_to "Delete", tag_alias_path(tag_alias), :remote => true, :method => :delete, :confirm => "Are you sure you want to delete this alias?" %>
|
||||||
|
|
||||||
|
<% if tag_alias.is_pending? %>
|
||||||
|
| <%= link_to "Approve", approve_tag_alias_path(tag_alias), :remote => true, :method => :post %>
|
||||||
|
<% end %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
|
1
app/views/tag_implications/approve.js.erb
Normal file
1
app/views/tag_implications/approve.js.erb
Normal file
@ -0,0 +1 @@
|
|||||||
|
$("#tag-implication-status-for-<%= @tag_implication.id %>").html("queued");
|
@ -11,10 +11,11 @@
|
|||||||
<table width="100%" class="striped">
|
<table width="100%" class="striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th width="20%">From</th>
|
<th width="30%">From</th>
|
||||||
<th width="20%">To</th>
|
<th width="30%">To</th>
|
||||||
<th width="20%">Reference</th>
|
<th width="10%">Reference</th>
|
||||||
<th width="40%"></th>
|
<th width="10%">Status</th>
|
||||||
|
<th width="15%"></th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
@ -27,10 +28,15 @@
|
|||||||
<%= link_to tag_implication.forum_topic_id, forum_topic_path(tag_implication.forum_topic_id) %>
|
<%= link_to tag_implication.forum_topic_id, forum_topic_path(tag_implication.forum_topic_id) %>
|
||||||
<% end %>
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
|
<td id="tag-implication-status-for-<%= tag_implication.id %>"><%= tag_implication.status %></td>
|
||||||
<td>
|
<td>
|
||||||
<% if CurrentUser.is_admin? %>
|
<% if CurrentUser.is_admin? %>
|
||||||
<%= link_to "Delete", tag_implication_path(tag_implication), :remote => true, :method => :delete, :confirm => "Are you sure you want to delete this implication?" %>
|
<%= link_to "Delete", tag_implication_path(tag_implication), :remote => true, :method => :delete, :confirm => "Are you sure you want to delete this implication?" %>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
|
||||||
|
<% if tag_implication.is_pending? %>
|
||||||
|
| <%= link_to "Approve", approve_tag_implication_path(tag_implication), :remote => true, :method => :post %>
|
||||||
|
<% end %>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<% end %>
|
<% end %>
|
||||||
|
@ -121,9 +121,14 @@ Danbooru::Application.routes.draw do
|
|||||||
resources :tag_aliases do
|
resources :tag_aliases do
|
||||||
member do
|
member do
|
||||||
delete :cache
|
delete :cache
|
||||||
|
post :approve
|
||||||
|
end
|
||||||
|
end
|
||||||
|
resources :tag_implications do
|
||||||
|
member do
|
||||||
|
post :approve
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
resources :tag_implications
|
|
||||||
resources :tag_subscriptions do
|
resources :tag_subscriptions do
|
||||||
member do
|
member do
|
||||||
get :posts
|
get :posts
|
||||||
|
BIN
tmp/alpha.png
Normal file
BIN
tmp/alpha.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
tmp/test-large.jpg
Normal file
BIN
tmp/test-large.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 89 KiB |
Loading…
Reference in New Issue
Block a user