allow moderators to edit story urls if they ever had one
This commit is contained in:
parent
4cae9d38ae
commit
5e357f5684
|
@ -187,7 +187,12 @@ class StoriesController < ApplicationController
|
||||||
@story.is_expired = false
|
@story.is_expired = false
|
||||||
@story.editor_user_id = @user.id
|
@story.editor_user_id = @user.id
|
||||||
|
|
||||||
if @story.update_attributes(params[:story].except(:url))
|
@story.attributes = params[:story].except(:url)
|
||||||
|
if @story.url_is_editable_by_user?(@user)
|
||||||
|
@story.url = params[:story][:url]
|
||||||
|
end
|
||||||
|
|
||||||
|
if @story.save
|
||||||
return redirect_to @story.comments_url
|
return redirect_to @story.comments_url
|
||||||
else
|
else
|
||||||
return render :action => "edit"
|
return render :action => "edit"
|
||||||
|
|
|
@ -314,19 +314,6 @@ class Story < ActiveRecord::Base
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def url=(u)
|
|
||||||
# strip out stupid google analytics parameters
|
|
||||||
if u && (m = u.match(/\A([^\?]+)\?(.+)\z/))
|
|
||||||
params = m[2].split("&")
|
|
||||||
params.reject!{|p|
|
|
||||||
p.match(/^utm_(source|medium|campaign|term|content)=/) }
|
|
||||||
|
|
||||||
u = m[1] << (params.any?? "?" << params.join("&") : "")
|
|
||||||
end
|
|
||||||
|
|
||||||
self[:url] = u
|
|
||||||
end
|
|
||||||
|
|
||||||
def title=(t)
|
def title=(t)
|
||||||
# change unicode whitespace characters into real spaces
|
# change unicode whitespace characters into real spaces
|
||||||
# TODO: remove remove_mb4 hack
|
# TODO: remove remove_mb4 hack
|
||||||
|
@ -341,10 +328,33 @@ class Story < ActiveRecord::Base
|
||||||
u.gsub(/^_+/, "").gsub(/_+$/, "")
|
u.gsub(/^_+/, "").gsub(/_+$/, "")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def url=(u)
|
||||||
|
# strip out stupid google analytics parameters
|
||||||
|
if u && (m = u.match(/\A([^\?]+)\?(.+)\z/))
|
||||||
|
params = m[2].split("&")
|
||||||
|
params.reject!{|p|
|
||||||
|
p.match(/^utm_(source|medium|campaign|term|content)=/) }
|
||||||
|
|
||||||
|
u = m[1] << (params.any?? "?" << params.join("&") : "")
|
||||||
|
end
|
||||||
|
|
||||||
|
self[:url] = u
|
||||||
|
end
|
||||||
|
|
||||||
def url_or_comments_url
|
def url_or_comments_url
|
||||||
self.url.blank? ? self.comments_url : self.url
|
self.url.blank? ? self.comments_url : self.url
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def url_is_editable_by_user?(user)
|
||||||
|
if self.new_record?
|
||||||
|
true
|
||||||
|
elsif user && user.is_moderator? && self.url.present?
|
||||||
|
true
|
||||||
|
else
|
||||||
|
false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
def is_editable_by_user?(user)
|
def is_editable_by_user?(user)
|
||||||
if user && user.is_moderator?
|
if user && user.is_moderator?
|
||||||
return true
|
return true
|
||||||
|
|
|
@ -2,26 +2,26 @@
|
||||||
|
|
||||||
<div class="box">
|
<div class="box">
|
||||||
<div class="boxline">
|
<div class="boxline">
|
||||||
<% if !f.object.new_record? && !f.object.url.blank? %>
|
<% if f.object.url_is_editable_by_user?(@user) %>
|
||||||
<%= f.label :url, "URL:", :class => "required" %>
|
<%= f.label :url, "URL:", :class => "required" %>
|
||||||
<div class="d">
|
<%= f.text_field :url, :autocomplete => "off" %>
|
||||||
<a href="<%= f.object.url %>"><%= f.object.url %></a>
|
|
||||||
</div>
|
|
||||||
<% elsif !f.object.id %>
|
|
||||||
<%= f.label :url, "URL:", :class => "required" %>
|
|
||||||
<%= f.text_field :url, :autocomplete => "off" %>
|
|
||||||
<%= button_tag "Fetch Title", :id => "story_fetch_title",
|
<%= button_tag "Fetch Title", :id => "story_fetch_title",
|
||||||
:type => "button" %>
|
:type => "button" %>
|
||||||
<% end %>
|
<% elsif !f.object.new_record? && !f.object.url.blank? %>
|
||||||
|
<%= f.label :url, "URL:", :class => "required" %>
|
||||||
|
<div class="d">
|
||||||
|
<a href="<%= f.object.url %>"><%= f.object.url %></a>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="boxline">
|
<div class="boxline">
|
||||||
<%= f.label :title, "Title:", :class => "required" %>
|
<%= f.label :title, "Title:", :class => "required" %>
|
||||||
<%= f.text_field :title, :maxlength => 100, :autocomplete => "off" %>
|
<%= f.text_field :title, :maxlength => 100, :autocomplete => "off" %>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="boxline" style="margin-bottom: 2px;">
|
<div class="boxline" style="margin-bottom: 2px;">
|
||||||
<%= f.label :tags_a, "Tags:", :class => "required",
|
<%= f.label :tags_a, "Tags:", :class => "required",
|
||||||
:style => "line-height: 2.3em;" %>
|
:style => "line-height: 2.3em;" %>
|
||||||
<%= f.select "tags_a", options_for_select(
|
<%= f.select "tags_a", options_for_select(
|
||||||
Tag.all_with_filtered_counts_for(@user).map{|t|
|
Tag.all_with_filtered_counts_for(@user).map{|t|
|
||||||
|
|
Loading…
Reference in a new issue