Class: Files::Permission

Inherits:
Object
  • Object
show all
Defined in:
lib/files.com/models/permission.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}, options = {}) ⇒ Permission

Returns a new instance of Permission.



7
8
9
10
# File 'lib/files.com/models/permission.rb', line 7

def initialize(attributes = {}, options = {})
  @attributes = attributes || {}
  @options = options || {}
end

Instance Attribute Details

#attributesObject (readonly)

Returns the value of attribute attributes.



5
6
7
# File 'lib/files.com/models/permission.rb', line 5

def attributes
  @attributes
end

#optionsObject (readonly)

Returns the value of attribute options.



5
6
7
# File 'lib/files.com/models/permission.rb', line 5

def options
  @options
end

Class Method Details

.all(path, params = {}, options = {}) ⇒ Object



132
133
134
# File 'lib/files.com/models/permission.rb', line 132

def self.all(path, params = {}, options = {})
  list(path, params, options)
end

.create(path, params = {}, options = {}) ⇒ Object

Parameters:

group_id - int64 - Group ID
path - string - Folder path
permission - string -  Permission type.  Can be `admin`, `full`, `readonly`, `writeonly`, `list`, or `history`
recursive - boolean - Apply to subfolders recursively?
user_id - int64 - User ID.  Provide `username` or `user_id`
username - string - User username.  Provide `username` or `user_id`


143
144
145
146
147
148
149
150
151
152
153
154
# File 'lib/files.com/models/permission.rb', line 143

def self.create(path, params = {}, options = {})
  params ||= {}
  params[:path] = path
  raise InvalidParameterError.new("Bad parameter: group_id must be an Integer") if params.dig(:group_id) and !params.dig(:group_id).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: permission must be an String") if params.dig(:permission) and !params.dig(:permission).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: user_id must be an Integer") if params.dig(:user_id) and !params.dig(:user_id).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: username must be an String") if params.dig(:username) and !params.dig(:username).is_a?(String)

  response, options = Api.send_request("/permissions", :post, params, options)
  Permission.new(response.data, options)
end

.delete(id, params = {}, options = {}) ⇒ Object

Parameters:

id (required) - int64 - Permission ID.


158
159
160
161
162
163
164
165
166
# File 'lib/files.com/models/permission.rb', line 158

def self.delete(id, params = {}, options = {})
  params ||= {}
  params[:id] = id
  raise InvalidParameterError.new("Bad parameter: id must be an Integer") if params.dig(:id) and !params.dig(:id).is_a?(Integer)
  raise MissingParameterError.new("Parameter missing: id") unless params.dig(:id)

  response, _options = Api.send_request("/permissions/#{params[:id]}", :delete, params, options)
  response.data
end

.destroy(id, params = {}, options = {}) ⇒ Object



168
169
170
# File 'lib/files.com/models/permission.rb', line 168

def self.destroy(id, params = {}, options = {})
  delete(id, params, options)
end

.list(path, params = {}, options = {}) ⇒ Object

Parameters:

page - int64 - Current page number.
per_page - int64 - Number of records to show per page.  (Max: 10,000, 1,000 or less is recommended).
action - string - Deprecated: If set to `count` returns a count of matching records rather than the records themselves.
cursor - string - Send cursor to resume an existing list from the point at which you left off.  Get a cursor from an existing list via the X-Files-Cursor-Next header.
sort_by - object - If set, sort records by the specified field in either 'asc' or 'desc' direction (e.g. sort_by[last_login_at]=desc). Valid fields are `deleted_at`, `group_id`, `path`, `user_id` or `permission`.
filter - object - If set, return records where the specifiied field is equal to the supplied value. Valid fields are `group_id`, `user_id` or `path`.
filter_gt - object - If set, return records where the specifiied field is greater than the supplied value. Valid fields are `group_id`, `user_id` or `path`.
filter_gteq - object - If set, return records where the specifiied field is greater than or equal to the supplied value. Valid fields are `group_id`, `user_id` or `path`.
filter_like - object - If set, return records where the specifiied field is equal to the supplied value. Valid fields are `group_id`, `user_id` or `path`.
filter_lt - object - If set, return records where the specifiied field is less than the supplied value. Valid fields are `group_id`, `user_id` or `path`.
filter_lteq - object - If set, return records where the specifiied field is less than or equal to the supplied value. Valid fields are `group_id`, `user_id` or `path`.
path - string - DEPRECATED: Permission path.  If provided, will scope permissions to this path. Use `filter[path]` instead.
group_id - string - DEPRECATED: Group ID.  If provided, will scope permissions to this group. Use `filter[group_id]` instead.`
user_id - string - DEPRECATED: User ID.  If provided, will scope permissions to this user. Use `filter[user_id]` instead.`
include_groups - boolean - If searching by user or group, also include user's permissions that are inherited from its groups?


109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/files.com/models/permission.rb', line 109

def self.list(path, params = {}, options = {})
  params ||= {}
  params[:path] = path
  raise InvalidParameterError.new("Bad parameter: page must be an Integer") if params.dig(:page) and !params.dig(:page).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: per_page must be an Integer") if params.dig(:per_page) and !params.dig(:per_page).is_a?(Integer)
  raise InvalidParameterError.new("Bad parameter: action must be an String") if params.dig(:action) and !params.dig(:action).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: cursor must be an String") if params.dig(:cursor) and !params.dig(:cursor).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: sort_by must be an Hash") if params.dig(:sort_by) and !params.dig(:sort_by).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter must be an Hash") if params.dig(:filter) and !params.dig(:filter).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter_gt must be an Hash") if params.dig(:filter_gt) and !params.dig(:filter_gt).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter_gteq must be an Hash") if params.dig(:filter_gteq) and !params.dig(:filter_gteq).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter_like must be an Hash") if params.dig(:filter_like) and !params.dig(:filter_like).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter_lt must be an Hash") if params.dig(:filter_lt) and !params.dig(:filter_lt).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: filter_lteq must be an Hash") if params.dig(:filter_lteq) and !params.dig(:filter_lteq).is_a?(Hash)
  raise InvalidParameterError.new("Bad parameter: path must be an String") if params.dig(:path) and !params.dig(:path).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: group_id must be an String") if params.dig(:group_id) and !params.dig(:group_id).is_a?(String)
  raise InvalidParameterError.new("Bad parameter: user_id must be an String") if params.dig(:user_id) and !params.dig(:user_id).is_a?(String)

  List.new(Permission, params) do
    Api.send_request("/permissions", :get, params, options)
  end
end

Instance Method Details

#group_idObject

int64 - Group ID



49
50
51
# File 'lib/files.com/models/permission.rb', line 49

def group_id
  @attributes[:group_id]
end

#group_id=(value) ⇒ Object



53
54
55
# File 'lib/files.com/models/permission.rb', line 53

def group_id=(value)
  @attributes[:group_id] = value
end

#group_nameObject

string - Group name if applicable



58
59
60
# File 'lib/files.com/models/permission.rb', line 58

def group_name
  @attributes[:group_name]
end

#group_name=(value) ⇒ Object



62
63
64
# File 'lib/files.com/models/permission.rb', line 62

def group_name=(value)
  @attributes[:group_name] = value
end

#idObject

int64 - Permission ID



13
14
15
# File 'lib/files.com/models/permission.rb', line 13

def id
  @attributes[:id]
end

#id=(value) ⇒ Object



17
18
19
# File 'lib/files.com/models/permission.rb', line 17

def id=(value)
  @attributes[:id] = value
end

#pathObject

string - Folder path This must be slash-delimited, but it must neither start nor end with a slash. Maximum of 5000 characters.



22
23
24
# File 'lib/files.com/models/permission.rb', line 22

def path
  @attributes[:path]
end

#path=(value) ⇒ Object



26
27
28
# File 'lib/files.com/models/permission.rb', line 26

def path=(value)
  @attributes[:path] = value
end

#permissionObject

string - Permission type



67
68
69
# File 'lib/files.com/models/permission.rb', line 67

def permission
  @attributes[:permission]
end

#permission=(value) ⇒ Object



71
72
73
# File 'lib/files.com/models/permission.rb', line 71

def permission=(value)
  @attributes[:permission] = value
end

#recursiveObject

boolean - Does this permission apply to subfolders?



76
77
78
# File 'lib/files.com/models/permission.rb', line 76

def recursive
  @attributes[:recursive]
end

#recursive=(value) ⇒ Object



80
81
82
# File 'lib/files.com/models/permission.rb', line 80

def recursive=(value)
  @attributes[:recursive] = value
end

#saveObject



84
85
86
87
88
89
90
91
# File 'lib/files.com/models/permission.rb', line 84

def save
  if @attributes[:path]
    raise NotImplementedError.new("The Permission object doesn't support updates.")
  else
    new_obj = Permission.create(@attributes, @options)
    @attributes = new_obj.attributes
  end
end

#user_idObject

int64 - User ID



31
32
33
# File 'lib/files.com/models/permission.rb', line 31

def user_id
  @attributes[:user_id]
end

#user_id=(value) ⇒ Object



35
36
37
# File 'lib/files.com/models/permission.rb', line 35

def user_id=(value)
  @attributes[:user_id] = value
end

#usernameObject

string - User’s username



40
41
42
# File 'lib/files.com/models/permission.rb', line 40

def username
  @attributes[:username]
end

#username=(value) ⇒ Object



44
45
46
# File 'lib/files.com/models/permission.rb', line 44

def username=(value)
  @attributes[:username] = value
end