Class: Appwrite::Teams

Inherits:
Service show all
Defined in:
lib/appwrite/services/teams.rb

Instance Method Summary collapse

Methods inherited from Service

#initialize

Constructor Details

This class inherits a constructor from Appwrite::Service

Instance Method Details

#create(team_id:, name:, roles: nil) ⇒ Team

Create a new team. The user who creates the team will automatically be assigned as the owner of the team. Only the users with the owner role can invite new members, add new owners and delete or update the team.

Parameters:

  • team_id (string)

    Team ID. Choose your own unique ID or pass the string "unique()" to auto generate it. Valid chars are a-z, A-Z, 0-9, period, hyphen, and underscore. Can't start with a special char. Max length is 36 chars.

  • name (string)

    Team name. Max length: 128 chars.

  • roles (array) (defaults to: nil)

    Array of strings. Use this param to set the roles in the team for the user who created it. The default role is owner. A role can be any string. Learn more about [roles and permissions](/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long.

Returns:

  • (Team)


55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/appwrite/services/teams.rb', line 55

def create(team_id:, name:, roles: nil)
    if team_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    if name.nil?
        raise Appwrite::Exception.new('Missing required parameter: "name"')
    end

    path = '/teams'

    params = {
        teamId: team_id,
        name: name,
        roles: roles,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Team
    )
end

#create_membership(team_id:, email:, roles:, url:, name: nil) ⇒ Membership

Invite a new member to join your team. If initiated from the client SDK, an email with a link to join the team will be sent to the member’s email address and an account will be created for them should they not be signed up already. If initiated from server-side SDKs, the new member will automatically be added to the team.

Use the ‘url’ parameter to redirect the user from the invitation email back to your app. When the user is redirected, use the [Update Team Membership Status](/docs/client/teams#teamsUpdateMembershipStatus) endpoint to allow the user to accept the invitation to the team.

Please note that to avoid a [Redirect Attack](github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.md) the only valid redirect URL’s are the once from domains you have set when adding your platforms in the console interface.

Parameters:

  • team_id (string)

    Team ID.

  • email (string)

    Email of the new team member.

  • roles (array)

    Array of strings. Use this param to set the user roles in the team. A role can be any string. Learn more about [roles and permissions](/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long.

  • url (string)

    URL to redirect the user back to your app from the invitation email. Only URLs from hostnames in your project platform list are allowed. This requirement helps to prevent an [open redirect](cheatsheetseries.owasp.org/cheatsheets/Unvalidated_Redirects_and_Forwards_Cheat_Sheet.html) attack against your project API.

  • name (string) (defaults to: nil)

    Name of the new team member. Max length: 128 chars.

Returns:

  • (Membership)


244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
# File 'lib/appwrite/services/teams.rb', line 244

def create_membership(team_id:, email:, roles:, url:, name: nil)
    if team_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    if email.nil?
        raise Appwrite::Exception.new('Missing required parameter: "email"')
    end

    if roles.nil?
        raise Appwrite::Exception.new('Missing required parameter: "roles"')
    end

    if url.nil?
        raise Appwrite::Exception.new('Missing required parameter: "url"')
    end

    path = '/teams/{teamId}/memberships'
        .gsub('{teamId}', team_id)

    params = {
        email: email,
        roles: roles,
        url: url,
        name: name,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'POST',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Membership
    )
end

#delete(team_id:) ⇒ Object

Delete a team using its ID. Only team members with the owner role can delete the team.

Parameters:

  • team_id (string)

    Team ID.

Returns:



156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/appwrite/services/teams.rb', line 156

def delete(team_id:)
    if team_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    path = '/teams/{teamId}'
        .gsub('{teamId}', team_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: path,
        headers: headers,
        params: params,
    )
end

#delete_membership(team_id:, membership_id:) ⇒ Object

This endpoint allows a user to leave a team or for a team owner to delete the membership of any other team member. You can also use this endpoint to delete a user membership even if it is not accepted.

Parameters:

  • team_id (string)

    Team ID.

  • membership_id (string)

    Membership ID.

Returns:



371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
# File 'lib/appwrite/services/teams.rb', line 371

def delete_membership(team_id:, membership_id:)
    if team_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    if membership_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "membershipId"')
    end

    path = '/teams/{teamId}/memberships/{membershipId}'
        .gsub('{teamId}', team_id)
        .gsub('{membershipId}', membership_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'DELETE',
        path: path,
        headers: headers,
        params: params,
    )
end

#get(team_id:) ⇒ Team

Get a team by its ID. All team members have read access for this resource.

Parameters:

  • team_id (string)

    Team ID.

Returns:

  • (Team)


90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/appwrite/services/teams.rb', line 90

def get(team_id:)
    if team_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    path = '/teams/{teamId}'
        .gsub('{teamId}', team_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Team
    )
end

#get_membership(team_id:, membership_id:) ⇒ MembershipList

Get a team member by the membership unique id. All team members have read access for this resource.

Parameters:

  • team_id (string)

    Team ID.

  • membership_id (string)

    Membership ID.

Returns:

  • (MembershipList)


291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
# File 'lib/appwrite/services/teams.rb', line 291

def get_membership(team_id:, membership_id:)
    if team_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    if membership_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "membershipId"')
    end

    path = '/teams/{teamId}/memberships/{membershipId}'
        .gsub('{teamId}', team_id)
        .gsub('{membershipId}', membership_id)

    params = {
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::MembershipList
    )
end

#get_memberships(team_id:, search: nil, limit: nil, offset: nil, cursor: nil, cursor_direction: nil, order_type: nil) ⇒ MembershipList

Use this endpoint to list a team’s members using the team’s ID. All team members have read access to this endpoint.

Parameters:

  • team_id (string)

    Team ID.

  • search (string) (defaults to: nil)

    Search term to filter your list results. Max length: 256 chars.

  • limit (number) (defaults to: nil)

    Maximum number of memberships to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.

  • offset (number) (defaults to: nil)

    Offset value. The default value is 0. Use this value to manage pagination. [learn more about pagination](appwrite.io/docs/pagination)

  • cursor (string) (defaults to: nil)

    ID of the membership used as the starting point for the query, excluding the membership itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](appwrite.io/docs/pagination)

  • cursor_direction (string) (defaults to: nil)

    Direction of the cursor, can be either 'before' or 'after'.

  • order_type (string) (defaults to: nil)

    Order result by ASC or DESC order.

Returns:

  • (MembershipList)


191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/appwrite/services/teams.rb', line 191

def get_memberships(team_id:, search: nil, limit: nil, offset: nil, cursor: nil, cursor_direction: nil, order_type: nil)
    if team_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    path = '/teams/{teamId}/memberships'
        .gsub('{teamId}', team_id)

    params = {
        search: search,
        limit: limit,
        offset: offset,
        cursor: cursor,
        cursorDirection: cursor_direction,
        orderType: order_type,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::MembershipList
    )
end

#list(search: nil, limit: nil, offset: nil, cursor: nil, cursor_direction: nil, order_type: nil) ⇒ TeamList

Get a list of all the teams in which the current user is a member. You can use the parameters to filter your results.

In admin mode, this endpoint returns a list of all the teams in the current project. [Learn more about different API modes](/docs/admin).

Parameters:

  • search (string) (defaults to: nil)

    Search term to filter your list results. Max length: 256 chars.

  • limit (number) (defaults to: nil)

    Maximum number of teams to return in response. By default will return maximum 25 results. Maximum of 100 results allowed per request.

  • offset (number) (defaults to: nil)

    Offset value. The default value is 0. Use this param to manage pagination. [learn more about pagination](appwrite.io/docs/pagination)

  • cursor (string) (defaults to: nil)

    ID of the team used as the starting point for the query, excluding the team itself. Should be used for efficient pagination when working with large sets of data. [learn more about pagination](appwrite.io/docs/pagination)

  • cursor_direction (string) (defaults to: nil)

    Direction of the cursor, can be either 'before' or 'after'.

  • order_type (string) (defaults to: nil)

    Order result by ASC or DESC order.

Returns:

  • (TeamList)


21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/appwrite/services/teams.rb', line 21

def list(search: nil, limit: nil, offset: nil, cursor: nil, cursor_direction: nil, order_type: nil)
    path = '/teams'

    params = {
        search: search,
        limit: limit,
        offset: offset,
        cursor: cursor,
        cursorDirection: cursor_direction,
        orderType: order_type,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'GET',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::TeamList
    )
end

#update(team_id:, name:) ⇒ Team

Update a team using its ID. Only members with the owner role can update the team.

Parameters:

  • team_id (string)

    Team ID.

  • name (string)

    New team name. Max length: 128 chars.

Returns:

  • (Team)


121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
# File 'lib/appwrite/services/teams.rb', line 121

def update(team_id:, name:)
    if team_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    if name.nil?
        raise Appwrite::Exception.new('Missing required parameter: "name"')
    end

    path = '/teams/{teamId}'
        .gsub('{teamId}', team_id)

    params = {
        name: name,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'PUT',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Team
    )
end

#update_membership_roles(team_id:, membership_id:, roles:) ⇒ Membership

Modify the roles of a team member. Only team members with the owner role have access to this endpoint. Learn more about [roles and permissions](/docs/permissions).

Parameters:

  • team_id (string)

    Team ID.

  • membership_id (string)

    Membership ID.

  • roles (array)

    An array of strings. Use this param to set the user's roles in the team. A role can be any string. Learn more about [roles and permissions](appwrite.io/docs/permissions). Maximum of 100 roles are allowed, each 32 characters long.

Returns:

  • (Membership)


329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
# File 'lib/appwrite/services/teams.rb', line 329

def update_membership_roles(team_id:, membership_id:, roles:)
    if team_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    if membership_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "membershipId"')
    end

    if roles.nil?
        raise Appwrite::Exception.new('Missing required parameter: "roles"')
    end

    path = '/teams/{teamId}/memberships/{membershipId}'
        .gsub('{teamId}', team_id)
        .gsub('{membershipId}', membership_id)

    params = {
        roles: roles,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Membership
    )
end

#update_membership_status(team_id:, membership_id:, user_id:, secret:) ⇒ Membership

Use this endpoint to allow a user to accept an invitation to join a team after being redirected back to your app from the invitation email received by the user.

If the request is successful, a session for the user is automatically created.

Parameters:

  • team_id (string)

    Team ID.

  • membership_id (string)

    Membership ID.

  • user_id (string)

    User ID.

  • secret (string)

    Secret key.

Returns:

  • (Membership)


413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
# File 'lib/appwrite/services/teams.rb', line 413

def update_membership_status(team_id:, membership_id:, user_id:, secret:)
    if team_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "teamId"')
    end

    if membership_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "membershipId"')
    end

    if user_id.nil?
        raise Appwrite::Exception.new('Missing required parameter: "userId"')
    end

    if secret.nil?
        raise Appwrite::Exception.new('Missing required parameter: "secret"')
    end

    path = '/teams/{teamId}/memberships/{membershipId}/status'
        .gsub('{teamId}', team_id)
        .gsub('{membershipId}', membership_id)

    params = {
        userId: user_id,
        secret: secret,
    }

    headers = {
        "content-type": 'application/json',
    }

    @client.call(
        method: 'PATCH',
        path: path,
        headers: headers,
        params: params,
        response_type: Models::Membership
    )
end