Class: Labimotion::KlassShareEntity

Inherits:
ApplicationEntity
  • Object
show all
Defined in:
lib/labimotion/entities/klass_share_entity.rb

Overview

One collaborator row in the Share modal. Exposes both the integer level and its label so the frontend neither hardcodes the numeric mapping nor loses the ordering the integers carry. The user block mirrors the owner block on GenericKlassEntity, state included — a share held by a departed user renders greyed out, it is never deleted (the account can be undeleted, and its shares should come back with it).

Instance Method Summary collapse

Instance Method Details

#permissionObject



17
18
19
20
# File 'lib/labimotion/entities/klass_share_entity.rb', line 17

def permission
  value = object.permission_level
  value.is_a?(Integer) ? Labimotion::KlassShare::LEVELS.key(value)&.to_s : value.to_s
end

#permission_level_valueObject



22
23
24
# File 'lib/labimotion/entities/klass_share_entity.rb', line 22

def permission_level_value
  object.level
end

#userObject



26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/labimotion/entities/klass_share_entity.rb', line 26

def user
  resolved = options[:users]&.[](object.shared_with_id) ||
             Labimotion::OwnerResolver.find(object.shared_with_id)
  return { id: object.shared_with_id, name: nil, name_abbreviation: nil, state: 'unknown' } if resolved.nil?

  {
    id: object.shared_with_id,
    name: resolved.name,
    name_abbreviation: resolved.name_abbreviation,
    state: user_state(resolved)
  }
end