foreman_datacenter 0.1.30 → 0.1.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 49cdb573f462e46ab86a64cd7b8915f0c09ff72e
4
- data.tar.gz: 8944573b46fa5dfa2932be16d7c8586ae9907687
3
+ metadata.gz: c2040560c40bda84aa1b4284af8b9ad05914e71f
4
+ data.tar.gz: 8d9f8c59eea56fc83de9277d8bc9f2b5d1f2a862
5
5
  SHA512:
6
- metadata.gz: c69e5748012abb678d68b200eca283cfd60825992cca16e7632cad172d20d228a5970e71787630752b4991b8d5480961e55410c05beabea829df7ec30c84b96a
7
- data.tar.gz: a8193287b95f9c995546bb339c5e0f2f23f8dd7397c5f1ae170319ad5f1ab88e7a35580c25b3b81705275806a01f42eb96274cf262d702fe07b8deb95535a690
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.update(comment_params.merge(user_id: User.current.id))
29
- process_success :success_redirect => "/datacenter/#{@submodule}/#{@comment.commentable_id}#comment-#{@comment.id}"
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
- process_error :redirect => "/datacenter/#{@submodule}/#{@comment.commentable_id}#comment-#{@comment.id}", :error_msg => _("Failed: %s") % (e)
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 = ForemanDatacenter::Comment.find(params[:id])
37
- if @comment.destroy
38
- process_success :success_redirect => "/datacenter/#{@resource}/#{@id}#comment-#{@comment.id}"
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
- process_error :redirect => "/datacenter/#{@resource}/#{@id}", :error_msg => _("Failed: %s") % (e)
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
- @user = User.current
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 object: @device
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
- Posted by <%= "#{comment.try(:user).try(:firstname)} #{comment.try(:user).try(:lastname)}" %> at <%= comment.updated_at %>
5
- <% else %>
6
- Posted at <%= comment.updated_at %>
7
- <% end %>
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
- <%= link_to "##{comment.id}", "#comment-#{comment.id}" %>
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
  &nbsp;
21
- <%= link_to "Edit", "/datacenter/comments/#{comment.id}/edit" %>
22
- &nbsp;
23
- <%= link_to "Delete", "/datacenter/#{commentable_data[:resource]}/#{commentable_data[:id]}/comments/#{comment.id}", method: :delete, data: {confirm: "Are you sure?"} %>
21
+ <% if @current_user == comment.user %>
22
+ <%= link_to "Edit", "/datacenter/comments/#{comment.id}/edit" %>
23
+ &nbsp;
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
- action: :destroy, data: { confirm: 'Are you sure?' } %>
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) :
@@ -1,3 +1,3 @@
1
1
  module ForemanDatacenter
2
- VERSION = '0.1.30'.freeze
2
+ VERSION = '0.1.31'.freeze
3
3
  end
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.30
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-05 00:00:00.000000000 Z
11
+ date: 2017-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: deface