Skip to content

Commit

Permalink
Merge branch 'master' of github.com:concerto/concerto
Browse files Browse the repository at this point in the history
  • Loading branch information
augustf committed May 7, 2012
2 parents eab0599 + 422665f commit 3852ba8
Show file tree
Hide file tree
Showing 8 changed files with 47 additions and 169 deletions.
25 changes: 7 additions & 18 deletions app/controllers/submissions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,16 @@ def show
end
end

# PUT /feeds/1/submission/1/approve
def approve
submission = Submission.find(params[:id])
respond_to do |format|
if submission.approve(current_user, params[:submission][:moderation_reason], params[:submission][:duration])
format.html { redirect_to(feed_submissions_path, :notice => t(:content_approved)) }
else
format.html { redirect_to(feed_submission_path, :notice => t(:content_failed_approve)) }
end
end
end
# PUT /feeds/1/submissions/1
def update
@submission = Submission.find(params[:id])
@submission.moderator = current_user

# PUT /feeds/1/submission/1/deny
def deny
submission = Submission.find(params[:id])
respond_to do |format|
if submission.deny(current_user, params[:submission][:moderation_reason])
format.html { redirect_to(feed_submissions_path, :notice => t(:content_denied)) }
if @submission.update_attributes(params[:submission])
format.html { redirect_to(feed_submissions_path, :notice => t(:content_moderated)) }
else
logger.debug submission.errors
format.html { redirect_to(feed_submission_path, :notice => t(:content_failed_deny)) }
format.html { redirect_to(feed_submission_path, :notice => t(:content_failed_moderation)) }
end
end
end
Expand Down
31 changes: 0 additions & 31 deletions app/models/submission.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,4 @@ def is_denied?
def is_pending?
moderation_flag.nil?
end

# Approve a piece of content on a feed. Must be
# affilailated with a moderator. Duration can be
# overridden as needed.
def approve(moderator, reason, duration = self.duration)
if update_attributes({:moderation_flag => true, :duration => duration, :moderator => moderator, :moderation_reason => reason})
true
else
reload
false
end
end

# Deny a piece of content on a feed. Must be affiliated
# with a moderator. Duration is not changed, because the
# the content is being denied.
def deny(moderator, reason)
if update_attributes({:moderation_flag => false, :moderator => moderator, :moderation_reason => reason})
true
else
reload
false
end
end

# Resets the moderation state of a content submission to a feed.
# Must be affialiated with a moderator. Duration resets on default
# to the duration specified by the uploader.
def unmoderate(moderator, duration = self.content.duration)
update_attributes({:moderation_flag => nil, :duration => duration, :moderator => moderator})
end
end
9 changes: 2 additions & 7 deletions app/views/submissions/_approve_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
<%= form_for([submission.feed, submission], :url => approve_feed_submission_path(submission.feed, submission)) do |f| %>
<div class="clearfix">
<%= f.label :moderation_reason, "Reason" %>
<div class="input">
<%= f.text_area :moderation_reason, :class => "span3" %>
</div>
</div>
<%= form_for([submission.feed, submission]) do |f| %>
<div class="clearfix">
<%= f.label :duration %>
<div class="input">
<%= f.number_field :duration, :class => "span3" %>
</div>
</div>
<%= f.hidden_field :moderation_flag, { :value => true }%>
<%= f.submit "Moderate Content", :class => "btn primary" %>
<% end %>
3 changes: 2 additions & 1 deletion app/views/submissions/_deny_form.html.erb
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<%= form_for([submission.feed, submission], :url => deny_feed_submission_path(submission.feed, submission)) do |f| %>
<%= form_for([submission.feed, submission]) do |f| %>
<div class="clearfix">
<%= f.label :moderation_reason, "Reason" %>
<div class="input">
<%= f.text_area :moderation_reason, :class => "span3" %>
</div>
</div>
<%= f.hidden_field :moderation_flag, { :value => false }%>
<%= f.submit "Moderate Content", :class => "btn primary" %>
<% end %>
23 changes: 11 additions & 12 deletions app/views/submissions/_index_body.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
</div>

</div>

<ul class="tabs">
<% if @sub_feeds.size < 1 %>
<li class="legend">No Sub-feeds</li>
Expand Down Expand Up @@ -67,22 +67,22 @@
<% end %>
<% end %>
</p>


<div id="moderate_<%= submission.id %>" style="display:none;">
<% if submission.is_approved? %>
<p>Currently <b style="color: green;">Approved</b></p>
<%= link_to "Change to Denied", deny_feed_submission_path(submission, :feed_id => submission.feed), :method => :put, :class => "btn danger" %>
<%= link_to "Change to Denied", feed_submission_path(submission, submission.feed), :class => "btn danger" %>
<br />
<% elsif submission.is_denied? %>
<p>Currently <b style="color: red;">Denied</b></p>
<%= link_to "Change to Approved", approve_feed_submission_path(submission, :feed_id => submission.feed), :method => :put, :class => "btn success" %>
<%= link_to "Change to Approved", feed_submission_path(submission, submission.feed), :class => "btn success" %>
<br />
<% else %>
<p>Currently <b>Pending Moderation</b></p>
<div class="btn-group">
<%= link_to "Approve", approve_feed_submission_path(submission, :feed_id => submission.feed), :method => :put, :class => "btn success" %>
<%= link_to "Deny", deny_feed_submission_path(submission, :feed_id => submission.feed), :method => :put, :class => "btn danger" %>
<%= link_to "Approve", feed_submission_path(submission, submission.feed), :class => "btn success" %>
<%= link_to "Deny", feed_submission_path(submission, submission.feed), :class => "btn danger" %>
</div>
<% end %>
<br />
Expand All @@ -103,9 +103,9 @@

$(document).ready(function() {
$('.dropdown-control').click(function(event) { event.preventDefault(); });

$('.dropdown-control.dd-jumpto').each(function() {

$(this).qtip( {

content: {
Expand Down Expand Up @@ -135,7 +135,7 @@
});

$('.dropdown-control.dd-moderate').each(function() {

$(this).qtip( {

content: {
Expand Down Expand Up @@ -163,10 +163,9 @@
});

});

// feed filtering
$('#filter_feeds').listFilter();

});
</script>

40 changes: 20 additions & 20 deletions config/locales/controllers/en.yml
Original file line number Diff line number Diff line change
@@ -1,49 +1,49 @@
en:
en:
#Contents controller
content_created: "Content was successfully created."
content_updated: "Content was successfully updated."

#Feeds controller
feed_created: "Feed was successfully created."
feed_updated: "Feed was successfully updated."
feed_updated: "Feed was successfully updated."

#Fields controller
field_created: "Field was successfully created."
field_updated: "Field was successfully updated."

#Groups controller
group_created: "Group was successfully created."
group_updated: "Group was successfully updated."
group_updated: "Group was successfully updated."

#Memberships controller
membership_created: "Membership was successfully created."
membership_updated: "Membership was successfully updated."
member_promoted: "Member promoted"
member_demoted: "Member demoted"
membership_updated: "Membership was successfully updated."
member_removed: "Member removed"

#Positions controller
position_created: "Position was successfully created."
position_updated: "Position was successfully updated."
position_updated: "Position was successfully updated."

#Screens controller
screen_created: "Screen was successfully created."
screen_updated: "Screen was successfully updated."
screen_updated: "Screen was successfully updated."

#Submissions controller
content_approved: "Content was approved."
content_failed_approve: "Content failed to approved."
content_denied: "Content was denied."
content_failed_deny: "Content failed to deny."

content_moderated: "Content was moderated."
content_failed_moderation: "Content failed moderation"

#Subscriptions controller
subscription_created: "Subscription was successfully created."
subscription_updated: "Subscription was successfully updated."
subscription_updated: "Subscription was successfully updated."

#Templates controller
template_created: "Template was successfully created."
template_updated: "Template was successfully updated."
template_updated: "Template was successfully updated."

#Users controller
user_created: "User was successfully created."
user_updated: "User was successfully updated."
user_updated: "User was successfully updated."
15 changes: 5 additions & 10 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

# These routes control the frontend of Concerto used by screens.
# You probably should not touch them without thinking very hard
# about what you are doing because they could break things in
# about what you are doing because they could break things in
# a very visible way.
namespace :frontend do
resources :screens, :only => [:show], :path => '' do
Expand All @@ -20,7 +20,7 @@
end
# End really dangerous routes.


devise_for :users, :controllers => {:registrations => 'concerto_devise/registrations'}
resources :users

Expand Down Expand Up @@ -61,12 +61,7 @@
end

resources :feeds do
resources :submissions, :only => [:index, :show] do
member do
put :approve
put :deny
end
end
resources :submissions, :only => [:index, :show, :update]
end

#map.resources :feeds do |feeds|
Expand All @@ -76,13 +71,13 @@
resources :contents, :path => "content" do
get :display, :on => :member
end

resources :graphics, :controller => :contents, :path => "content" do
get :display, :on => :member
end

resources :tickers, :controller => :contents, :path => "content"

#Set a non-restul route to the dashboard
match 'dashboard/' => 'dashboard#index'
match 'dashboard/update' => 'dashboard#update', :via => "post"
Expand Down
70 changes: 0 additions & 70 deletions test/unit/submission_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -63,74 +63,4 @@ def setup
assert !submissions(:denied_ticker).is_pending?
assert submissions(:pending_ticker).is_pending?
end

# Verify the approve behavior approves the content.
# If a duration is set, make sure that is used.
test "submission approval" do
s = submissions(:pending_ticker)
assert !s.is_approved?

assert s.approve(users(:katie), nil), "#{s.errors}"
assert s.is_approved?
assert_equal s.moderator, users(:katie)

assert s.approve(users(:kristen), nil, 123)
assert s.is_approved?
assert_equal s.moderator, users(:kristen)
assert_equal 123, s.duration
end

# Make sure content can be denied.
test "submission denial" do
s = submissions(:approved_ticker)
assert !s.is_denied?

assert s.deny(users(:katie), nil), "#{s.errors}"
assert s.is_denied?
assert_equal s.moderator, users(:katie)
end

# Make sure content can be unmoderated. If
# a duration is used, that one should be used
# otherwise it should be reset to the
# content's duration.
test "submission un-moderation" do
s = submissions(:denied_ticker)
assert !s.is_pending?

assert s.unmoderate(users(:katie), 234), "#{s.errors}"
assert s.is_pending?
assert_equal s.moderator, users(:katie)
assert_equal s.duration, 234

assert s.unmoderate(users(:katie)), "#{s.errors}"
assert s.is_pending?
assert_equal s.moderator, users(:katie)
assert_equal s.duration, s.content.duration
end

# Approved or denied content requires
# a moderator to be present.
test "moderated submission needs moderator" do
s = submissions(:pending_ticker)
assert s.is_pending?

assert !s.approve(nil, nil)
assert !s.is_approved?

assert s.approve(users(:katie), nil)
assert s.is_approved?

s.moderator = nil
assert s.invalid?

assert !s.deny(nil, nil)
assert !s.is_denied?

assert s.deny(users(:katie), nil)
assert s.is_denied?

s.moderator = nil
assert s.invalid?
end
end

0 comments on commit 3852ba8

Please sign in to comment.