Permalink
Browse files

allow moderators to edit story urls if they ever had one

  • Loading branch information...
jcs committed Mar 26, 2013
1 parent 4cae9d3 commit 5e357f5684077a47656b0a57deb75d1ecaf70c41
Showing with 39 additions and 24 deletions.
  1. +6 −1 app/controllers/stories_controller.rb
  2. +23 −13 app/models/story.rb
  3. +10 −10 app/views/stories/_form.html.erb
@@ -187,7 +187,12 @@ def update
@story.is_expired = false
@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
else
return render :action => "edit"
View
@@ -314,19 +314,6 @@ def tagging_changes
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)
# change unicode whitespace characters into real spaces
# TODO: remove remove_mb4 hack
@@ -341,10 +328,33 @@ def title_as_url
u.gsub(/^_+/, "").gsub(/_+$/, "")
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
self.url.blank? ? self.comments_url : self.url
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)
if user && user.is_moderator?
return true
@@ -2,26 +2,26 @@
<div class="box">
<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" %>
<div class="d">
<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" %>
<%= f.text_field :url, :autocomplete => "off" %>
<%= button_tag "Fetch Title", :id => "story_fetch_title",
: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 class="boxline">
<%= f.label :title, "Title:", :class => "required" %>
<%= f.text_field :title, :maxlength => 100, :autocomplete => "off" %>
</div>
</div>
<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;" %>
<%= f.select "tags_a", options_for_select(
Tag.all_with_filtered_counts_for(@user).map{|t|

0 comments on commit 5e357f5

Please sign in to comment.