Skip to content

Commit

Permalink
added admin delete function
Browse files Browse the repository at this point in the history
  • Loading branch information
leemartin committed Aug 9, 2010
1 parent 7835aa3 commit c67b7c9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 10 deletions.
8 changes: 6 additions & 2 deletions app/controllers/remixes_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ def destroy

flash[:notice] = "Your track was successfully deleted."

@remix = Remix.find(:first, :conditions => {:id => params[:id], :user_id => current_user[:id]})
@remix.destroy
@remix = Remix.find(params[:id])

if current_user.uploaded(@remix) || current_user.admin?
@remix.destroy
end

redirect_to(remixes_url)

end
Expand Down
4 changes: 4 additions & 0 deletions app/models/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,8 @@ def uploaded(remix)
remix.user_id == id ? true : false
end

def admin?
SETTINGS["admin_id"].to_s == soundcloud_id ? true : false
end

end
10 changes: 3 additions & 7 deletions app/views/remixes/_remix.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,9 @@
Uploaded by <%= link_to remix.user.name, remix.user.permalink_url, :target => "_blank" -%> <%= time_ago_in_words remix.created_at -%> ago

<% if logged_in? %>

<% if current_user.uploaded(remix) %>

- <%= link_to 'Delete', remix, :confirm => 'Are you sure?', :method => :delete %>

<% end %>

<% if current_user.uploaded(remix) || current_user.admin? %>
- <%= link_to 'Delete', remix, :confirm => 'Are you sure?', :method => :delete %>
<% end %>
<% end %>

</div>
Expand Down
2 changes: 2 additions & 0 deletions config/initializers/configure_remix.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@

SETTINGS["group_id"] = HTTParty.get("http://api.soundcloud.com/resolve?url=#{SETTINGS["group"]}", :format => :xml)["group"]["id"]

SETTINGS["admin_id"] = HTTParty.get("http://api.soundcloud.com/resolve?url=#{SETTINGS["admin"]}", :format => :xml)["user"]["id"]

SETTINGS["instructions"] = File.read("#{RAILS_ROOT}/config/instructions.txt")
5 changes: 4 additions & 1 deletion config/settings.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@ description: SoundCloud remix contest. Submit your remix and vote on other remix
# A link to your Terms, if needed. Leave blank, otherwise
terms:

# Group on SoundCloud where remixes will be added
# URL to user on SoundCloud that will administer the remix app, e.g. http://soundcloud.com/leemartin
admin:

# URL to group on SoundCloud where remixes will be added, e.g. http://soundcloud.com/groups/soundcloud-remix
# You can start a new group here: http://soundcloud.com/groups/new
group:

Expand Down

0 comments on commit c67b7c9

Please sign in to comment.