Exception: AtlasRb::PermissionsError

Inherits:
Error
  • Object
show all
Defined in:
lib/atlas_rb/errors.rb

Overview

Note:

Keyed on the envelope's error code, not the request path, so other 422s on the same endpoint (e.g. tombstone's has_live_children) pass through untouched.

Raised when Atlas refuses an ACL write on a resource (PATCH /{works,collections,communities}/:id with metadata[permissions]) because it breaks a rights invariant. Today the one code is visibility_exceeds_parent: a resource may be no more visible than its structural container, so opening a Work to public inside a restricted Collection is refused (the fix is to widen the container).

This is NOT an authorization failure — the caller may well hold full edit rights on the resource, and a depositor choosing "Public" on their own item under a private collection trips it in ordinary use. Without the typed error the binding's ["collection"] / ["work"] unwrap returns an envelope the caller reads as success, so the user's visibility edit is silently discarded.

rescue AtlasRb::PermissionsError => e
flash.now[:alert] = t("permissions.errors.#{e.code}", default: e.message)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(message, code: nil, resource_id: nil) ⇒ PermissionsError

Returns a new instance of PermissionsError.

Parameters:

  • message (String)

    human-readable rejection description.

  • code (String, nil) (defaults to: nil)

    the envelope's error discriminator.

  • resource_id (String, nil) (defaults to: nil)

    the rejected resource's ID.



235
236
237
238
239
# File 'lib/atlas_rb/errors.rb', line 235

def initialize(message, code: nil, resource_id: nil)
  super(message)
  @code = code
  @resource_id = resource_id
end

Instance Attribute Details

#codeString? (readonly)

Returns the machine-readable error code from the envelope, suitable for keying an i18n map.

Returns:

  • (String, nil)

    the machine-readable error code from the envelope, suitable for keying an i18n map.



227
228
229
# File 'lib/atlas_rb/errors.rb', line 227

def code
  @code
end

#resource_idString? (readonly)

Returns the rejected resource's ID, from the envelope.

Returns:

  • (String, nil)

    the rejected resource's ID, from the envelope.



230
231
232
# File 'lib/atlas_rb/errors.rb', line 230

def resource_id
  @resource_id
end