Skip to content

Commit 93b5fab

Browse files
committed
Add 'My Images' to the user profile, through which user can delete uploaded images
1 parent 345bfdf commit 93b5fab

File tree

6 files changed

+97
-0
lines changed

6 files changed

+97
-0
lines changed

app/abilities/ability.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ def initialize(user)
1717
can [:index, :feed], Changeset
1818
can :index, ChangesetComment
1919
can [:index, :rss, :show, :comments], DiaryEntry
20+
can [:index, :rss, :show, :comments], UploadedImage
2021
can [:mine], Note
2122
can [:index, :show], Redaction
2223
can [:index, :show, :data, :georss, :picture, :icon], Trace
@@ -37,6 +38,7 @@ def initialize(user)
3738
if Settings.status != "database_offline"
3839
can [:index, :new, :create, :show, :edit, :update, :destroy], ClientApplication
3940
can [:new, :create, :edit, :update, :comment, :subscribe, :unsubscribe], DiaryEntry
41+
can [:new, :create, :edit, :update, :comment, :subscribe, :unsubscribe, :destroy, :destroy_multiple], UploadedImage
4042
can [:new, :create, :reply, :show, :inbox, :outbox, :mark, :destroy], Message
4143
can [:close, :reopen], Note
4244
can [:new, :create], Report
@@ -45,6 +47,7 @@ def initialize(user)
4547

4648
if user.moderator?
4749
can [:hide, :hidecomment], DiaryEntry
50+
can [:hide, :hidecomment], UploadedImage
4851
can [:index, :show, :resolve, :ignore, :reopen], Issue
4952
can :create, IssueComment
5053
can [:new, :create, :edit, :update, :destroy], Redaction
@@ -53,6 +56,7 @@ def initialize(user)
5356

5457
if user.administrator?
5558
can [:hide, :unhide, :hidecomment, :unhidecomment], DiaryEntry
59+
can [:hide, :unhide, :hidecomment, :unhidecomment], UploadedImage
5660
can [:index, :show, :resolve, :ignore, :reopen], Issue
5761
can :create, IssueComment
5862
can [:set_status, :delete, :index], User
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
class UploadedImagesController < ApplicationController
2+
layout "site", :except => :rss
3+
before_action :authorize_web
4+
before_action :set_locale
5+
6+
authorize_resource
7+
8+
before_action :lookup_user, :only => [:show, :comments]
9+
before_action :allow_thirdparty_images, :only => [:new, :create, :edit, :update, :index, :show, :comments]
10+
11+
def index
12+
if params[:display_name]
13+
@user = User.active.find_by(:display_name => params[:display_name])
14+
if @user
15+
@title = @user.display_name + "'s uploaded images"
16+
end
17+
end
18+
uri = URI.parse('http://noter-backend:3001/api/v0.1/images/')
19+
response = Net::HTTP.get_response(uri)
20+
@images = JSON.parse(response.body)
21+
end
22+
23+
def destroy_multiple
24+
if params[:deleted_img_ids]
25+
for id in params[:deleted_img_ids] do
26+
uri = URI('http://noter-backend:3001/api/v0.1/images/' + id.to_s + '/')
27+
http = Net::HTTP.new(uri.host, uri.port)
28+
req = Net::HTTP::Delete.new(uri.path)
29+
req["X-Email"] = current_user.email
30+
res = http.request(req)
31+
end
32+
end
33+
redirect_to :action => "index", :display_name => current_user.display_name
34+
end
35+
end

app/models/uploaded_image.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
class UploadedImage < ActiveRecord::Base
2+
def self.get_uploaded_images
3+
uri = URI.parse('http://noter-backend:3001/api/v0.1/images/')
4+
response = Net::HTTP.get_response(uri)
5+
JSON.parse(response.body)
6+
end
7+
end
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<% content_for :heading do %>
2+
<div <% if @user %> id="userinformation"<% end %>>
3+
<% if @user %>
4+
<%= user_image @user %>
5+
<% end %>
6+
<h1><%= h(@title) %></h1>
7+
8+
<ul class='secondary-actions clearfix'>
9+
<% if @user %>
10+
<% if @user == current_user %>
11+
<div>
12+
<li><%= link_to image_tag("new.png", :class => "small_icon", :border => 0) + "Upload", "http://localhost/nf/", :title => t(".new_title") %></li>
13+
</div>
14+
<% end %>
15+
<% else %>
16+
<% if current_user %>
17+
<div>
18+
<li><%= link_to image_tag("new.png", :class => "small_icon", :border => 0) + "Upload", "http://localhost/nf/", :title => t(".new_title") %></li>
19+
</div>
20+
<% end %>
21+
<% end %>
22+
</ul>
23+
</div>
24+
<% end %>
25+
26+
<%= form_tag(destroy_multiplee_uploaded_images_path, method: :delete) do %>
27+
<% @images.each do |img| %>
28+
<ul style="display: table; width:auto; display: inline-block;">
29+
<li style="text-align: center;">
30+
<%= image_tag "http://localhost/nb/download/" + img["id"].to_s + "/", height: "100", alt: "one image" %>
31+
<div>
32+
<%= check_box_tag "deleted_img_ids[]", img["id"] %>
33+
</div>
34+
</li>
35+
</ul>
36+
<% end %>
37+
<%= submit_tag "Delete selected" %>
38+
<% end %>

app/views/users/show.html.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@
2020
<li>
2121
<%= link_to t(".my comments"), :controller => "diary_entries", :action => "comments", :display_name => current_user.display_name %>
2222
</li>
23+
<li>
24+
<%= link_to "My Images", :controller => "uploaded_images", :action => "index", :display_name => current_user.display_name %>
25+
<span class='count-number'><%= number_with_delimiter(UploadedImage.get_uploaded_images().length()) %></span>
26+
</li>
2327
<li>
2428
<%= link_to t(".my settings"), :controller => "users", :action => "account", :display_name => current_user.display_name %>
2529
</li>

config/routes.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,5 +319,14 @@
319319
match "/403", :to => "errors#forbidden", :via => :all
320320
match "/404", :to => "errors#not_found", :via => :all
321321
match "/500", :to => "errors#internal_server_error", :via => :all
322+
323+
#uploaded images
324+
get "/uploaded_images/rss" => "uploaded_images#rss", :defaults => { :format => :rss }
325+
resources :uploaded_images do
326+
collection do
327+
delete :destroy_multiple, as: :destroy_multiplee
328+
end
329+
end
330+
resources :uploaded_images
322331
end
323332
end

0 commit comments

Comments
 (0)