Sha256: e9c38d2bc12e74f3f0f44761fd5d6da351b4251ec50271af5b50c104a48bca64

Contents?: true

Size: 1.98 KB

Versions: 38

Compression:

Stored size: 1.98 KB

Contents

module ForestLiana
  class PermissionsGetter
    class << PermissionsGetter
      def get_permissions_api_route
        '/liana/v3/permissions'
      end

      # Permission format example:
      # collections => {
      #   {model_name} => {
      #     collection => {
      #       browseEnabled => true,
      #       readEnabled => true,
      #       editEnabled => true,
      #       addEnabled => true,
      #       deleteEnabled => true,
      #       exportEnabled => true,
      #     },
      #     actions => {
      #       {action_name} => {
      #         triggerEnabled => true,
      #       },
      #     },
      #   },
      # },
      # rederings => {
      #   {rendering_id} => {
      #       {collection_id} => {
      #         scope => {
      #           dynamicScopesValues => {},
      #           filter => {}
      #         }
      #       }
      #     }
      #   }
      # }
      # With `rendering_specific_only` this returns only the permissions related data specific to the provided rendering
      # For now this only includes scopes
      def get_permissions_for_rendering(rendering_id, rendering_specific_only: false)
        begin
          query_parameters = { 'renderingId' => rendering_id }
          query_parameters['renderingSpecificOnly'] = rendering_specific_only if rendering_specific_only

          api_route = get_permissions_api_route
          response = ForestLiana::ForestApiRequester.get(api_route, query: query_parameters)

          if response.is_a?(Net::HTTPOK)
            JSON.parse(response.body)
          else
            raise "Forest API returned an #{ForestLiana::Errors::HTTPErrorHelper.format(response)}"
          end
        rescue => exception
          FOREST_LOGGER.error 'Cannot retrieve the permissions from the Forest server.'
          FOREST_LOGGER.error 'Which was caused by:'
          ForestLiana::Errors::ExceptionHelper.recursively_print(exception, margin: ' ', is_error: true)
          nil
        end
      end
    end
  end
end

Version data entries

38 entries across 38 versions & 1 rubygems

Version Path
forest_liana-6.6.3 app/services/forest_liana/permissions_getter.rb
forest_liana-6.6.2 app/services/forest_liana/permissions_getter.rb
forest_liana-6.6.1 app/services/forest_liana/permissions_getter.rb
forest_liana-6.6.0 app/services/forest_liana/permissions_getter.rb
forest_liana-6.5.1 app/services/forest_liana/permissions_getter.rb
forest_liana-7.0.0.beta.2 app/services/forest_liana/permissions_getter.rb
forest_liana-6.5.0 app/services/forest_liana/permissions_getter.rb
forest_liana-6.4.1 app/services/forest_liana/permissions_getter.rb
forest_liana-7.0.0.beta.1 app/services/forest_liana/permissions_getter.rb
forest_liana-6.4.0 app/services/forest_liana/permissions_getter.rb
forest_liana-6.3.8 app/services/forest_liana/permissions_getter.rb
forest_liana-6.3.7 app/services/forest_liana/permissions_getter.rb
forest_liana-6.3.6 app/services/forest_liana/permissions_getter.rb
forest_liana-6.3.5 app/services/forest_liana/permissions_getter.rb
forest_liana-6.3.4 app/services/forest_liana/permissions_getter.rb
forest_liana-6.3.3 app/services/forest_liana/permissions_getter.rb
forest_liana-6.3.2 app/services/forest_liana/permissions_getter.rb
forest_liana-6.3.1 app/services/forest_liana/permissions_getter.rb
forest_liana-6.3.0 app/services/forest_liana/permissions_getter.rb
forest_liana-6.2.3 app/services/forest_liana/permissions_getter.rb