allow editing of pending aliases/implications
This commit is contained in:
@@ -12,6 +12,20 @@ class TagAliasesController < ApplicationController
|
||||
respond_with(@tag_alias)
|
||||
end
|
||||
|
||||
def edit
|
||||
@tag_alias = TagAlias.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@tag_alias = TagAlias.find(params[:id])
|
||||
|
||||
if @tag_alias.is_pending? && @tag_alias.editable_by?(CurrentUser.user)
|
||||
@tag_alias.update_attributes(params[:tag_alias])
|
||||
end
|
||||
|
||||
respond_with(@tag_alias)
|
||||
end
|
||||
|
||||
def index
|
||||
@search = TagAlias.search(params[:search])
|
||||
@tag_aliases = @search.order("(case status when 'pending' then 0 when 'queued' then 1 else 2 end), antecedent_name, consequent_name").paginate(params[:page], :limit => params[:limit])
|
||||
|
||||
@@ -12,6 +12,20 @@ class TagImplicationsController < ApplicationController
|
||||
respond_with(@tag_implication)
|
||||
end
|
||||
|
||||
def edit
|
||||
@tag_implication = TagImplication.find(params[:id])
|
||||
end
|
||||
|
||||
def update
|
||||
@tag_implication = TagImplication.find(params[:id])
|
||||
|
||||
if @tag_implication.is_pending? && @tag_implication.editable_by?(CurrentUser.user)
|
||||
@tag_implication.update_attributes(params[:tag_implication])
|
||||
end
|
||||
|
||||
respond_with(@tag_implication)
|
||||
end
|
||||
|
||||
def index
|
||||
@search = TagImplication.search(params[:search])
|
||||
@tag_implications = @search.order("(case status when 'pending' then 0 when 'queued' then 1 else 2 end), antecedent_name, consequent_name").paginate(params[:page], :limit => params[:limit])
|
||||
|
||||
@@ -222,4 +222,8 @@ class TagAlias < ActiveRecord::Base
|
||||
return true if is_pending? && user.id == creator_id
|
||||
return false
|
||||
end
|
||||
|
||||
def editable_by?(user)
|
||||
deletable_by?(user)
|
||||
end
|
||||
end
|
||||
|
||||
@@ -211,4 +211,8 @@ class TagImplication < ActiveRecord::Base
|
||||
return true if is_pending? && user.id == creator_id
|
||||
return false
|
||||
end
|
||||
|
||||
def editable_by?(user)
|
||||
deletable_by?(user)
|
||||
end
|
||||
end
|
||||
|
||||
20
app/views/tag_aliases/edit.html.erb
Normal file
20
app/views/tag_aliases/edit.html.erb
Normal file
@@ -0,0 +1,20 @@
|
||||
<div id="c-tag-aliases">
|
||||
<div id="a-new">
|
||||
<h1>Edit Tag Alias</h1>
|
||||
|
||||
<%= error_messages_for :tag_alias %>
|
||||
|
||||
<%= simple_form_for(@tag_alias) do |f| %>
|
||||
<%= f.input :antecedent_name, :as => :string, :label => "From" %>
|
||||
<%= f.input :consequent_name, :label => "To" %>
|
||||
<%= f.input :forum_topic_id, :label => "Forum" %>
|
||||
<%= f.button :submit %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
Edit Tag Alias - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
||||
@@ -32,6 +32,11 @@
|
||||
</td>
|
||||
<td>
|
||||
<%= link_to "Show", tag_alias_path(tag_alias) %>
|
||||
|
||||
<% if tag_alias.editable_by?(CurrentUser.user) %>
|
||||
| <%= link_to "Edit", edit_tag_alias_path(tag_alias) %>
|
||||
<% end %>
|
||||
|
||||
<% if tag_alias.deletable_by?(CurrentUser.user) %>
|
||||
| <%= link_to "Delete", tag_alias_path(tag_alias), :remote => true, :method => :delete, :data => {:confirm => "Are you sure you want to delete this alias?"} %>
|
||||
<% end %>
|
||||
|
||||
20
app/views/tag_implications/edit.html.erb
Normal file
20
app/views/tag_implications/edit.html.erb
Normal file
@@ -0,0 +1,20 @@
|
||||
<div id="c-tag-aliases">
|
||||
<div id="a-new">
|
||||
<h1>Edit Tag Implication</h1>
|
||||
|
||||
<%= error_messages_for :tag_implication %>
|
||||
|
||||
<%= simple_form_for(@tag_implication) do |f| %>
|
||||
<%= f.input :antecedent_name, :label => "From" %>
|
||||
<%= f.input :consequent_name, :label => "To" %>
|
||||
<%= f.input :forum_topic_id, :label => "Forum" %>
|
||||
<%= f.button :submit %>
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<%= render "secondary_links" %>
|
||||
|
||||
<% content_for(:page_title) do %>
|
||||
Edit Tag Implication - <%= Danbooru.config.app_name %>
|
||||
<% end %>
|
||||
@@ -30,9 +30,15 @@
|
||||
<td id="tag-implication-status-for-<%= tag_implication.id %>"><%= tag_implication.status %></td>
|
||||
<td>
|
||||
<%= link_to "Show", tag_implication_path(tag_implication) %>
|
||||
|
||||
<% if tag_implication.editable_by?(CurrentUser.user) %>
|
||||
| <%= link_to "Edit", edit_tag_implication_path(tag_implication) %>
|
||||
<% end %>
|
||||
|
||||
<% if tag_implication.deletable_by?(CurrentUser.user) %>
|
||||
| <%= link_to "Delete", tag_implication_path(tag_implication), :remote => true, :method => :delete, :data => {:confirm => "Are you sure you want to delete this implication?"} %>
|
||||
<% end %>
|
||||
|
||||
<% if CurrentUser.user.is_admin? && tag_implication.is_pending? %>
|
||||
| <%= link_to "Approve", approve_tag_implication_path(tag_implication), :remote => true, :method => :post %>
|
||||
<% end %>
|
||||
|
||||
@@ -210,7 +210,7 @@ Rails.application.routes.draw do
|
||||
resource :correction, :only => [:new, :create, :show], :controller => "tag_corrections"
|
||||
end
|
||||
resources :tag_aliases do
|
||||
resource :correction, :only => [:create, :new, :show], :controller => "tag_alias_corrections"
|
||||
resource :correction, :controller => "tag_alias_corrections"
|
||||
member do
|
||||
post :approve
|
||||
end
|
||||
|
||||
@@ -15,17 +15,58 @@ class TagAliasesControllerTest < ActionController::TestCase
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
context "edit action" do
|
||||
setup do
|
||||
@tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
|
||||
should "render" do
|
||||
get :edit, {:id => @tag_alias.id}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "update action" do
|
||||
setup do
|
||||
@tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
|
||||
context "for a pending alias" do
|
||||
setup do
|
||||
@tag_alias.update_attribute(:status, "pending")
|
||||
end
|
||||
|
||||
should "succeed" do
|
||||
post :update, {:id => @tag_alias.id, :tag_alias => {:antecedent_name => "xxx"}}, {:user_id => @user.id}
|
||||
@tag_alias.reload
|
||||
assert_equal("xxx", @tag_alias.antecedent_name)
|
||||
end
|
||||
end
|
||||
|
||||
context "for an approved alias" do
|
||||
setup do
|
||||
@tag_alias.update_attribute(:status, "approved")
|
||||
end
|
||||
|
||||
should "fail" do
|
||||
post :update, {:id => @tag_alias.id, :tag_alias => {:antecedent_name => "xxx"}}, {:user_id => @user.id}
|
||||
@tag_alias.reload
|
||||
assert_equal("aaa", @tag_alias.antecedent_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
@tag_alias = FactoryGirl.create(:tag_alias, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
|
||||
should "list all tag aliass" do
|
||||
should "list all tag alias" do
|
||||
get :index, {}, {:user_id => @user.id}
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
should "list all tag_aliass (with search)" do
|
||||
should "list all tag_alias (with search)" do
|
||||
get :index, {:search => {:antecedent_name => "aaa"}}, {:user_id => @user.id}
|
||||
assert_response :success
|
||||
end
|
||||
|
||||
@@ -15,6 +15,48 @@ class TagImplicationsControllerTest < ActionController::TestCase
|
||||
CurrentUser.ip_addr = nil
|
||||
end
|
||||
|
||||
|
||||
context "edit action" do
|
||||
setup do
|
||||
@tag_implication = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
|
||||
should "render" do
|
||||
get :edit, {:id => @tag_implication.id}
|
||||
assert_response :success
|
||||
end
|
||||
end
|
||||
|
||||
context "update action" do
|
||||
setup do
|
||||
@tag_implication = FactoryGirl.create(:tag_implication, :antecedent_name => "aaa", :consequent_name => "bbb")
|
||||
end
|
||||
|
||||
context "for a pending implication" do
|
||||
setup do
|
||||
@tag_implication.update_attribute(:status, "pending")
|
||||
end
|
||||
|
||||
should "succeed" do
|
||||
post :update, {:id => @tag_implication.id, :tag_implication => {:antecedent_name => "xxx"}}, {:user_id => @user.id}
|
||||
@tag_implication.reload
|
||||
assert_equal("xxx", @tag_implication.antecedent_name)
|
||||
end
|
||||
end
|
||||
|
||||
context "for an approved implication" do
|
||||
setup do
|
||||
@tag_implication.update_attribute(:status, "approved")
|
||||
end
|
||||
|
||||
should "fail" do
|
||||
post :update, {:id => @tag_implication.id, :tag_implication => {:antecedent_name => "xxx"}}, {:user_id => @user.id}
|
||||
@tag_implication.reload
|
||||
assert_equal("aaa", @tag_implication.antecedent_name)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context "index action" do
|
||||
setup do
|
||||
CurrentUser.scoped(@user, "127.0.0.1") do
|
||||
|
||||
Reference in New Issue
Block a user