diff --git a/app/controllers/tag_aliases_controller.rb b/app/controllers/tag_aliases_controller.rb index 96a55ff8f..49ddb9f0a 100644 --- a/app/controllers/tag_aliases_controller.rb +++ b/app/controllers/tag_aliases_controller.rb @@ -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]) diff --git a/app/controllers/tag_implications_controller.rb b/app/controllers/tag_implications_controller.rb index e441c040c..0d20a4485 100644 --- a/app/controllers/tag_implications_controller.rb +++ b/app/controllers/tag_implications_controller.rb @@ -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]) diff --git a/app/models/tag_alias.rb b/app/models/tag_alias.rb index fe6a17039..ad39069a6 100644 --- a/app/models/tag_alias.rb +++ b/app/models/tag_alias.rb @@ -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 diff --git a/app/models/tag_implication.rb b/app/models/tag_implication.rb index 951a0e26b..4672c77e0 100644 --- a/app/models/tag_implication.rb +++ b/app/models/tag_implication.rb @@ -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 diff --git a/app/views/tag_aliases/edit.html.erb b/app/views/tag_aliases/edit.html.erb new file mode 100644 index 000000000..1b708bd89 --- /dev/null +++ b/app/views/tag_aliases/edit.html.erb @@ -0,0 +1,20 @@ +
+
+

Edit Tag Alias

+ + <%= 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 %> +
+
+ +<%= render "secondary_links" %> + +<% content_for(:page_title) do %> + Edit Tag Alias - <%= Danbooru.config.app_name %> +<% end %> diff --git a/app/views/tag_aliases/index.html.erb b/app/views/tag_aliases/index.html.erb index 380cecdd2..60873b5af 100644 --- a/app/views/tag_aliases/index.html.erb +++ b/app/views/tag_aliases/index.html.erb @@ -32,6 +32,11 @@ <%= 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 %> diff --git a/app/views/tag_implications/edit.html.erb b/app/views/tag_implications/edit.html.erb new file mode 100644 index 000000000..97703f5a8 --- /dev/null +++ b/app/views/tag_implications/edit.html.erb @@ -0,0 +1,20 @@ +
+
+

Edit Tag Implication

+ + <%= 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 %> +
+
+ +<%= render "secondary_links" %> + +<% content_for(:page_title) do %> + Edit Tag Implication - <%= Danbooru.config.app_name %> +<% end %> diff --git a/app/views/tag_implications/index.html.erb b/app/views/tag_implications/index.html.erb index 84f96625d..cd0727b71 100644 --- a/app/views/tag_implications/index.html.erb +++ b/app/views/tag_implications/index.html.erb @@ -30,9 +30,15 @@ <%= tag_implication.status %> <%= 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 %> diff --git a/config/routes.rb b/config/routes.rb index 9d8c0b71b..10c61566b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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 diff --git a/test/functional/tag_aliases_controller_test.rb b/test/functional/tag_aliases_controller_test.rb index 148d329fa..c488220ce 100644 --- a/test/functional/tag_aliases_controller_test.rb +++ b/test/functional/tag_aliases_controller_test.rb @@ -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 diff --git a/test/functional/tag_implications_controller_test.rb b/test/functional/tag_implications_controller_test.rb index d41f1c793..15db44959 100644 --- a/test/functional/tag_implications_controller_test.rb +++ b/test/functional/tag_implications_controller_test.rb @@ -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