Class: Appwrite::Teams

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Teams



6
7
8
# File 'lib/appwrite/services/teams.rb', line 6

def initialize(client)
    @client = client
end

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.



51
52
53
54
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
# File 'lib/appwrite/services/teams.rb', line 51

def create(team_id:, name:, roles: nil)
    path = '/teams'

    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

    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.



237
238
239
240
241
242
243
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
# File 'lib/appwrite/services/teams.rb', line 237

def create_membership(team_id:, email:, roles:, url:, name: nil)
    path = '/teams/{teamId}/memberships'
        .gsub('{teamId}', team_id)

    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

    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.



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

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

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

    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.



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

def delete_membership(team_id:, membership_id:)
    path = '/teams/{teamId}/memberships/{membershipId}'
        .gsub('{teamId}', team_id)
        .gsub('{membershipId}', 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

    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.



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

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

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

    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.



285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
# File 'lib/appwrite/services/teams.rb', line 285

def get_membership(team_id:, membership_id:)
    path = '/teams/{teamId}/memberships/{membershipId}'
        .gsub('{teamId}', team_id)
        .gsub('{membershipId}', 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

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

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

#list(queries: nil, search: 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).



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

def list(queries: nil, search: nil)
    path = '/teams'

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

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

#list_memberships(team_id:, queries: nil, search: 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.



187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/appwrite/services/teams.rb', line 187

def list_memberships(team_id:, queries: nil, search: nil)
    path = '/teams/{teamId}/memberships'
        .gsub('{teamId}', team_id)

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

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

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

#update(team_id:, name:) ⇒ Team

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



119
120
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
# File 'lib/appwrite/services/teams.rb', line 119

def update(team_id:, name:)
    path = '/teams/{teamId}'
        .gsub('{teamId}', team_id)

    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

    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).



324
325
326
327
328
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
# File 'lib/appwrite/services/teams.rb', line 324

def update_membership_roles(team_id:, membership_id:, roles:)
    path = '/teams/{teamId}/memberships/{membershipId}'
        .gsub('{teamId}', team_id)
        .gsub('{membershipId}', 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

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

    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.



410
411
412
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
# File 'lib/appwrite/services/teams.rb', line 410

def update_membership_status(team_id:, membership_id:, user_id:, secret:)
    path = '/teams/{teamId}/memberships/{membershipId}/status'
        .gsub('{teamId}', team_id)
        .gsub('{membershipId}', 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

    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

    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