foreman_datacenter 0.1.30 → 0.1.31
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/foreman_datacenter/comments_controller.rb +31 -8
- data/app/controllers/foreman_datacenter/devices_controller.rb +2 -2
- data/app/views/foreman_datacenter/comments/_item.html.erb +13 -11
- data/app/views/foreman_datacenter/devices/show.html.erb +1 -1
- data/lib/foreman_datacenter/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c2040560c40bda84aa1b4284af8b9ad05914e71f
|
4
|
+
data.tar.gz: 8d9f8c59eea56fc83de9277d8bc9f2b5d1f2a862
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f2f676d6354876392cc88ecdc9b0856b0a4d0153aad8e68c2965fa13baf7e74e8b36deb1ae5213227d14d6f8f82b7a4488f28140f21ff8bf481f80f43abc066c
|
7
|
+
data.tar.gz: 0b45cb353eda6b5c39318623b7d33f0c483f69580fd357d2235b85c379e01d888421ec41970ada91071c11b805c7d7fd8c78cbeb9a7501d92018001f8ce36bf3
|
@@ -1,6 +1,7 @@
|
|
1
1
|
module ForemanDatacenter
|
2
2
|
class CommentsController < ApplicationController
|
3
|
-
before_filter :load_resource, :load_commentable
|
3
|
+
before_filter :load_resource, :load_commentable, :load_current_user
|
4
|
+
before_filter :check_owner, only: [:edit]
|
4
5
|
|
5
6
|
def new
|
6
7
|
@comment = Comment.new
|
@@ -25,24 +26,46 @@ module ForemanDatacenter
|
|
25
26
|
@comment = Comment.find(params[:id])
|
26
27
|
@device = find_commentable(@comment)
|
27
28
|
@submodule = parse_submodule(@comment)
|
28
|
-
if @comment.
|
29
|
-
|
29
|
+
if @comment.user == @current_user
|
30
|
+
if @comment.update(comment_params)
|
31
|
+
process_success :success_redirect => "/datacenter/#{@submodule}/#{@comment.commentable_id}#comment-#{@comment.id}"
|
32
|
+
else
|
33
|
+
process_error :redirect => "/datacenter/#{@submodule}/#{@comment.commentable_id}#comment-#{@comment.id}", :error_msg => _("Failed: %s") % (e)
|
34
|
+
end
|
30
35
|
else
|
31
|
-
|
36
|
+
process_error :redirect => "/datacenter/#{@submodule}/#{@comment.commentable_id}#comment-#{@comment.id}", :error_msg => _("You can edit only your own comments")
|
32
37
|
end
|
33
38
|
end
|
34
39
|
|
35
40
|
def destroy
|
36
|
-
@comment =
|
37
|
-
if @comment.
|
38
|
-
|
41
|
+
@comment = Comment.find(params[:id])
|
42
|
+
if @comment.user == @current_user
|
43
|
+
if @comment.destroy
|
44
|
+
process_success :success_redirect => "/datacenter/#{@resource}/#{@id}#comment-#{@comment.id}"
|
45
|
+
else
|
46
|
+
process_error :redirect => "/datacenter/#{@resource}/#{@id}", :error_msg => _("Failed: %s") % (e)
|
47
|
+
end
|
39
48
|
else
|
40
|
-
|
49
|
+
process_error :redirect => "/datacenter/#{@resource}/#{@id}", :error_msg => _("You can delete only your own comments")
|
41
50
|
end
|
42
51
|
end
|
43
52
|
|
44
53
|
private
|
45
54
|
|
55
|
+
def load_current_user
|
56
|
+
@current_user = User.current
|
57
|
+
end
|
58
|
+
|
59
|
+
def check_owner
|
60
|
+
comment = Comment.find(params[:id])
|
61
|
+
commentable = comment.commentable_type.constantize.find(comment.commentable_id)
|
62
|
+
resource = parse_submodule(comment)
|
63
|
+
if comment.user != @current_user
|
64
|
+
process_error :redirect => (request.referrer || "/datacenter/#{resource}/#{commentable.id}" || root_path), :error_msg => _("You can edit only your own comments")
|
65
|
+
return
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
46
69
|
def load_resource
|
47
70
|
if (params[:resource] && params[:resource_id])
|
48
71
|
@resource, @id = params[:resource], params[:resource_id]
|
@@ -30,7 +30,7 @@ module ForemanDatacenter
|
|
30
30
|
console_ports: [:console_server_port],
|
31
31
|
power_ports: [:power_outlet]
|
32
32
|
).find(params[:id])
|
33
|
-
@
|
33
|
+
@current_user = User.current
|
34
34
|
@commentable = @device
|
35
35
|
@comment = Comment.new
|
36
36
|
end
|
@@ -68,7 +68,7 @@ module ForemanDatacenter
|
|
68
68
|
|
69
69
|
def destroy
|
70
70
|
if @device.destroy
|
71
|
-
process_success
|
71
|
+
process_success success_redirect: "/datacenter/devices"
|
72
72
|
else
|
73
73
|
process_error object: @device
|
74
74
|
end
|
@@ -1,15 +1,15 @@
|
|
1
1
|
<strong id="comment-<%= comment.id %>">
|
2
2
|
<small class="text-left pull-left">
|
3
|
+
Posted
|
3
4
|
<% if comment.user %>
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
</small>
|
5
|
+
by <%= "#{comment.try(:user).try(:firstname)} #{comment.try(:user).try(:lastname)}" %>
|
6
|
+
<% end %>
|
7
|
+
at <%= comment.updated_at.to_formatted_s(:long_ordinal) %>
|
8
|
+
</small>
|
9
9
|
|
10
|
-
<small class="text-right pull-right">
|
11
|
-
|
12
|
-
</small>
|
10
|
+
<small class="text-right pull-right">
|
11
|
+
<%= link_to "##{comment.id}", "#comment-#{comment.id}" %>
|
12
|
+
</small>
|
13
13
|
</strong>
|
14
14
|
<br/>
|
15
15
|
<div class="text-left pull-left">
|
@@ -18,9 +18,11 @@
|
|
18
18
|
<small>
|
19
19
|
<%= link_to "Reply", new_comment_path(parent_id: comment.id, resource: commentable_data[:resource], resource_id: commentable_data[:id]) %>
|
20
20
|
|
21
|
-
|
22
|
-
|
23
|
-
|
21
|
+
<% if @current_user == comment.user %>
|
22
|
+
<%= link_to "Edit", "/datacenter/comments/#{comment.id}/edit" %>
|
23
|
+
|
24
|
+
<%= link_to "Delete", "/datacenter/#{commentable_data[:resource]}/#{commentable_data[:id]}/comments/#{comment.id}", method: :delete, data: {confirm: "Are you sure?"} %>
|
25
|
+
<% end %>
|
24
26
|
</small>
|
25
27
|
</div>
|
26
28
|
<br/>
|
@@ -17,7 +17,7 @@
|
|
17
17
|
<div class="btn-toolbar pull-right">
|
18
18
|
<%= link_to 'Edit', edit_device_path(@device), class: 'btn btn-warning' %>
|
19
19
|
<%= link_to 'Delete', device_path(@device), class: 'btn btn-danger',
|
20
|
-
|
20
|
+
method: :delete, data: { confirm: 'Are you sure?' } %>
|
21
21
|
<%= link_to 'Import from hosts',
|
22
22
|
@device.host ?
|
23
23
|
edit_device_path(@device, host_id: @device.host.id) :
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: foreman_datacenter
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.31
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pavel Ivanov
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-10-
|
11
|
+
date: 2017-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: deface
|