diff --git a/app/controllers/tag_aliases_controller.rb b/app/controllers/tag_aliases_controller.rb index 7e9f6df95..8d4edee17 100644 --- a/app/controllers/tag_aliases_controller.rb +++ b/app/controllers/tag_aliases_controller.rb @@ -1,5 +1,6 @@ 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 def new @@ -9,13 +10,12 @@ class TagAliasesController < ApplicationController def index @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) end def create @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})) end @@ -25,6 +25,13 @@ class TagAliasesController < ApplicationController respond_with(@tag_alias, :location => tag_aliases_path) 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 @tag_alias = TagAlias.find(params[:id]) @tag_alias.clear_cache diff --git a/app/controllers/tag_implications_controller.rb b/app/controllers/tag_implications_controller.rb index 36f829baf..882e19945 100644 --- a/app/controllers/tag_implications_controller.rb +++ b/app/controllers/tag_implications_controller.rb @@ -1,5 +1,6 @@ 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 def new @@ -9,13 +10,12 @@ class TagImplicationsController < ApplicationController def index @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) end def create @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})) end @@ -24,4 +24,11 @@ class TagImplicationsController < ApplicationController @tag_implication.destroy respond_with(@tag_implication) 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 diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index 786c87951..0b6ca57a4 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -11,7 +11,7 @@ class TagAlias < ActiveRecord::Base def self.to_aliased(names) alias_hash = Cache.get_multi(names.flatten, "ta") do |name| ta = TagAlias.find_by_antecedent_name(name) - if ta + if ta && ta.is_active? ta.consequent_name else name @@ -29,6 +29,14 @@ class TagAlias < ActiveRecord::Base update_column(:status, "error: #{e}") end + def is_pending? + status == "pending" + end + + def is_active? + status == "active" + end + def initialize_creator self.creator_id = CurrentUser.user.id self.creator_ip_addr = CurrentUser.ip_addr diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index e0a497f87..06c56ebff 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -13,7 +13,7 @@ class TagImplication < ActiveRecord::Base module ClassMethods # assumes names are normalized 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 @@ -24,7 +24,7 @@ class TagImplication < ActiveRecord::Base until children.empty? 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 @@ -103,6 +103,14 @@ class TagImplication < ActiveRecord::Base end end + def is_pending? + status == "pending" + end + + def is_active? + status == "active" + end + def reload(options = {}) super clear_parent_cache diff --git a/app/views/tag_aliases/approve.js.erb b/app/views/tag_aliases/approve.js.erb new file mode 100644 index 000000000..5fc44ba7f --- /dev/null +++ b/app/views/tag_aliases/approve.js.erb @@ -0,0 +1 @@ +$("#tag-alias-status-for-<%= @tag_alias.id %>").html("queued"); \ No newline at end of file diff --git a/app/views/tag_aliases/index.html.erb b/app/views/tag_aliases/index.html.erb index 9bfce28a7..5b0cb8d07 100644 --- a/app/views/tag_aliases/index.html.erb +++ b/app/views/tag_aliases/index.html.erb @@ -11,10 +11,11 @@ - - - - + + + + + @@ -27,9 +28,16 @@ <%= link_to tag_alias.forum_topic_id, forum_topic_path(tag_alias.forum_topic_id) %> <% end %> + diff --git a/app/views/tag_implications/approve.js.erb b/app/views/tag_implications/approve.js.erb new file mode 100644 index 000000000..f51bfb638 --- /dev/null +++ b/app/views/tag_implications/approve.js.erb @@ -0,0 +1 @@ +$("#tag-implication-status-for-<%= @tag_implication.id %>").html("queued"); \ No newline at end of file diff --git a/app/views/tag_implications/index.html.erb b/app/views/tag_implications/index.html.erb index 6df6b8c8b..29685f7bd 100644 --- a/app/views/tag_implications/index.html.erb +++ b/app/views/tag_implications/index.html.erb @@ -11,10 +11,11 @@
FromToReferenceFromToReferenceStatus
+ <%= tag_alias.status %> + <% 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?" %> + + <% if tag_alias.is_pending? %> + | <%= link_to "Approve", approve_tag_alias_path(tag_alias), :remote => true, :method => :post %> + <% end %> <% end %>
- - - - + + + + + @@ -27,10 +28,15 @@ <%= link_to tag_implication.forum_topic_id, forum_topic_path(tag_implication.forum_topic_id) %> <% end %> + <% end %> diff --git a/config/routes.rb b/config/routes.rb index eb1f0a698..4926024b0 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -121,9 +121,14 @@ Danbooru::Application.routes.draw do resources :tag_aliases do member do delete :cache + post :approve + end + end + resources :tag_implications do + member do + post :approve end end - resources :tag_implications resources :tag_subscriptions do member do get :posts diff --git a/tmp/alpha.png b/tmp/alpha.png new file mode 100644 index 000000000..7fec549c9 Binary files /dev/null and b/tmp/alpha.png differ diff --git a/tmp/test-large.jpg b/tmp/test-large.jpg new file mode 100644 index 000000000..c27382e5f Binary files /dev/null and b/tmp/test-large.jpg differ
FromToReferenceFromToReferenceStatus
<%= tag_implication.status %> <% 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?" %> <% end %> + + <% if tag_implication.is_pending? %> + | <%= link_to "Approve", approve_tag_implication_path(tag_implication), :remote => true, :method => :post %> + <% end %>