This commit is contained in:
albert
2013-03-10 16:31:39 -04:00
parent 1946fab809
commit e53d60d99b
22 changed files with 384 additions and 17 deletions

View File

@@ -1,10 +1,6 @@
class TagAliasCorrectionsController < ApplicationController
before_filter :moderator_only
def new
@correction = TagAliasCorrection.new(params[:tag_alias_id])
end
def create
@correction = TagAliasCorrection.new(params[:tag_alias_id])
@@ -13,7 +9,7 @@ class TagAliasCorrectionsController < ApplicationController
flash[:notice] = "The fix has been queued and will be processed"
end
redirect_to tag_alias_correction_path(:id => params[:tag_alias_id])
redirect_to tag_alias_correction_path(:tag_alias_id => params[:tag_alias_id])
end
def show

View File

@@ -0,0 +1,17 @@
class TagAliasRequestsController < ApplicationController
before_filter :member_only
rescue_from TagAliasRequest::ValidationError, :with => :rescue_exception
def new
end
def create
@tag_alias_request = TagAliasRequest.new(
params[:tag_alias_request][:antecedent_name],
params[:tag_alias_request][:consequent_name],
params[:tag_alias_request][:reason]
)
@tag_alias_request.create
redirect_to(forum_topic_path(@tag_alias_request.forum_topic))
end
end

View File

@@ -1,5 +1,5 @@
class TagAliasesController < ApplicationController
before_filter :admin_only, :only => [:approve, :destroy, :create]
before_filter :admin_only, :only => [:approve, :destroy, :new, :create]
respond_to :html, :xml, :json, :js
def new

View File

@@ -0,0 +1,17 @@
class TagImplicationRequestsController < ApplicationController
before_filter :member_only
rescue_from TagImplicationRequest::ValidationError, :with => :rescue_exception
def new
end
def create
@tag_implication_request = TagImplicationRequest.new(
params[:tag_implication_request][:antecedent_name],
params[:tag_implication_request][:consequent_name],
params[:tag_implication_request][:reason]
)
@tag_implication_request.create
redirect_to(forum_topic_path(@tag_implication_request.forum_topic))
end
end

View File

@@ -143,10 +143,10 @@ protected
when "moderator/dashboards"
/^\/moderator/
when "tag_aliases", "tag_alias_corrections"
when "tag_aliases", "tag_alias_corrections", "tag_alias_requests"
/^\/tag_aliases/
when "tag_implications"
when "tag_implications", "tag_implication_requests"
/^\/tag_implications/
when "wiki_pages", "wiki_page_versions"

View File

@@ -0,0 +1,39 @@
class TagAliasRequest
class ValidationError < Exception ; end
attr_reader :antecedent_name, :consequent_name, :reason, :tag_alias, :forum_topic
def initialize(antecedent_name, consequent_name, reason)
@antecedent_name = antecedent_name
@consequent_name = consequent_name
@reason = reason
end
def create
TagAlias.transaction do
create_alias
create_forum_topic
end
end
def create_alias
@tag_alias = TagAlias.create(:antecedent_name => antecedent_name, :consequent_name => consequent_name, :status => "pending")
if @tag_alias.errors.any?
raise ValidationError.new(@tag_alias.errors.full_messages.join("; "))
end
end
def create_forum_topic
@forum_topic = ForumTopic.create(
:title => "Tag alias: #{antecedent_name} -> #{consequent_name}",
:original_post_attributes => {
:body => reason + "\n\n\"Link to alias\":/tag_aliases?search[id]=#{tag_alias.id}"
}
)
if @forum_topic.errors.any?
raise ValidationError.new(@forum_topic.errors.full_messages.join("; "))
end
tag_alias.update_attribute(:forum_topic_id, @forum_topic.id)
end
end

View File

@@ -0,0 +1,39 @@
class TagImplicationRequest
class ValidationError < Exception ; end
attr_reader :antecedent_name, :consequent_name, :reason, :tag_implication, :forum_topic
def initialize(antecedent_name, consequent_name, reason)
@antecedent_name = antecedent_name
@consequent_name = consequent_name
@reason = reason
end
def create
TagImplication.transaction do
create_implication
create_forum_topic
end
end
def create_implication
@tag_implication = TagImplication.create(:antecedent_name => antecedent_name, :consequent_name => consequent_name, :status => "pending")
if @tag_implication.errors.any?
raise ValidationError.new(@tag_implication.errors.full_messages.join("; "))
end
end
def create_forum_topic
@forum_topic = ForumTopic.create(
:title => "Tag implication: #{antecedent_name} -> #{consequent_name}",
:original_post_attributes => {
:body => reason + "\n\n\"Link to implication\":/tag_implications?search[id]=#{tag_implication.id}"
}
)
if @forum_topic.errors.any?
raise ValidationError.new(@forum_topic.errors.full_messages.join("; "))
end
tag_implication.update_attribute(:forum_topic_id, @forum_topic.id)
end
end

View File

@@ -4,10 +4,11 @@ class TagAlias < ActiveRecord::Base
after_save :ensure_category_consistency
after_destroy :clear_all_cache
before_validation :initialize_creator, :on => :create
validates_presence_of :creator_id
validates_presence_of :creator_id, :antecedent_name, :consequent_name
validates_uniqueness_of :antecedent_name
validate :absence_of_transitive_relation
belongs_to :creator, :class_name => "User"
belongs_to :forum_topic
module SearchMethods
def name_matches(name)

View File

@@ -3,7 +3,7 @@ class TagImplication < ActiveRecord::Base
after_save :update_descendant_names_for_parent
belongs_to :creator, :class_name => "User"
before_validation :initialize_creator, :on => :create
validates_presence_of :creator_id
validates_presence_of :creator_id, :antecedent_name, :consequent_name
validates_uniqueness_of :antecedent_name, :scope => :consequent_name
validate :absence_of_circular_relation

View File

@@ -16,8 +16,7 @@
<p>You can try to fix this alias. This will clear the cache and re-save all posts associated with <strong><%= @correction.antecedent_name %></strong>.</p>
<%= form_tag(tag_alias_correction_path) do %>
<%= hidden_field "tag_alias_id", params[:tag_alias_id] %>
<%= form_tag(tag_alias_correction_path(:tag_alias_id => @correction.tag_alias_id)) do %>
<%= submit_tag "Fix" %>
<%= submit_tag "Cancel" %>
<% end %>

View File

@@ -0,0 +1,30 @@
<div id="c-tag-aliases">
<div id="a-request-new">
<h1>Tag Alias Request</h1>
<p>You can request a new tag alias be created. This will create a corresponding forum topic for community review.</p>
<%= form_tag(tag_alias_request_path, :class => "simple_form") do %>
<div class="input">
<label>Antecedent</label>
<%= text_field "tag_alias_request", "antecedent_name" %>
</div>
<div class="input">
<label>Consequent</label>
<%= text_field "tag_alias_request", "consequent_name" %>
</div>
<div class="input">
<label>Reason</label>
<%= text_area "tag_alias_request", "reason" %>
</div>
<div class="input">
<%= submit_tag "Submit" %>
</div>
<% end %>
<%= render "tag_aliases/secondary_links" %>
</div>
</div>

View File

@@ -1,7 +1,11 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= link_to "Listing", tag_aliases_path %></li>
<li><%= link_to "New", new_tag_alias_path %></li>
<% if CurrentUser.is_admin? %>
<li><%= link_to "New", new_tag_alias_path %></li>
<% else %>
<li><%= link_to "Request", new_tag_alias_request_path %></li>
<% end %>
<li><%= link_to "Help", wiki_pages_path(:title => "help:tag_aliases") %></li>
</menu>
<% end %>

View File

@@ -0,0 +1,30 @@
<div id="c-tag-implications">
<div id="a-request-new">
<h1>Tag Implication Request</h1>
<p>You can request a new tag implication be created. This will create a corresponding forum topic for community review.</p>
<%= form_tag(tag_implication_request_path, :class => "simple_form") do %>
<div class="input">
<label>Antecedent</label>
<%= text_field "tag_implication_request", "antecedent_name" %>
</div>
<div class="input">
<label>Consequent</label>
<%= text_field "tag_implication_request", "consequent_name" %>
</div>
<div class="input">
<label>Reason</label>
<%= text_area "tag_implication_request", "reason" %>
</div>
<div class="input">
<%= submit_tag "Submit" %>
</div>
<% end %>
<%= render "tag_implications/secondary_links" %>
</div>
</div>

View File

@@ -1,7 +1,11 @@
<% content_for(:secondary_links) do %>
<menu>
<li><%= link_to "Listing", tag_implications_path %></li>
<li><%= link_to "New", new_tag_implication_path %></li>
<% if CurrentUser.is_admin? %>
<li><%= link_to "New", new_tag_implication_path %></li>
<% else %>
<li><%= link_to "Request", new_tag_implication_request_path %></li>
<% end %>
<li><%= link_to "Help", wiki_pages_path(:title => "help:tag_implications") %></li>
</menu>
<% end %>