etna 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
  SHA256:
3
- metadata.gz: 9118a99396cf2b041083ff982fb680a5d60096802699789962d19bcf3fecf41d
4
- data.tar.gz: 3145994427f0fa57bf796e68dfe4e69156eb407f144a6afe048bd17454201949
3
+ metadata.gz: 1e8722ab25f18920f6d9b101d3fb78d52e03a7ffbb884da89b5942c0f3985bb1
4
+ data.tar.gz: 24547dbfc711d1a97cdad56302f1e29ebd6b3bdd6286ca046b34619c134137a5
5
5
  SHA512:
6
- metadata.gz: ec59fd21bcf8bb88848e0c8c628a0185226d7dd7ee1af79525a790ac2117fe2b7d44b9d3e514717e9c23233bd531c9d3c8404981892174adbeee221e62118c33
7
- data.tar.gz: bf0cc8cea804bb218e7f487ea014c84e394738760dc400de1c716b780da6a668ca5f853a72acfff7a77cd979f4a90004a866cdd16cb26a008a3498c83161fd71
6
+ metadata.gz: c878e9867cd036b302bacb0040003f803003760b5445c482797a1e7045b8421852e0f4326916f62d02e4a12e182930b90f06c4f5a66c5baa5a7d1c5c153ef047
7
+ data.tar.gz: c40d34810aef6d6de593732401842d29aa0bd2f33774a439e36713b6736c05a19539e616d3473a73db3104a97f3a89f6c59bfe8aaf6942a013df86eb03f6225c
@@ -48,8 +48,16 @@ module Etna
48
48
 
49
49
  retry
50
50
  rescue Etna::Error => e
51
- raise e unless e.message.include?('not found')
52
- break
51
+ if e.status === 502
52
+ if attempts > 5
53
+ raise e
54
+ end
55
+
56
+ retry
57
+ else
58
+ raise e unless e.message.include?('not found')
59
+ break
60
+ end
53
61
  end
54
62
 
55
63
  documents += last_page.models.model(model_name).documents unless block_given?
@@ -34,7 +34,7 @@ module Etna
34
34
  record_names,
35
35
  model_attributes_mask: model_attributes_mask,
36
36
  model_filters: model_filters,
37
- page_size: 500,
37
+ page_size: 20,
38
38
  ) do |template, document|
39
39
  logger&.info("Materializing #{template.name}##{document[template.identifier]}")
40
40
  templates[template.name] = template
@@ -241,7 +241,13 @@ module Etna
241
241
  attribute_name_clean = attribute_name.strip
242
242
  raise "Invalid attribute \"#{attribute_name_clean}\" for model #{@model_name}." unless attribute = @workflow.find_attribute(@model_name, attribute_name_clean)
243
243
 
244
- attributes[attribute_name_clean] = stripped_value(attribute, @raw[attribute_name])
244
+ stripped = stripped_value(attribute, @raw[attribute_name])
245
+
246
+ unless @workflow.hole_value.nil?
247
+ next if stripped == @workflow.hole_value
248
+ end
249
+
250
+ attributes[attribute_name_clean] = stripped
245
251
  end
246
252
  end
247
253
  end
@@ -9,6 +9,27 @@ module Etna
9
9
  class WalkModelTreeWorkflow < Struct.new(:magma_crud, :logger, keyword_init: true)
10
10
  def initialize(**args)
11
11
  super(**({}.update(args)))
12
+ @template_for = {}
13
+ end
14
+
15
+ def masked_attributes(template:, model_attributes_mask:, model_name:)
16
+ attributes_mask = model_attributes_mask[model_name]
17
+ return ["all", "all"] if attributes_mask.nil?
18
+ [(attributes_mask + [template.identifier, 'parent']).uniq, attributes_mask]
19
+ end
20
+
21
+ def attribute_included?(mask, attribute_name)
22
+ return true if mask == "all"
23
+ mask.include?(attribute_name)
24
+ end
25
+
26
+ def template_for(model_name)
27
+ @template_for[model_name] ||= magma_crud.magma_client.retrieve(RetrievalRequest.new(
28
+ project_name: magma_crud.project_name,
29
+ model_name: model_name,
30
+ record_names: [],
31
+ attribute_names: [],
32
+ )).models.model(model_name).template
12
33
  end
13
34
 
14
35
  def walk_from(
@@ -26,29 +47,30 @@ module Etna
26
47
  next if seen.include?([path[:from], model_name])
27
48
  seen.add([path[:from], model_name])
28
49
 
50
+ template = template_for(model_name)
51
+ query_attributes, walk_attributes = masked_attributes(template: template, model_attributes_mask: model_attributes_mask, model_name: model_name)
52
+
29
53
  request = RetrievalRequest.new(
30
54
  project_name: magma_crud.project_name,
31
55
  model_name: model_name,
32
56
  record_names: path[:record_names],
33
57
  filter: model_filters[model_name],
58
+ attribute_names: query_attributes,
34
59
  page_size: page_size, page: 1
35
60
  )
36
61
 
37
62
  related_models = {}
38
63
 
39
64
  magma_crud.page_records(model_name, request) do |response|
40
- model = response.models.model(model_name)
41
- template = model.template
42
-
43
65
  tables = []
44
66
  collections = []
45
67
  links = []
46
68
  attributes = []
47
69
 
70
+ model = response.models.model(model_name)
71
+
48
72
  template.attributes.attribute_keys.each do |attr_name|
49
- attributes_mask = model_attributes_mask[model_name]
50
- black_listed = !attributes_mask.nil? && !attributes_mask.include?(attr_name)
51
- next if black_listed && attr_name != template.identifier && attr_name != 'parent'
73
+ next unless attribute_included?(query_attributes, attr_name)
52
74
  attributes << attr_name
53
75
 
54
76
  attr = template.attributes.attribute(attr_name)
@@ -63,7 +85,7 @@ module Etna
63
85
  elsif attr.attribute_type == AttributeType::CHILD
64
86
  related_models[attr.link_model_name] ||= Set.new
65
87
  links << attr_name
66
- elsif attr.attribute_type == AttributeType::PARENT && !black_listed
88
+ elsif attr.attribute_type == AttributeType::PARENT && attribute_included?(walk_attributes, attr_name)
67
89
  related_models[attr.link_model_name] ||= Set.new
68
90
  links << attr_name
69
91
  end
@@ -69,6 +69,11 @@ module Etna
69
69
  @etna_client.folder_remove(delete_folder_request.to_h))
70
70
  end
71
71
 
72
+ def delete_file(delete_file_request)
73
+ FilesResponse.new(
74
+ @etna_client.file_remove(delete_file_request.to_h))
75
+ end
76
+
72
77
  def find(find_request)
73
78
  FoldersAndFilesResponse.new(
74
79
  @etna_client.bucket_find(find_request.to_h))
@@ -95,6 +95,21 @@ module Etna
95
95
  end
96
96
  end
97
97
 
98
+ class DeleteFileRequest < Struct.new(:project_name, :bucket_name, :file_path, keyword_init: true)
99
+ include JsonSerializableStruct
100
+
101
+ def initialize(**params)
102
+ super({}.update(params))
103
+ end
104
+
105
+ def to_h
106
+ # The :project_name comes in from Polyphemus as a symbol value,
107
+ # we need to make sure it's a string because it's going
108
+ # in the URL.
109
+ super().compact.transform_values(&:to_s)
110
+ end
111
+ end
112
+
98
113
  class FindRequest < Struct.new(:project_name, :bucket_name, :limit, :offset, :params, keyword_init: true)
99
114
  include JsonSerializableStruct
100
115
 
data/lib/etna/user.rb CHANGED
@@ -46,7 +46,7 @@ module Etna
46
46
  viewer: /[Vv]/,
47
47
  restricted: /[AEV]/,
48
48
  }
49
- def has_roles(project, *roles)
49
+ def has_any_role?(project, *roles)
50
50
  perm = permissions[project.to_s]
51
51
 
52
52
  return false unless perm
@@ -55,15 +55,23 @@ module Etna
55
55
  end
56
56
 
57
57
  def is_superuser? project=nil
58
- has_roles(:administration, :admin)
58
+ has_any_role?(:administration, :admin)
59
+ end
60
+
61
+ def is_supereditor? project=nil
62
+ has_any_role?(:administration, :admin, :editor)
63
+ end
64
+
65
+ def is_superviewer? project=nil
66
+ has_any_role?(:administration, :admin, :editor, :viewer)
59
67
  end
60
68
 
61
69
  def can_edit? project
62
- is_superuser? || has_roles(project, :admin, :editor)
70
+ is_supereditor? || has_any_role?(project, :admin, :editor)
63
71
  end
64
72
 
65
73
  def can_view? project
66
- is_superuser? || has_roles(project, :admin, :editor, :viewer)
74
+ is_superviewer? || has_any_role?(project, :admin, :editor, :viewer)
67
75
  end
68
76
 
69
77
  # superusers - administrators of the Administration group - cannot
@@ -75,7 +83,7 @@ module Etna
75
83
  end
76
84
 
77
85
  def is_admin? project
78
- is_superuser? || has_roles(project, :admin)
86
+ is_superuser? || has_any_role?(project, :admin)
79
87
  end
80
88
 
81
89
  def active? project=nil
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: etna
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
  - Saurabh Asthana
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-03 00:00:00.000000000 Z
11
+ date: 2021-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack