foreman_snapshot_management 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 30f8e2f14c91a5cf8d79a5c39ae5d65bcf9df35b
4
- data.tar.gz: 2b0299b2785eba2d00c7d4e5fc901532d72647d5
3
+ metadata.gz: 92825bf181cfd185b7005b4ae8484a45fb76be22
4
+ data.tar.gz: 69df917d45d4c2fee44194a275aad9b3a93b0484
5
5
  SHA512:
6
- metadata.gz: 4854c380a31a34c47df1cae2040e3c6720b69337b0d0298a1b33dab96034796a5999731d24e417ef8348235e5c2c3b99f890de5a2f7e0a2c35421bf54b541206
7
- data.tar.gz: 276fa74482b40f90600e250ca1ddc57308ce4d241ebe835d8d3e7c5af95e28ac207dbb65341fb44bda75cc8824f78ba1f083cbbdd197c4d3faab694beb450a8f
6
+ metadata.gz: 1c6fe6bf1cd7b925a20bdd929e519901d193fecbf5817736c4056ffebe2f35bf8c293d313b820cf134bedf8489ccebf1ebd94ba30ff852f62e3ea7b0b9bfbf40
7
+ data.tar.gz: a24566a0193ce31c7dc8060cee2d82a6c2ca82a232cdd813d7c7595d2211d378768511093e1084f88e5f7040283ace1cf63b37f49f76febe466c156ed1863c41
data/README.md CHANGED
@@ -1,3 +1,5 @@
1
+ [![Build Status](https://travis-ci.org/ATIX-AG/foreman_snapshot_management.svg?branch=master)](https://travis-ci.org/ATIX-AG/foreman_snapshot_management)
2
+
1
3
  # ForemanSnapshotManagement
2
4
 
3
5
  ForemanSnapshotManagement is a Foreman plugin to manage snapshots.
@@ -79,26 +79,13 @@ module ForemanSnapshotManagement
79
79
  not_found
80
80
  return false
81
81
  end
82
- @host = Host.authorized(host_permission).friendly.find(host_id)
82
+ @host = Host.authorized("#{action_permission}_snapshots".to_sym, Host).friendly.find(host_id)
83
83
  unless @host
84
84
  not_found
85
85
  return(false)
86
86
  end
87
87
  end
88
88
 
89
- def host_permission
90
- case action_permission.to_s
91
- when 'create', 'destroy'
92
- 'edit'
93
- when 'edit', 'view'
94
- 'view'
95
- when 'revert'
96
- 'revert'
97
- else
98
- raise ::Foreman::Exception.new(N_('unknown host permission for %s'), "#{params[:controller]}##{action_permission}")
99
- end
100
- end
101
-
102
89
  def action_permission
103
90
  case params[:action]
104
91
  when 'revert'
@@ -53,7 +53,13 @@ module ForemanSnapshotManagement
53
53
  #
54
54
  # This methods returns a specific Snapshot for a given host.
55
55
  def get_snapshot(server_id, snapshot_id)
56
- client.snapshots(server_id: server_id).get(snapshot_id)
56
+ snapshot = client.snapshots(server_id: server_id).get(snapshot_id)
57
+ # Workaround for https://github.com/fog/fog-vsphere/commit/d808255cd19c3d43d3227825f1e0d72d3f6ee6b9
58
+ # Remove, when fog-vshpere 1.11 lands in foreman
59
+ while snapshot && snapshot.ref != snapshot_id
60
+ snapshot = snapshot.get_child(snapshot_id)
61
+ end
62
+ snapshot
57
63
  end
58
64
 
59
65
  # Get Snapshots
@@ -1,3 +1,3 @@
1
- <% if @host.compute_resource && @host.compute_resource.capabilities.include?(:snapshots) && authorized_for(:controller => 'foreman_snapshot_management/snapshots', :action => :index) %>
1
+ <% if @host.compute_resource && @host.compute_resource.capabilities.include?(:snapshots) && authorized_for(:auth_object => @host, :permission => :view_snapshots) %>
2
2
  <li><a href='#snapshots' data-toggle='tab'><%= _('Snapshots') %></a></li>
3
3
  <% end %>
@@ -1,4 +1,4 @@
1
- <% if @host.compute_resource && @host.compute_resource.capabilities.include?(:snapshots) && authorized_for(:controller => 'foreman_snapshot_management/snapshots', :action => :index) %>
1
+ <% if @host.compute_resource && @host.compute_resource.capabilities.include?(:snapshots) && authorized_for(:auth_object => @host, :permission => :view_snapshots) %>
2
2
  <div id='snapshots' class='tab-pane'
3
3
  data-ajax-url='<%= host_snapshots_path(host_id: @host)%>'
4
4
  data-on-complete='onContentLoad'>
@@ -8,7 +8,7 @@
8
8
  </tr>
9
9
  </thead>
10
10
  <tbody>
11
- <% if authorized_for(:controller => 'foreman_snapshot_management/snapshots', :action => :create) %>
11
+ <% if authorized_for(:auth_object => @host, :permission => :create_snapshots) %>
12
12
  <tr>
13
13
  <td>
14
14
  <%= f.text_field :name, class: 'form-control' %>
@@ -24,7 +24,7 @@
24
24
  <% @snapshots.each do |snapshot| %>
25
25
  <tr>
26
26
  <td>
27
- <% if authorized_for(:controller => 'foreman_snapshot_management/snapshots', :action => :edit) %>
27
+ <% if authorized_for(:auth_object => @host, :permission => :edit_snapshots) %>
28
28
  <%= edit_textfield snapshot, :name %>
29
29
  <% else %>
30
30
  <%= snapshot.name %>
@@ -32,7 +32,7 @@
32
32
  <br /><%= snapshot.formatted_create_time() %>
33
33
  </td>
34
34
  <td>
35
- <% if authorized_for(:controller => 'foreman_snapshot_management/snapshots', :action => :edit) %>
35
+ <% if authorized_for(:auth_object => @host, :permission => :edit_snapshots) %>
36
36
  <%= edit_textarea snapshot, :description %>
37
37
  <% else %>
38
38
  <%= snapshot.description %>
@@ -40,8 +40,8 @@
40
40
  </td>
41
41
  <td>
42
42
  <%= action_buttons(
43
- display_link_if_authorized(_('Rollback'), hash_for_revert_host_snapshot_path(host_id: @host, id: snapshot.id), method: :put, class: 'btn btn-primary', data: {confirm: _("Are you sure to revert this Snapshot?")}),
44
- display_delete_if_authorized(hash_for_host_snapshot_path(host_id: @host, id: snapshot.id), data: {confirm: _("Are you sure to delete this Snapshot?")}),
43
+ display_link_if_authorized(_('Rollback'), hash_for_revert_host_snapshot_path(host_id: @host, id: snapshot.id).merge(:auth_object => @host, :permission => :revert_snapshots), method: :put, class: 'btn btn-primary', data: {confirm: _("Are you sure to revert this Snapshot?")}),
44
+ display_delete_if_authorized(hash_for_host_snapshot_path(host_id: @host, id: snapshot.id).merge(:auth_object => @host, :permission => :delete_snapshots), data: {confirm: _("Are you sure to delete this Snapshot?")}),
45
45
  ) %>
46
46
  </td>
47
47
  </tr>
data/config/routes.rb CHANGED
@@ -18,7 +18,7 @@ Rails.application.routes.draw do
18
18
 
19
19
  constraints(host_id: %r{[^\/]+}) do
20
20
  resources :hosts, only: [] do
21
- resources :snapshots, module: 'foreman_snapshot_management' do
21
+ resources :snapshots, module: 'foreman_snapshot_management', only: [:index, :create, :destroy, :update] do
22
22
  member do
23
23
  put :revert
24
24
  end
@@ -1,3 +1,3 @@
1
1
  module ForemanSnapshotManagement
2
- VERSION = '1.2.0'.freeze
2
+ VERSION = '1.3.0'.freeze
3
3
  end
@@ -2,11 +2,11 @@ require 'test_helper'
2
2
 
3
3
  class Api::V2::SnapshotsControllerTest < ActionController::TestCase
4
4
  let(:compute_resource) do
5
- cr = FactoryGirl.create(:compute_resource, :vmware, :uuid => 'Solutions')
5
+ cr = FactoryBot.create(:compute_resource, :vmware, :uuid => 'Solutions')
6
6
  ComputeResource.find_by_id(cr.id)
7
7
  end
8
8
  let(:uuid) { '5032c8a5-9c5e-ba7a-3804-832a03e16381' }
9
- let(:host) { FactoryGirl.create(:host, :managed, :compute_resource => compute_resource, :uuid => uuid) }
9
+ let(:host) { FactoryBot.create(:host, :managed, :compute_resource => compute_resource, :uuid => uuid) }
10
10
  let(:snapshot_id) { 'snapshot-0101' }
11
11
  setup { ::Fog.mock! }
12
12
  teardown { ::Fog.unmock! }
@@ -3,11 +3,11 @@ require 'test_helper'
3
3
  module ForemanSnapshotManagement
4
4
  class SnapshotsControllerTest < ActionController::TestCase
5
5
  let(:compute_resource) do
6
- cr = FactoryGirl.create(:compute_resource, :vmware, :uuid => 'Solutions')
6
+ cr = FactoryBot.create(:compute_resource, :vmware, :uuid => 'Solutions')
7
7
  ComputeResource.find_by_id(cr.id)
8
8
  end
9
9
  let(:uuid) { '5032c8a5-9c5e-ba7a-3804-832a03e16381' }
10
- let(:host) { FactoryGirl.create(:host, :managed, :compute_resource => compute_resource, :uuid => uuid) }
10
+ let(:host) { FactoryBot.create(:host, :managed, :compute_resource => compute_resource, :uuid => uuid) }
11
11
  let(:snapshot_id) { 'snapshot-0101' }
12
12
  setup { ::Fog.mock! }
13
13
  teardown { ::Fog.unmock! }
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: foreman_snapshot_management
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ATIX AG
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-07 00:00:00.000000000 Z
11
+ date: 2017-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: deface
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: rubocop
15
29
  requirement: !ruby/object:Gem::Requirement