ecoportal-api-v2 1.1.7 → 2.0.0
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 +4 -4
- data/.markdownlint.json +4 -0
- data/.rubocop.yml +54 -15
- data/.ruby-version +1 -0
- data/CHANGELOG.md +485 -373
- data/ecoportal-api-v2.gemspec +13 -12
- data/lib/ecoportal/api/common/concerns/benchmarkable.rb +47 -34
- data/lib/ecoportal/api/common/concerns/threadable.rb +41 -0
- data/lib/ecoportal/api/common/concerns.rb +1 -0
- data/lib/ecoportal/api/common/content/array_model.rb +85 -79
- data/lib/ecoportal/api/common/content/class_helpers.rb +34 -31
- data/lib/ecoportal/api/common/content/collection_model.rb +77 -65
- data/lib/ecoportal/api/common/content/double_model.rb +105 -87
- data/lib/ecoportal/api/common/content/wrapped_response.rb +11 -11
- data/lib/ecoportal/api/v2/page/component/reference_field.rb +17 -13
- data/lib/ecoportal/api/v2/page/component.rb +67 -68
- data/lib/ecoportal/api/v2/page/components.rb +9 -9
- data/lib/ecoportal/api/v2/page/force.rb +6 -7
- data/lib/ecoportal/api/v2/page/stages.rb +5 -6
- data/lib/ecoportal/api/v2/page.rb +35 -33
- data/lib/ecoportal/api/v2/pages/page_stage.rb +22 -20
- data/lib/ecoportal/api/v2/pages.rb +18 -14
- data/lib/ecoportal/api/v2/people.rb +2 -3
- data/lib/ecoportal/api/v2/registers.rb +28 -13
- data/lib/ecoportal/api/v2/s3/data.rb +27 -0
- data/lib/ecoportal/api/v2/s3/files/batch_upload.rb +110 -0
- data/lib/ecoportal/api/v2/s3/files/poll.rb +82 -0
- data/lib/ecoportal/api/v2/s3/files/poll_status.rb +52 -0
- data/lib/ecoportal/api/v2/s3/files.rb +132 -0
- data/lib/ecoportal/api/v2/s3/upload.rb +154 -0
- data/lib/ecoportal/api/v2/s3.rb +66 -0
- data/lib/ecoportal/api/v2.rb +10 -3
- data/lib/ecoportal/api/v2_version.rb +1 -1
- metadata +53 -54
| @@ -14,7 +14,7 @@ module Ecoportal | |
| 14 14 | 
             
                      class_resolver :plain_text_field_class, "Ecoportal::API::V2::Page::Component::PlainTextField"
         | 
| 15 15 | 
             
                      class_resolver :rich_text_field_class,  "Ecoportal::API::V2::Page::Component::RichTextField"
         | 
| 16 16 | 
             
                      class_resolver :people_field_class,     "Ecoportal::API::V2::Page::Component::PeopleField"
         | 
| 17 | 
            -
                      class_resolver :contractor_entities_field_class, "Ecoportal::API::V2::Page::Component::ContractorEntitiesField"
         | 
| 17 | 
            +
                      class_resolver :contractor_entities_field_class, "Ecoportal::API::V2::Page::Component::ContractorEntitiesField" # rubocop:disable Layout/LineLength
         | 
| 18 18 | 
             
                      class_resolver :checklist_field_class,  "Ecoportal::API::V2::Page::Component::ChecklistField"
         | 
| 19 19 | 
             
                      class_resolver :action_field_class,     "Ecoportal::API::V2::Page::Component::ActionField"
         | 
| 20 20 | 
             
                      class_resolver :actions_field_class,    "Ecoportal::API::V2::Page::Component::ActionsField"
         | 
| @@ -30,65 +30,64 @@ module Ecoportal | |
| 30 30 | 
             
                      class << self
         | 
| 31 31 | 
             
                        def new_doc(type: nil)
         | 
| 32 32 | 
             
                          {
         | 
| 33 | 
            -
                            "id" | 
| 33 | 
            +
                            "id" => new_uuid
         | 
| 34 34 | 
             
                          }.tap do |base_doc|
         | 
| 35 35 | 
             
                            if type
         | 
| 36 36 | 
             
                              base_doc.merge!({"type" => type})
         | 
| 37 | 
            -
                              if klass = get_class(base_doc)
         | 
| 37 | 
            +
                              if (klass = get_class(base_doc))
         | 
| 38 38 | 
             
                                base_doc.merge!(klass.new_doc || {})
         | 
| 39 39 | 
             
                              end
         | 
| 40 40 | 
             
                            end
         | 
| 41 41 | 
             
                          end
         | 
| 42 42 | 
             
                        end
         | 
| 43 43 |  | 
| 44 | 
            -
                        def get_class(doc)
         | 
| 45 | 
            -
                           | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 48 | 
            -
             | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 51 | 
            -
             | 
| 52 | 
            -
             | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
             | 
| 56 | 
            -
             | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
             | 
| 63 | 
            -
             | 
| 64 | 
            -
             | 
| 65 | 
            -
             | 
| 66 | 
            -
             | 
| 67 | 
            -
             | 
| 68 | 
            -
             | 
| 69 | 
            -
             | 
| 70 | 
            -
             | 
| 71 | 
            -
             | 
| 72 | 
            -
             | 
| 73 | 
            -
             | 
| 74 | 
            -
             | 
| 75 | 
            -
             | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
             | 
| 81 | 
            -
             | 
| 82 | 
            -
             | 
| 83 | 
            -
             | 
| 84 | 
            -
             | 
| 85 | 
            -
             | 
| 86 | 
            -
             | 
| 87 | 
            -
             | 
| 88 | 
            -
             | 
| 89 | 
            -
             | 
| 90 | 
            -
             | 
| 91 | 
            -
                            end
         | 
| 44 | 
            +
                        def get_class(doc) # rubocop:disable Metrics/AbcSize
         | 
| 45 | 
            +
                          return nil unless doc.is_a?(Hash)
         | 
| 46 | 
            +
                          case doc["type"]
         | 
| 47 | 
            +
                          when "tag_field"
         | 
| 48 | 
            +
                            tag_field_class
         | 
| 49 | 
            +
                          when "geo"
         | 
| 50 | 
            +
                            geo_field_class
         | 
| 51 | 
            +
                          when "select"
         | 
| 52 | 
            +
                            selection_field_class
         | 
| 53 | 
            +
                          when "date"
         | 
| 54 | 
            +
                            date_field_class
         | 
| 55 | 
            +
                          when "number"
         | 
| 56 | 
            +
                            number_field_class
         | 
| 57 | 
            +
                          when "gauge"
         | 
| 58 | 
            +
                            gauge_field_class
         | 
| 59 | 
            +
                          when "plain_text"
         | 
| 60 | 
            +
                            plain_text_field_class
         | 
| 61 | 
            +
                          when "rich_text"
         | 
| 62 | 
            +
                            rich_text_field_class
         | 
| 63 | 
            +
                          when "people"
         | 
| 64 | 
            +
                            people_field_class
         | 
| 65 | 
            +
                          when "contractor_entities"
         | 
| 66 | 
            +
                            contractor_entities_field_class
         | 
| 67 | 
            +
                          when "checklist"
         | 
| 68 | 
            +
                            checklist_field_class
         | 
| 69 | 
            +
                          when "page_action", "checklist_task"
         | 
| 70 | 
            +
                            action_field_class
         | 
| 71 | 
            +
                          when "actions_list"
         | 
| 72 | 
            +
                            actions_field_class
         | 
| 73 | 
            +
                          when "file"
         | 
| 74 | 
            +
                            files_field_class
         | 
| 75 | 
            +
                          when "image_gallery"
         | 
| 76 | 
            +
                            images_field_class
         | 
| 77 | 
            +
                          when "signature"
         | 
| 78 | 
            +
                            signature_field_class
         | 
| 79 | 
            +
                          when "cross_reference"
         | 
| 80 | 
            +
                            reference_field_class
         | 
| 81 | 
            +
                          when "law"
         | 
| 82 | 
            +
                            law_field_class
         | 
| 83 | 
            +
                          when "mailbox"
         | 
| 84 | 
            +
                            mailbox_field_class
         | 
| 85 | 
            +
                          when "chart"
         | 
| 86 | 
            +
                            chart_field_class
         | 
| 87 | 
            +
                          when "frequency_rate_chart"
         | 
| 88 | 
            +
                            chart_fr_field_class
         | 
| 89 | 
            +
                          else
         | 
| 90 | 
            +
                            self
         | 
| 92 91 | 
             
                          end
         | 
| 93 92 | 
             
                        end
         | 
| 94 93 | 
             
                      end
         | 
| @@ -103,7 +102,7 @@ module Ecoportal | |
| 103 102 | 
             
                      passarray   :refs
         | 
| 104 103 |  | 
| 105 104 | 
             
                      def ooze
         | 
| 106 | 
            -
                         | 
| 105 | 
            +
                        _parent.ooze
         | 
| 107 106 | 
             
                      end
         | 
| 108 107 |  | 
| 109 108 | 
             
                      def ref_backend
         | 
| @@ -111,9 +110,10 @@ module Ecoportal | |
| 111 110 | 
             
                      end
         | 
| 112 111 |  | 
| 113 112 | 
             
                      def ref(any_length: false)
         | 
| 114 | 
            -
                         | 
| 115 | 
            -
             | 
| 116 | 
            -
             | 
| 113 | 
            +
                        digest = self.class.hash_label(label, any_length: any_length)
         | 
| 114 | 
            +
                        return unless digest
         | 
| 115 | 
            +
             | 
| 116 | 
            +
                        [type, digest].join(".")
         | 
| 117 117 | 
             
                      end
         | 
| 118 118 |  | 
| 119 119 | 
             
                      # Looks up the section that this component belongs to.
         | 
| @@ -159,19 +159,19 @@ module Ecoportal | |
| 159 159 |  | 
| 160 160 | 
             
                      # @return [Boolean] `true` if the component is bound to any force, `false` otherwise
         | 
| 161 161 | 
             
                      def bindings?
         | 
| 162 | 
            -
                        forces.count | 
| 162 | 
            +
                        forces.count&.positive?
         | 
| 163 163 | 
             
                      end
         | 
| 164 164 |  | 
| 165 165 | 
             
                      # If the field has bindings they are replaced by this new field
         | 
| 166 166 | 
             
                      # @note careful with this, depending what's done in the force, this may brake the force.
         | 
| 167 167 | 
             
                      def replace(fld)
         | 
| 168 168 | 
             
                        if fld.section
         | 
| 169 | 
            -
                          fld.move(section:  | 
| 169 | 
            +
                          fld.move(section: section, before: self)
         | 
| 170 170 | 
             
                        else
         | 
| 171 | 
            -
                           | 
| 171 | 
            +
                          section.add(fld, before: self)
         | 
| 172 172 | 
             
                        end
         | 
| 173 173 | 
             
                        replace_bindings(fld)
         | 
| 174 | 
            -
                         | 
| 174 | 
            +
                        delete!
         | 
| 175 175 | 
             
                      end
         | 
| 176 176 |  | 
| 177 177 | 
             
                      def replace_bindings(fld)
         | 
| @@ -179,13 +179,13 @@ module Ecoportal | |
| 179 179 | 
             
                      end
         | 
| 180 180 |  | 
| 181 181 | 
             
                      def delete!
         | 
| 182 | 
            -
                        bindings.each | 
| 183 | 
            -
                         | 
| 184 | 
            -
                         | 
| 182 | 
            +
                        bindings.each(&:delete!)
         | 
| 183 | 
            +
                        unattach!
         | 
| 184 | 
            +
                        _parent.delete!(self)
         | 
| 185 185 | 
             
                      end
         | 
| 186 186 |  | 
| 187 187 | 
             
                      def move(section:, before: nil, after: nil, side: nil)
         | 
| 188 | 
            -
                         | 
| 188 | 
            +
                        unattach!
         | 
| 189 189 | 
             
                        section.add_component(self, before: before, after: after, side: side)
         | 
| 190 190 | 
             
                      end
         | 
| 191 191 |  | 
| @@ -212,17 +212,16 @@ module Ecoportal | |
| 212 212 | 
             
                          when :hide_reports
         | 
| 213 213 | 
             
                            self.hidden_on_reports = true
         | 
| 214 214 | 
             
                          when Hash
         | 
| 215 | 
            -
                            if cnf.key?(:global)
         | 
| 216 | 
            -
                              self.global_binding = cnf[:global]
         | 
| 217 | 
            -
                            end
         | 
| 215 | 
            +
                            self.global_binding = cnf[:global] if cnf.key?(:global)
         | 
| 218 216 | 
             
                          else
         | 
| 219 217 | 
             
                            unused.push(cnf)
         | 
| 220 218 | 
             
                          end
         | 
| 221 219 | 
             
                        end.tap do |unused|
         | 
| 222 | 
            -
                           | 
| 220 | 
            +
                          next if unused.empty?
         | 
| 221 | 
            +
             | 
| 222 | 
            +
                          raise "Unsupported configuration options '#{unused}' for #{self.class}"
         | 
| 223 223 | 
             
                        end
         | 
| 224 224 | 
             
                      end
         | 
| 225 | 
            -
             | 
| 226 225 | 
             
                    end
         | 
| 227 226 | 
             
                  end
         | 
| 228 227 | 
             
                end
         | 
| @@ -5,28 +5,28 @@ module Ecoportal | |
| 5 5 | 
             
                    class Components < Common::Content::CollectionModel
         | 
| 6 6 | 
             
                      class_resolver :component_class, "Ecoportal::API::V2::Page::Component"
         | 
| 7 7 |  | 
| 8 | 
            -
                       | 
| 8 | 
            +
                      klass do |doc|
         | 
| 9 9 | 
             
                        component_class.get_class(doc).tap do |klass|
         | 
| 10 10 | 
             
                          klass.key = :id
         | 
| 11 11 | 
             
                        end
         | 
| 12 12 | 
             
                      end
         | 
| 13 13 |  | 
| 14 | 
            -
                      order_matters = true
         | 
| 14 | 
            +
                      #self.order_matters = true
         | 
| 15 15 |  | 
| 16 16 | 
             
                      def ooze
         | 
| 17 | 
            -
                         | 
| 17 | 
            +
                        _parent.ooze
         | 
| 18 18 | 
             
                      end
         | 
| 19 19 |  | 
| 20 20 | 
             
                      # @return [Ecoportal::API::V2::Page::Component] the field with `id`
         | 
| 21 21 | 
             
                      def get_by_id(id)
         | 
| 22 | 
            -
                         | 
| 22 | 
            +
                        find do |comp|
         | 
| 23 23 | 
             
                          comp.id == id
         | 
| 24 24 | 
             
                        end
         | 
| 25 25 | 
             
                      end
         | 
| 26 26 |  | 
| 27 27 | 
             
                      # @return [Array<Ecoportal::API::V2::Page::Component>] the fields of that `type`
         | 
| 28 28 | 
             
                      def get_by_type(type)
         | 
| 29 | 
            -
                         | 
| 29 | 
            +
                        select do |comp|
         | 
| 30 30 | 
             
                          comp.type.downcase == type.to_s.strip.downcase
         | 
| 31 31 | 
             
                        end
         | 
| 32 32 | 
             
                      end
         | 
| @@ -53,19 +53,19 @@ module Ecoportal | |
| 53 53 | 
             
                      def add(doc: nil, label: doc && doc["label"], type: doc && doc["type"])
         | 
| 54 54 | 
             
                        fld_doc = doc ? JSON.parse(doc.to_json) : component_class.new_doc(type: type)
         | 
| 55 55 | 
             
                        upsert!(fld_doc) do |fld|
         | 
| 56 | 
            -
                          fld.label | 
| 57 | 
            -
                          yield(fld) | 
| 56 | 
            +
                          fld.label = label unless doc
         | 
| 57 | 
            +
                          yield(fld)        if block_given?
         | 
| 58 58 | 
             
                        end
         | 
| 59 59 | 
             
                      end
         | 
| 60 60 |  | 
| 61 61 | 
             
                      # @return [Array<Ecoportal::API::V2::Page::Component>] **orphaned** fields (with no section).
         | 
| 62 62 | 
             
                      def unattached
         | 
| 63 | 
            -
                         | 
| 63 | 
            +
                        reject(&:attached?)
         | 
| 64 64 | 
             
                      end
         | 
| 65 65 |  | 
| 66 66 | 
             
                      # @return [Array<Ecoportal::API::V2::Page::Component>] fields belonging to more than one section.
         | 
| 67 67 | 
             
                      def multi_section
         | 
| 68 | 
            -
                        select | 
| 68 | 
            +
                        select(&:multi_section?)
         | 
| 69 69 | 
             
                      end
         | 
| 70 70 | 
             
                    end
         | 
| 71 71 | 
             
                  end
         | 
| @@ -8,8 +8,8 @@ module Ecoportal | |
| 8 8 | 
             
                      class << self
         | 
| 9 9 | 
             
                        def new_doc
         | 
| 10 10 | 
             
                          {
         | 
| 11 | 
            -
                            "id" | 
| 12 | 
            -
                            "weight" | 
| 11 | 
            +
                            "id"     => new_uuid,
         | 
| 12 | 
            +
                            "weight" => INITIAL_WEIGHT
         | 
| 13 13 | 
             
                          }
         | 
| 14 14 | 
             
                        end
         | 
| 15 15 | 
             
                      end
         | 
| @@ -23,11 +23,11 @@ module Ecoportal | |
| 23 23 | 
             
                      passdate    :last_synced_at
         | 
| 24 24 | 
             
                      passthrough :custom_script
         | 
| 25 25 | 
             
                      passthrough :script, read_only: true
         | 
| 26 | 
            -
                      embeds_many :bindings, | 
| 27 | 
            -
                      embeds_many :helpers, | 
| 26 | 
            +
                      embeds_many :bindings, enum_class: :bindings_class
         | 
| 27 | 
            +
                      embeds_many :helpers, klass: :helper_class
         | 
| 28 28 |  | 
| 29 29 | 
             
                      def ooze
         | 
| 30 | 
            -
                         | 
| 30 | 
            +
                        _parent.ooze
         | 
| 31 31 | 
             
                      end
         | 
| 32 32 |  | 
| 33 33 | 
             
                      # @see Ecoportal::API::V2::Page::Force::Bindings#add
         | 
| @@ -39,12 +39,11 @@ module Ecoportal | |
| 39 39 | 
             
                      def custom_script=(value)
         | 
| 40 40 | 
             
                        doc["custom_script"] = value
         | 
| 41 41 | 
             
                        update_script
         | 
| 42 | 
            -
                        value
         | 
| 43 42 | 
             
                      end
         | 
| 44 43 |  | 
| 45 44 | 
             
                      # It sets the `script` value by using `custom_script` and `helpers[N..1].script`
         | 
| 46 45 | 
             
                      def update_script
         | 
| 47 | 
            -
                        doc["script"] = helpers.to_a.reverse.map(&:script).push( | 
| 46 | 
            +
                        doc["script"] = helpers.to_a.reverse.map(&:script).push(custom_script).join("\n")
         | 
| 48 47 | 
             
                      end
         | 
| 49 48 | 
             
                    end
         | 
| 50 49 | 
             
                  end
         | 
| @@ -5,27 +5,26 @@ module Ecoportal | |
| 5 5 | 
             
                    class Stages < Common::Content::CollectionModel
         | 
| 6 6 | 
             
                      class_resolver :stage_class, "Ecoportal::API::V2::Page::Stage"
         | 
| 7 7 |  | 
| 8 | 
            -
                      self.klass | 
| 8 | 
            +
                      self.klass     = :stage_class
         | 
| 9 9 | 
             
                      self.order_key = :ordering
         | 
| 10 | 
            -
             | 
| 10 | 
            +
             | 
| 11 11 | 
             
                      def ooze
         | 
| 12 | 
            -
                         | 
| 12 | 
            +
                        _parent.ooze
         | 
| 13 13 | 
             
                      end
         | 
| 14 14 |  | 
| 15 15 | 
             
                      # @param name [String, Regexp] the `name` of the stage to find.
         | 
| 16 16 | 
             
                      # @return [Ecoportal::API::V2::Page::Stage, nil]
         | 
| 17 17 | 
             
                      def get_by_name(name)
         | 
| 18 | 
            -
                         | 
| 18 | 
            +
                        find do |stage|
         | 
| 19 19 | 
             
                          same_string?(stage.name, name)
         | 
| 20 20 | 
             
                        end
         | 
| 21 21 | 
             
                      end
         | 
| 22 22 |  | 
| 23 23 | 
             
                      def ordered
         | 
| 24 | 
            -
                         | 
| 24 | 
            +
                        sort_by.with_index do |stage, index|
         | 
| 25 25 | 
             
                          [stage.ordering, index]
         | 
| 26 26 | 
             
                        end
         | 
| 27 27 | 
             
                      end
         | 
| 28 | 
            -
             | 
| 29 28 | 
             
                    end
         | 
| 30 29 | 
             
                  end
         | 
| 31 30 | 
             
                end
         | 
| @@ -2,18 +2,19 @@ module Ecoportal | |
| 2 2 | 
             
              module API
         | 
| 3 3 | 
             
                class V2
         | 
| 4 4 | 
             
                  class Page < Common::Content::DoubleModel
         | 
| 5 | 
            -
                    ALLOWED_KEYS | 
| 6 | 
            -
                       | 
| 7 | 
            -
                       | 
| 8 | 
            -
                       | 
| 9 | 
            -
                       | 
| 10 | 
            -
                       | 
| 11 | 
            -
                       | 
| 12 | 
            -
                       | 
| 13 | 
            -
                       | 
| 14 | 
            -
                    ]
         | 
| 5 | 
            +
                    ALLOWED_KEYS = %w[
         | 
| 6 | 
            +
                      id external_id patch_ver name template_id
         | 
| 7 | 
            +
                      base_tags tags
         | 
| 8 | 
            +
                      time_zone created_at updated_at
         | 
| 9 | 
            +
                      components sections stages
         | 
| 10 | 
            +
                      permits mould_counter mould
         | 
| 11 | 
            +
                      state task_priority
         | 
| 12 | 
            +
                      votes_enabled upvotes downvotes
         | 
| 13 | 
            +
                      forces force_errors subtags
         | 
| 14 | 
            +
                    ].freeze
         | 
| 15 15 |  | 
| 16 16 | 
             
                    passkey     :id
         | 
| 17 | 
            +
                    passthrough :external_id
         | 
| 17 18 | 
             
                    passforced  :patch_ver, default: 1
         | 
| 18 19 | 
             
                    passthrough :name, :template_id
         | 
| 19 20 | 
             
                    passarray   :base_tags, :tags, order_matters: false
         | 
| @@ -41,48 +42,50 @@ module Ecoportal | |
| 41 42 |  | 
| 42 43 | 
             
                    def as_update
         | 
| 43 44 | 
             
                      super.tap do |hash|
         | 
| 44 | 
            -
                        unless  | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
                           | 
| 48 | 
            -
                          return nil if (hash["data"].keys - ["patch_ver"]).empty?
         | 
| 45 | 
            +
                        next unless hash
         | 
| 46 | 
            +
             | 
| 47 | 
            +
                        hash["data"].select! do |key, _value|
         | 
| 48 | 
            +
                          ALLOWED_KEYS.include?(key)
         | 
| 49 49 | 
             
                        end
         | 
| 50 | 
            +
             | 
| 51 | 
            +
                        return nil if (hash["data"].keys - ["patch_ver"]).empty?
         | 
| 50 52 | 
             
                      end
         | 
| 51 53 | 
             
                    end
         | 
| 52 54 |  | 
| 53 55 | 
             
                    def stages?
         | 
| 54 | 
            -
                       | 
| 56 | 
            +
                      doc["stages"] && stages.count.positive?
         | 
| 55 57 | 
             
                    end
         | 
| 56 58 |  | 
| 57 59 | 
             
                    # @return [String] with feedback, if for this page instance, there are any of:
         | 
| 58 60 | 
             
                    #   1. components multi-section (fields belonging to more than one section)
         | 
| 59 61 | 
             
                    def validate
         | 
| 60 | 
            -
                       | 
| 61 | 
            -
                       | 
| 62 | 
            -
                        msg += "There are fields attached to more than one section:\n  • "
         | 
| 63 | 
            -
                        msg += multi.map do |fld|
         | 
| 64 | 
            -
                          fld.label
         | 
| 65 | 
            -
                        end.join("\n  • ") + "\n"
         | 
| 66 | 
            -
                      end
         | 
| 62 | 
            +
                      multi = components.multi_section
         | 
| 63 | 
            +
                      return true unless multi.length.positive?
         | 
| 67 64 |  | 
| 68 | 
            -
                      msg | 
| 65 | 
            +
                      msg = ""
         | 
| 66 | 
            +
                      msg << "There are fields attached to more than one section:"
         | 
| 67 | 
            +
                      msg << "\n  • "
         | 
| 68 | 
            +
                      msg << multi.map(&:label).join("\n  • ")
         | 
| 69 | 
            +
                      msg << "\n"
         | 
| 70 | 
            +
                      msg
         | 
| 69 71 | 
             
                    end
         | 
| 70 72 |  | 
| 71 73 | 
             
                    private
         | 
| 72 74 |  | 
| 73 75 | 
             
                    def _doc_bug_fix(hash)
         | 
| 74 | 
            -
                      hash.tap do | 
| 76 | 
            +
                      hash.tap do
         | 
| 75 77 | 
             
                        _fix_doc(hash["stages"], "flow_node_ids", "section_ids") if hash.key?("stages")
         | 
| 76 | 
            -
             | 
| 77 | 
            -
             | 
| 78 | 
            -
             | 
| 79 | 
            -
             | 
| 80 | 
            -
                         | 
| 78 | 
            +
             | 
| 79 | 
            +
                        next unless hash.key?("sections")
         | 
| 80 | 
            +
             | 
| 81 | 
            +
                        _fix_doc(hash["sections"], "membrane_ids", "component_ids")
         | 
| 82 | 
            +
                        _fix_doc(hash["sections"], "left_membrane_ids", "left_component_ids")
         | 
| 83 | 
            +
                        _fix_doc(hash["sections"], "right_membrane_ids", "right_component_ids")
         | 
| 81 84 | 
             
                      end
         | 
| 82 85 | 
             
                    end
         | 
| 83 86 |  | 
| 84 87 | 
             
                    def _fix_doc(value, source, dest)
         | 
| 85 | 
            -
                      value.tap do | 
| 88 | 
            +
                      value.tap do
         | 
| 86 89 | 
             
                        case value
         | 
| 87 90 | 
             
                        when Array
         | 
| 88 91 | 
             
                          value.each {|v| _fix_doc(v, source, dest)}
         | 
| @@ -91,12 +94,11 @@ module Ecoportal | |
| 91 94 | 
             
                            value[dest] = value[source]
         | 
| 92 95 | 
             
                            value.delete(source)
         | 
| 93 96 | 
             
                          end
         | 
| 94 | 
            -
                        else
         | 
| 97 | 
            +
                        else # rubocop:disable Style/EmptyElse
         | 
| 95 98 | 
             
                          # Do nothing!
         | 
| 96 99 | 
             
                        end
         | 
| 97 100 | 
             
                      end
         | 
| 98 101 | 
             
                    end
         | 
| 99 | 
            -
             | 
| 100 102 | 
             
                  end
         | 
| 101 103 | 
             
                end
         | 
| 102 104 | 
             
              end
         | 
| @@ -18,11 +18,10 @@ module Ecoportal | |
| 18 18 |  | 
| 19 19 | 
             
                      # @return [String] unique id
         | 
| 20 20 | 
             
                      def uid
         | 
| 21 | 
            -
                         | 
| 22 | 
            -
             | 
| 23 | 
            -
             | 
| 24 | 
            -
             | 
| 25 | 
            -
                        end
         | 
| 21 | 
            +
                        return id unless mould_counter?
         | 
| 22 | 
            +
                        return id unless (counter = mould_counter)
         | 
| 23 | 
            +
             | 
| 24 | 
            +
                        counter.render
         | 
| 26 25 | 
             
                      end
         | 
| 27 26 |  | 
| 28 27 | 
             
                      # @return [String] `id` of the stage we got the data of.
         | 
| @@ -32,43 +31,46 @@ module Ecoportal | |
| 32 31 |  | 
| 33 32 | 
             
                      # @return [Ecoportal::API::V2::Page::Stage]
         | 
| 34 33 | 
             
                      def current_stage
         | 
| 35 | 
            -
                         | 
| 36 | 
            -
             | 
| 37 | 
            -
                         | 
| 34 | 
            +
                        return false unless (stage_id = current_stage_id)
         | 
| 35 | 
            +
             | 
| 36 | 
            +
                        stages[stage_id]
         | 
| 38 37 | 
             
                      end
         | 
| 39 38 |  | 
| 40 39 | 
             
                      # @return [String] with feedback, if for this page instance, there are any of:
         | 
| 41 40 | 
             
                      #   1. orphaned components (fields not belonging to any section)
         | 
| 42 41 | 
             
                      #   2. orphaned sections (sections not belonging to any stage)
         | 
| 43 | 
            -
                      def validate
         | 
| 42 | 
            +
                      def validate # rubocop:disable Metrics/AbcSize
         | 
| 44 43 | 
             
                        msg  = super
         | 
| 45 44 | 
             
                        msg  = "" unless msg.is_a?(String)
         | 
| 46 45 |  | 
| 47 46 | 
             
                        orphans = components.unattached.select {|comp| comp.global_binding.to_s.strip.empty?}
         | 
| 48 | 
            -
                        if orphans.length | 
| 49 | 
            -
                          msg  | 
| 50 | 
            -
                          msg  | 
| 51 | 
            -
             | 
| 52 | 
            -
                           | 
| 47 | 
            +
                        if orphans.length.positive?
         | 
| 48 | 
            +
                          msg << "There are fields not attached to any sections:"
         | 
| 49 | 
            +
                          msg << "\n  • "
         | 
| 50 | 
            +
                          msg << orphans.map(&:label).join("\n  • ")
         | 
| 51 | 
            +
                          msg << "\n"
         | 
| 53 52 | 
             
                        end
         | 
| 54 53 |  | 
| 55 | 
            -
                        if (orphans = sections.unattached).length | 
| 56 | 
            -
                          msg  | 
| 57 | 
            -
                          msg  | 
| 54 | 
            +
                        if (orphans = sections.unattached).length.positive?
         | 
| 55 | 
            +
                          msg << "There are sections not attached to any stage:"
         | 
| 56 | 
            +
                          msg << "\n  • "
         | 
| 57 | 
            +
                          msg << orphans.map do |sec|
         | 
| 58 58 | 
             
                            "'#{sec.heading}' (#{sec.id})"
         | 
| 59 | 
            -
                          end.join("\n  • ") | 
| 59 | 
            +
                          end.join("\n  • ")
         | 
| 60 | 
            +
                          msg << "\n"
         | 
| 60 61 | 
             
                        end
         | 
| 62 | 
            +
             | 
| 61 63 | 
             
                        msg.empty?? true : msg
         | 
| 62 64 | 
             
                      end
         | 
| 63 65 |  | 
| 64 66 | 
             
                      def mark_as_submit
         | 
| 65 67 | 
             
                        doc["submitted"] = true
         | 
| 66 | 
            -
                        doc["type"] | 
| 68 | 
            +
                        doc["type"]      = "complete_page"
         | 
| 67 69 | 
             
                      end
         | 
| 68 70 |  | 
| 69 71 | 
             
                      def mark_as_sign_off
         | 
| 70 72 | 
             
                        doc["sign_off"] = true
         | 
| 71 | 
            -
                        doc["type"] | 
| 73 | 
            +
                        doc["type"]     = "review_page"
         | 
| 72 74 | 
             
                      end
         | 
| 73 75 | 
             
                    end
         | 
| 74 76 | 
             
                  end
         | 
| @@ -1,16 +1,17 @@ | |
| 1 1 | 
             
            module Ecoportal
         | 
| 2 2 | 
             
              module API
         | 
| 3 3 | 
             
                class V2
         | 
| 4 | 
            -
                  # @attr_reader client [Common::Client] a `Common::Client` object that | 
| 4 | 
            +
                  # @attr_reader client [Common::Client] a `Common::Client` object that
         | 
| 5 | 
            +
                  #   holds the configuration of the api connection.
         | 
| 5 6 | 
             
                  class Pages
         | 
| 6 | 
            -
                    STAGE_REX = /stages\/(?<sid>.*) | 
| 7 | 
            +
                    STAGE_REX = /stages\/(?<sid>.*)/.freeze
         | 
| 7 8 | 
             
                    extend Common::BaseClass
         | 
| 8 9 | 
             
                    include Common::Content::DocHelpers
         | 
| 9 10 |  | 
| 10 11 | 
             
                    class_resolver :stages_class, "Ecoportal::API::V2::Pages::Stages"
         | 
| 11 | 
            -
                    class_resolver :page_class, | 
| 12 | 
            -
                    class_resolver :page_stage_class, | 
| 13 | 
            -
                    class_resolver :create_page_response_class, | 
| 12 | 
            +
                    class_resolver :page_class, "Ecoportal::API::V2::Page"
         | 
| 13 | 
            +
                    class_resolver :page_stage_class, "Ecoportal::API::V2::Pages::PageStage"
         | 
| 14 | 
            +
                    class_resolver :create_page_response_class, "Ecoportal::API::V2::Pages::PageCreateResponse"
         | 
| 14 15 |  | 
| 15 16 | 
             
                    attr_reader :client
         | 
| 16 17 |  | 
| @@ -35,16 +36,19 @@ module Ecoportal | |
| 35 36 | 
             
                    # @return [Ecoportal::API::V2::Page, Ecoportal::API::V2::Pages::PageStage] the target page.
         | 
| 36 37 | 
             
                    def get(id, stage_id: nil)
         | 
| 37 38 | 
             
                      return stages.get(id: id, stage_id: stage_id) if stage_id
         | 
| 39 | 
            +
             | 
| 38 40 | 
             
                      id       = get_id(id)
         | 
| 39 41 | 
             
                      response = client.get("/pages/#{CGI.escape(id)}")
         | 
| 40 42 | 
             
                      wrapped  = Common::Content::WrappedResponse.new(response, page_class)
         | 
| 41 43 |  | 
| 42 44 | 
             
                      return wrapped.result if wrapped.success?
         | 
| 43 | 
            -
             | 
| 44 | 
            -
             | 
| 45 | 
            -
             | 
| 46 | 
            -
             | 
| 47 | 
            -
             | 
| 45 | 
            +
             | 
| 46 | 
            +
                      url = nil
         | 
| 47 | 
            +
                      url = response.body["data"]     if response.status == 302
         | 
| 48 | 
            +
                      stage_id = url_to_stage_id(url) unless url.nil?
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                      return stages.get(id: id, stage_id: stage_id) if stage_id
         | 
| 51 | 
            +
             | 
| 48 52 | 
             
                      raise "Could not get page #{id} - Error #{response.status}: #{response.body}"
         | 
| 49 53 | 
             
                    end
         | 
| 50 54 |  | 
| @@ -56,7 +60,8 @@ module Ecoportal | |
| 56 60 | 
             
                      body = get_body(doc) # , level: "page"
         | 
| 57 61 | 
             
                      # Launch only if there are changes
         | 
| 58 62 | 
             
                      raise "Missing page object" unless body && body["page"]
         | 
| 59 | 
            -
             | 
| 63 | 
            +
             | 
| 64 | 
            +
                      id = get_id(doc)
         | 
| 60 65 | 
             
                      client.patch("/pages/#{CGI.escape(id)}", data: body)
         | 
| 61 66 | 
             
                    end
         | 
| 62 67 |  | 
| @@ -81,9 +86,9 @@ module Ecoportal | |
| 81 86 | 
             
                      body   = get_body(doc).tap do |hash|
         | 
| 82 87 | 
             
                        unless hash["page"]
         | 
| 83 88 | 
             
                          hash["page"] = {
         | 
| 84 | 
            -
                            "id" | 
| 89 | 
            +
                            "id"        => "111111111111111111111111",
         | 
| 85 90 | 
             
                            "operation" => "changed",
         | 
| 86 | 
            -
                            "data" | 
| 91 | 
            +
                            "data"      => {"patch_ver" => 0}
         | 
| 87 92 | 
             
                          }
         | 
| 88 93 | 
             
                        end
         | 
| 89 94 | 
             
                      end
         | 
| @@ -98,7 +103,6 @@ module Ecoportal | |
| 98 103 | 
             
                    def url_to_stage_id(url)
         | 
| 99 104 | 
             
                      (matches = url.match(STAGE_REX)) && matches[:sid]
         | 
| 100 105 | 
             
                    end
         | 
| 101 | 
            -
             | 
| 102 106 | 
             
                  end
         | 
| 103 107 | 
             
                end
         | 
| 104 108 | 
             
              end
         | 
| @@ -1,9 +1,9 @@ | |
| 1 1 | 
             
            module Ecoportal
         | 
| 2 2 | 
             
              module API
         | 
| 3 3 | 
             
                class V2
         | 
| 4 | 
            -
                  # @attr_reader client [Common::Client] a `Common::Client` object that | 
| 4 | 
            +
                  # @attr_reader client [Common::Client] a `Common::Client` object that
         | 
| 5 | 
            +
                  #   holds the configuration of the api connection.
         | 
| 5 6 | 
             
                  class People < API::Internal::People
         | 
| 6 | 
            -
             | 
| 7 7 | 
             
                    def batch
         | 
| 8 8 | 
             
                      unavailable_method!(__method__)
         | 
| 9 9 | 
             
                    end
         | 
| @@ -24,7 +24,6 @@ module Ecoportal | |
| 24 24 | 
             
                    def unavailable_method!(str)
         | 
| 25 25 | 
             
                      raise "Unavailable method '#{str}' for api '#{VERSION}'"
         | 
| 26 26 | 
             
                    end
         | 
| 27 | 
            -
             | 
| 28 27 | 
             
                  end
         | 
| 29 28 | 
             
                end
         | 
| 30 29 | 
             
              end
         |