eco-helpers 2.0.2 → 2.0.3

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
  SHA256:
3
- metadata.gz: 37b6126eddfc0f3ef3c32f621fd0c6d15e5b1e15e83e539a52d331ebe59d8d16
4
- data.tar.gz: 838d28773e4175fe9948243dd0145ee184d6c1329a1c4fb772743db146261465
3
+ metadata.gz: 44dd3a1b4d94cef2da5fc8c4618c6898bf0310f48778be120cd83503913af297
4
+ data.tar.gz: 128f7c6d4a4112636089c82ec61a127914263553af0fe4d54aad563d73088532
5
5
  SHA512:
6
- metadata.gz: daa1ee54fdf2aa3bb983ef4ca8c813c4e6778cea94f32777854fbb157864d80c9eb2120007fbbd4c9a47c3b84d72ca4f671f3f64c8bf0bbafca6385d490e7437
7
- data.tar.gz: 8370f7da5acf41bc0951ed0fee5822bea43e128d8de34a3c84e626d60ad9ade2686bb0911af11e35b0197f8e67d9073826ff0f6b9b4dca4f5c78a73e9297b031
6
+ metadata.gz: d14f77e2cf74584eafc8c9834a71d52d1e399767352d27167ef5cbf05266c2a77777f866e64c482e610c8ca2a600aea3640256ed16ee1c6855a6b2db30af2c76
7
+ data.tar.gz: 1db0afa72df07479f22eca03553b3ac3c51f0228a7d726422a2f6e313565c960554be778c8b36515f1b14dc1085d8378d5d1ec859e96ef26cd116b36ccc738cf
data/CHANGELOG.md CHANGED
@@ -1,7 +1,16 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## [2.0.2] - 2021-02-xx
4
+ ## [2.0.3] - 2021-02-23
5
+
6
+ ### Added
7
+ - `Eco::API::UseCases::OozeSamples::OozeUpdateCase`: added integration to update page instances (non-templates)
8
+
9
+ ### Changed
10
+ ### Fixed
11
+ - `Eco::API::Policies::DefaultPolicies::UserAccess` complete default policy code.
12
+
13
+ ## [2.0.2] - 2021-02-22
5
14
 
6
15
  ### Added
7
16
  ### Changed
@@ -1,18 +1,18 @@
1
1
  class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loaders::Policy
2
2
  name "default-user-access"
3
3
 
4
- attr_reader :session, :options
4
+ attr_reader :session, :options, :job
5
5
  attr_accessor :account_removed_count
6
6
 
7
7
  def main(people, session, options, policy, job)
8
- @session = session; @options = options
8
+ @session = session; @options = options; @job = job
9
9
 
10
10
  self.account_removed_count = 0
11
11
 
12
12
  people.each do |person|
13
- remove_account_when_no_email!(person) if person.email.to_s.empty?
14
- person.account.policy_group_ids = [defid] if no_policy_group_ids?(person)
15
- refresh_abilities!(person.account)
13
+ remove_account_when_no_email!(person) if person.email.to_s.empty?
14
+ person.account.policy_group_ids = defid if no_policy_group_ids?(person)
15
+ refresh_abilities!(person)
16
16
  end
17
17
 
18
18
  warn_account_removal!
@@ -22,14 +22,14 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
22
22
 
23
23
  def warn_account_removal!
24
24
  if account_removed_count > 0
25
- msg = "Removed account to #{account_removed_count} people"
25
+ msg = "(DefaultPolicy on job '#{job.name}') Removed account to #{account_removed_count} people"
26
26
  session.logger.warn(msg)
27
27
  end
28
28
  end
29
29
 
30
30
  def remove_account_when_no_email!(person)
31
31
  if person.account
32
- account_removed_count += 1 if had_account?(person)
32
+ self.account_removed_count += 1 if had_account?(person)
33
33
  person.account = nil
34
34
  end
35
35
  end
@@ -40,23 +40,11 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
40
40
  return !!person.original_doc["account"]
41
41
  end
42
42
 
43
- def provision_basic_level!(person)
44
- if account = person.account
45
-
46
- unless options.dig(:exclude, :abilities)
47
- account.permissions_custom = session.new_preset(person)
48
-
49
- if no_abilities?(person)
50
- account.permissions_custom = min_abilities
51
- end
52
- end
53
-
54
- end
55
- end
56
-
57
- def refresh_abilities!(account)
58
- return nil unless account
59
-
43
+ def refresh_abilities!(person)
44
+ return nil if options.dig(:exclude, :abilities)
45
+ return nil unless account = person.account
46
+ account.permissions_custom = session.new_preset(person)
47
+ account.permissions_custom = min_abilities if no_abilities?(person)
60
48
  end
61
49
 
62
50
  def no_policy_group_ids?(person)
@@ -64,8 +52,8 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
64
52
  end
65
53
 
66
54
  def no_abilities?(person)
67
- person.account.permissions_custom &&
68
- person.account.permissions_custom.values.all?(&:nil?)
55
+ return true unless account = person.account
56
+ account.permissions_custom && account.permissions_custom.values.all?(&:nil?)
69
57
  end
70
58
 
71
59
  def min_abilities
@@ -86,7 +74,7 @@ class Eco::API::Policies::DefaultPolicies::UserAccess < Eco::API::Common::Loader
86
74
  end
87
75
 
88
76
  def defid
89
- @defid ||= policy_groups.to_id(default_group)
77
+ @defid ||= policy_groups.to_id([default_group]).compact
90
78
  end
91
79
 
92
80
  def default_group
@@ -195,6 +195,7 @@ module Eco
195
195
  # @yieldreturn [Eco::API::UseCases::BaseIO] the `io` input/output object carried througout all the _workflow_
196
196
  # @return [Eco::API::Session::Config::Workflow] the current stage object (to ease chainig).
197
197
  def run(key = nil, io:, &block)
198
+ raise "Missing BaseIO object" unless io.is_a?(Eco::API::UseCases::BaseIO)
198
199
  begin
199
200
  if key
200
201
  io = stage(key).run(io: io, &block)
@@ -25,10 +25,30 @@ class Eco::API::UseCases::OozeSamples::OozeUpdateCase < Eco::API::Common::Loader
25
25
  options.dig(:source, :ooze_id)
26
26
  end
27
27
 
28
+ def stage_id
29
+ options.dig(:source, :stage_id)
30
+ end
31
+
32
+ def stage(id_name = stage_id)
33
+ if stg = ooze.stages[id_name] || ooze.stages.get_by_name(id_name)
34
+ return apiv2.pages.get(ooze_id, stage_id: stg.id).tap do |stage|
35
+ if stage
36
+ new_target(stage)
37
+ logger.info("Got #{object_reference(stage)} from #{object_reference(ooze)}")
38
+ else
39
+ logger.error("Could not get stage '#{id_name}' in ooze '#{ooze_id}'")
40
+ exit(1)
41
+ end
42
+ end
43
+ end
44
+ raise "Stage '#{id_name}' doesn't exist in ooze '#{ooze_id}'"
45
+ end
46
+
28
47
  def ooze
29
48
  @ooze ||= apiv2.pages.get(ooze_id).tap do |ooze|
30
49
  if ooze
31
- logger.info("Got ooze '#{ooze_id}': '#{ooze.name}'")
50
+ new_target(ooze)
51
+ logger.info("Got #{object_reference(ooze)}")
32
52
  else
33
53
  logger.error("Could not get ooze '#{ooze_id}'")
34
54
  exit(1)
@@ -39,7 +59,7 @@ class Eco::API::UseCases::OozeSamples::OozeUpdateCase < Eco::API::Common::Loader
39
59
  def launch_request
40
60
  prompt_to_confirm!
41
61
 
42
- apiv2.pages.update(ooze).tap do |response|
62
+ apiv2.pages.update(target).tap do |response|
43
63
  if response.success?
44
64
  logger.info("All went OK")
45
65
  else
@@ -59,9 +79,35 @@ class Eco::API::UseCases::OozeSamples::OozeUpdateCase < Eco::API::Common::Loader
59
79
  @apiv2 ||= session.api(version: :oozes)
60
80
  end
61
81
 
62
- def patch_doc(renew: false)
63
- return @patch_doc if @patch_doc && !renew
64
- @patch_doc = apiv2.pages.get_body(ooze)
82
+ def target
83
+ @target
84
+ end
85
+
86
+ def new_target(object)
87
+ if @target && patch_doc["page"]
88
+ logger.warn "You you are switching to a new target #{object_reference(object)} after doing unsaved changes to #{object_reference(@target)}"
89
+ end
90
+ @target = object
91
+ end
92
+
93
+ def object_reference(obj)
94
+ return "No reference" unless obj
95
+ "".tap do |ref|
96
+ case obj
97
+ when Ecoportal::API::V2::Page::Stage
98
+ ref << "Stage "
99
+ when Ecoportal::API::V2::Pages::PageStage
100
+ ref << "StagePage "
101
+ when Ecoportal::API::V2::Page
102
+ ref << "Page "
103
+ end
104
+ ref << "'#{obj.name}' " if obj.respond_to?(:name)
105
+ end
106
+ end
107
+
108
+
109
+ def patch_doc
110
+ apiv2.pages.get_body(target)
65
111
  end
66
112
 
67
113
  def backup_patch!
data/lib/eco/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Eco
2
- VERSION = "2.0.2"
2
+ VERSION = "2.0.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: eco-helpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.2
4
+ version: 2.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oscar Segura