Class: Merge::Filestorage::Permission

Inherits:
Object
  • Object
show all
Defined in:
lib/merge_ruby_client/filestorage/types/permission.rb

Overview

# The Permission Object

### Description
The Permission object is used to represent a user's or group's access to a File
or Folder. Permissions are unexpanded by default.
### Usage Example
Fetch from the `GET Files` or `GET Folders` endpoint. Permissions are unexpanded
by default. Use the query param `expand=permissions` to see more details.

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: OMIT, remote_id: OMIT, created_at: OMIT, modified_at: OMIT, user: OMIT, group: OMIT, type: OMIT, roles: OMIT, additional_properties: nil) ⇒ Merge::Filestorage::Permission

Parameters:

  • id (String) (defaults to: OMIT)
  • remote_id (String) (defaults to: OMIT)

    The third-party API ID of the matching object.

  • created_at (DateTime) (defaults to: OMIT)

    The datetime that this object was created by Merge.

  • modified_at (DateTime) (defaults to: OMIT)

    The datetime that this object was modified by Merge.

  • user (Merge::Filestorage::PermissionUser) (defaults to: OMIT)

    The user that is granted this permission.

  • group (Merge::Filestorage::PermissionGroup) (defaults to: OMIT)

    The group that is granted this permission.

  • type (Merge::Filestorage::TypeEnum) (defaults to: OMIT)

    Denotes what type of people have access to the file.

    • ‘USER` - USER

    • ‘GROUP` - GROUP

    • ‘COMPANY` - COMPANY

    • ‘ANYONE` - ANYONE

  • roles (Array<Merge::Filestorage::RolesEnum>) (defaults to: OMIT)

    The permissions that the user or group has for the File or Folder. It is possible for a user or group to have multiple roles, such as viewing & uploading. Possible values include: ‘READ`, `WRITE`, `OWNER`. In cases where there is no clear mapping, the original value passed through will be returned.

  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/merge_ruby_client/filestorage/types/permission.rb', line 69

def initialize(id: OMIT, remote_id: OMIT, created_at: OMIT, modified_at: OMIT, user: OMIT, group: OMIT,
               type: OMIT, roles: OMIT, additional_properties: nil)
  @id = id if id != OMIT
  @remote_id = remote_id if remote_id != OMIT
  @created_at = created_at if created_at != OMIT
  @modified_at = modified_at if modified_at != OMIT
  @user = user if user != OMIT
  @group = group if group != OMIT
  @type = type if type != OMIT
  @roles = roles if roles != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "id": id,
    "remote_id": remote_id,
    "created_at": created_at,
    "modified_at": modified_at,
    "user": user,
    "group": group,
    "type": type,
    "roles": roles
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



45
46
47
# File 'lib/merge_ruby_client/filestorage/types/permission.rb', line 45

def additional_properties
  @additional_properties
end

#created_atDateTime (readonly)

Returns The datetime that this object was created by Merge.

Returns:

  • (DateTime)

    The datetime that this object was created by Merge.



26
27
28
# File 'lib/merge_ruby_client/filestorage/types/permission.rb', line 26

def created_at
  @created_at
end

#groupMerge::Filestorage::PermissionGroup (readonly)

Returns The group that is granted this permission.

Returns:



32
33
34
# File 'lib/merge_ruby_client/filestorage/types/permission.rb', line 32

def group
  @group
end

#idString (readonly)

Returns:

  • (String)


22
23
24
# File 'lib/merge_ruby_client/filestorage/types/permission.rb', line 22

def id
  @id
end

#modified_atDateTime (readonly)

Returns The datetime that this object was modified by Merge.

Returns:

  • (DateTime)

    The datetime that this object was modified by Merge.



28
29
30
# File 'lib/merge_ruby_client/filestorage/types/permission.rb', line 28

def modified_at
  @modified_at
end

#remote_idString (readonly)

Returns The third-party API ID of the matching object.

Returns:

  • (String)

    The third-party API ID of the matching object.



24
25
26
# File 'lib/merge_ruby_client/filestorage/types/permission.rb', line 24

def remote_id
  @remote_id
end

#rolesArray<Merge::Filestorage::RolesEnum> (readonly)

Returns The permissions that the user or group has for the File or Folder. It is possible for a user or group to have multiple roles, such as viewing & uploading. Possible values include: ‘READ`, `WRITE`, `OWNER`. In cases where there is no clear mapping, the original value passed through will be returned.

Returns:

  • (Array<Merge::Filestorage::RolesEnum>)

    The permissions that the user or group has for the File or Folder. It is possible for a user or group to have multiple roles, such as viewing & uploading. Possible values include: ‘READ`, `WRITE`, `OWNER`. In cases where there is no clear mapping, the original value passed through will be returned.



43
44
45
# File 'lib/merge_ruby_client/filestorage/types/permission.rb', line 43

def roles
  @roles
end

#typeMerge::Filestorage::TypeEnum (readonly)

Returns Denotes what type of people have access to the file.

  • ‘USER` - USER

  • ‘GROUP` - GROUP

  • ‘COMPANY` - COMPANY

  • ‘ANYONE` - ANYONE.

Returns:

  • (Merge::Filestorage::TypeEnum)

    Denotes what type of people have access to the file.

    • ‘USER` - USER

    • ‘GROUP` - GROUP

    • ‘COMPANY` - COMPANY

    • ‘ANYONE` - ANYONE



38
39
40
# File 'lib/merge_ruby_client/filestorage/types/permission.rb', line 38

def type
  @type
end

#userMerge::Filestorage::PermissionUser (readonly)

Returns The user that is granted this permission.

Returns:



30
31
32
# File 'lib/merge_ruby_client/filestorage/types/permission.rb', line 30

def user
  @user
end

Class Method Details

.from_json(json_object:) ⇒ Merge::Filestorage::Permission

Deserialize a JSON object to an instance of Permission

Parameters:

  • json_object (String)

Returns:



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/merge_ruby_client/filestorage/types/permission.rb', line 98

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  id = parsed_json["id"]
  remote_id = parsed_json["remote_id"]
  created_at = (DateTime.parse(parsed_json["created_at"]) unless parsed_json["created_at"].nil?)
  modified_at = (DateTime.parse(parsed_json["modified_at"]) unless parsed_json["modified_at"].nil?)
  if parsed_json["user"].nil?
    user = nil
  else
    user = parsed_json["user"].to_json
    user = Merge::Filestorage::PermissionUser.from_json(json_object: user)
  end
  if parsed_json["group"].nil?
    group = nil
  else
    group = parsed_json["group"].to_json
    group = Merge::Filestorage::PermissionGroup.from_json(json_object: group)
  end
  type = parsed_json["type"]
  roles = parsed_json["roles"]
  new(
    id: id,
    remote_id: remote_id,
    created_at: created_at,
    modified_at: modified_at,
    user: user,
    group: group,
    type: type,
    roles: roles,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given

hash and check each fields type against the current object's property
definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


145
146
147
148
149
150
151
152
153
154
# File 'lib/merge_ruby_client/filestorage/types/permission.rb', line 145

def self.validate_raw(obj:)
  obj.id&.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  obj.remote_id&.is_a?(String) != false || raise("Passed value for field obj.remote_id is not the expected type, validation failed.")
  obj.created_at&.is_a?(DateTime) != false || raise("Passed value for field obj.created_at is not the expected type, validation failed.")
  obj.modified_at&.is_a?(DateTime) != false || raise("Passed value for field obj.modified_at is not the expected type, validation failed.")
  obj.user.nil? || Merge::Filestorage::PermissionUser.validate_raw(obj: obj.user)
  obj.group.nil? || Merge::Filestorage::PermissionGroup.validate_raw(obj: obj.group)
  obj.type&.is_a?(Merge::Filestorage::TypeEnum) != false || raise("Passed value for field obj.type is not the expected type, validation failed.")
  obj.roles&.is_a?(Array) != false || raise("Passed value for field obj.roles is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of Permission to a JSON object

Returns:

  • (String)


135
136
137
# File 'lib/merge_ruby_client/filestorage/types/permission.rb', line 135

def to_json(*_args)
  @_field_set&.to_json
end