1
0
Fork 0
mirror of synced 2024-08-23 14:11:54 +12:00
appwrite/app/sdks/client-flutter/lib/services/teams.dart

203 lines
7.1 KiB
Dart
Raw Normal View History

2020-03-27 02:20:07 +13:00
2020-04-09 05:26:18 +12:00
2020-01-31 05:18:59 +13:00
import 'package:dio/dio.dart';
2020-03-27 02:20:07 +13:00
import 'package:meta/meta.dart';
2020-04-06 01:23:15 +12:00
import "../client.dart";
2020-03-27 02:20:07 +13:00
import '../enums.dart';
2020-04-06 01:23:15 +12:00
import "../service.dart";
2020-01-31 05:18:59 +13:00
class Teams extends Service {
2020-04-06 01:23:15 +12:00
Teams(Client client): super(client);
2020-01-31 05:18:59 +13:00
2020-04-11 22:02:21 +12:00
/// List Teams
///
2020-01-31 05:18:59 +13:00
/// Get a list of all the current user teams. You can use the query params to
/// filter your results. On admin mode, this endpoint will return a list of all
/// of the project teams. [Learn more about different API modes](/docs/admin).
2020-04-11 22:02:21 +12:00
///
2020-04-06 16:55:38 +12:00
Future<Response> list({String search = '', int limit = 25, int offset = 0, OrderType orderType = OrderType.asc}) {
2020-04-06 01:23:15 +12:00
final String path = '/teams';
2020-01-31 05:18:59 +13:00
2020-04-06 01:23:15 +12:00
final Map<String, dynamic> params = {
'search': search,
'limit': limit,
'offset': offset,
'orderType': orderType.name(),
};
2020-01-31 05:18:59 +13:00
2020-04-11 22:02:21 +12:00
final Map<String, String> headers = {
'content-type': 'application/json',
};
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
2020-01-31 05:18:59 +13:00
}
2020-04-11 22:02:21 +12:00
/// Create Team
///
2020-01-31 05:18:59 +13:00
/// Create a new team. The user who creates the team will automatically be
/// assigned as the owner of the team. The team owner can invite new members,
/// who will be able add new owners and update or delete the team from your
/// project.
2020-04-11 22:02:21 +12:00
///
2020-04-06 01:23:15 +12:00
Future<Response> create({@required String name, List roles = const ["owner"]}) {
final String path = '/teams';
2020-01-31 05:18:59 +13:00
2020-04-06 01:23:15 +12:00
final Map<String, dynamic> params = {
'name': name,
'roles': roles,
};
2020-01-31 05:18:59 +13:00
2020-04-11 22:02:21 +12:00
final Map<String, String> headers = {
'content-type': 'application/json',
};
return client.call(HttpMethod.post, path: path, params: params, headers: headers);
2020-01-31 05:18:59 +13:00
}
2020-04-11 22:02:21 +12:00
/// Get Team
///
2020-01-31 05:18:59 +13:00
/// Get team by its unique ID. All team members have read access for this
/// resource.
2020-04-11 22:02:21 +12:00
///
2020-04-06 01:23:15 +12:00
Future<Response> get({@required String teamId}) {
final String path = '/teams/{teamId}'.replaceAll(RegExp('{teamId}'), teamId);
2020-01-31 05:18:59 +13:00
2020-04-06 01:23:15 +12:00
final Map<String, dynamic> params = {
};
2020-01-31 05:18:59 +13:00
2020-04-11 22:02:21 +12:00
final Map<String, String> headers = {
'content-type': 'application/json',
};
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
2020-01-31 05:18:59 +13:00
}
2020-04-11 22:02:21 +12:00
/// Update Team
///
2020-01-31 05:18:59 +13:00
/// Update team by its unique ID. Only team owners have write access for this
/// resource.
2020-04-11 22:02:21 +12:00
///
2020-04-06 01:23:15 +12:00
Future<Response> update({@required String teamId, @required String name}) {
final String path = '/teams/{teamId}'.replaceAll(RegExp('{teamId}'), teamId);
2020-01-31 05:18:59 +13:00
2020-04-06 01:23:15 +12:00
final Map<String, dynamic> params = {
'name': name,
};
2020-01-31 05:18:59 +13:00
2020-04-11 22:02:21 +12:00
final Map<String, String> headers = {
'content-type': 'application/json',
};
return client.call(HttpMethod.put, path: path, params: params, headers: headers);
2020-01-31 05:18:59 +13:00
}
2020-04-11 22:02:21 +12:00
/// Delete Team
///
2020-01-31 05:18:59 +13:00
/// Delete team by its unique ID. Only team owners have write access for this
/// resource.
2020-04-11 22:02:21 +12:00
///
2020-04-06 01:23:15 +12:00
Future<Response> delete({@required String teamId}) {
final String path = '/teams/{teamId}'.replaceAll(RegExp('{teamId}'), teamId);
2020-01-31 05:18:59 +13:00
2020-04-06 01:23:15 +12:00
final Map<String, dynamic> params = {
};
2020-01-31 05:18:59 +13:00
2020-04-11 22:02:21 +12:00
final Map<String, String> headers = {
'content-type': 'application/json',
};
return client.call(HttpMethod.delete, path: path, params: params, headers: headers);
2020-01-31 05:18:59 +13:00
}
2020-04-11 22:02:21 +12:00
/// Get Team Memberships
///
2020-01-31 05:18:59 +13:00
/// Get team members by the team unique ID. All team members have read access
/// for this list of resources.
2020-04-11 22:02:21 +12:00
///
2020-04-06 01:23:15 +12:00
Future<Response> getMemberships({@required String teamId}) {
final String path = '/teams/{teamId}/memberships'.replaceAll(RegExp('{teamId}'), teamId);
2020-01-31 05:18:59 +13:00
2020-04-06 01:23:15 +12:00
final Map<String, dynamic> params = {
};
2020-01-31 05:18:59 +13:00
2020-04-11 22:02:21 +12:00
final Map<String, String> headers = {
'content-type': 'application/json',
};
return client.call(HttpMethod.get, path: path, params: params, headers: headers);
2020-01-31 05:18:59 +13:00
}
2020-04-11 22:02:21 +12:00
/// Create Team Membership
///
2020-02-14 19:28:54 +13:00
/// Use this endpoint to invite a new member to join your team. An email with a
/// link to join the team will be sent to the new member email address if the
/// member doesn't exist in the project it will be created automatically.
2020-01-31 05:18:59 +13:00
///
2020-02-14 19:28:54 +13:00
/// Use the 'URL' parameter to redirect the user from the invitation email back
2020-01-31 05:18:59 +13:00
/// to your app. When the user is redirected, use the [Update Team Membership
2020-02-14 19:28:54 +13:00
/// Status](/docs/teams#updateMembershipStatus) endpoint to allow the user to
/// accept the invitation to the team.
2020-01-31 05:18:59 +13:00
///
/// Please note that in order to avoid a [Redirect
/// Attacks](https://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
/// added your platforms in the console interface.
2020-04-11 22:02:21 +12:00
///
2020-04-06 16:55:38 +12:00
Future<Response> createMembership({@required String teamId, @required String email, @required List roles, @required String url, String name = ''}) {
2020-04-06 01:23:15 +12:00
final String path = '/teams/{teamId}/memberships'.replaceAll(RegExp('{teamId}'), teamId);
2020-01-31 05:18:59 +13:00
2020-04-06 01:23:15 +12:00
final Map<String, dynamic> params = {
'email': email,
'name': name,
'roles': roles,
'url': url,
};
2020-01-31 05:18:59 +13:00
2020-04-11 22:02:21 +12:00
final Map<String, String> headers = {
'content-type': 'application/json',
};
return client.call(HttpMethod.post, path: path, params: params, headers: headers);
2020-01-31 05:18:59 +13:00
}
2020-04-11 22:02:21 +12:00
/// Delete Team Membership
///
2020-01-31 05:18:59 +13:00
/// 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 he didn't accept it.
2020-04-11 22:02:21 +12:00
///
2020-04-06 01:23:15 +12:00
Future<Response> deleteMembership({@required String teamId, @required String inviteId}) {
final String path = '/teams/{teamId}/memberships/{inviteId}'.replaceAll(RegExp('{teamId}'), teamId).replaceAll(RegExp('{inviteId}'), inviteId);
2020-01-31 05:18:59 +13:00
2020-04-06 01:23:15 +12:00
final Map<String, dynamic> params = {
};
2020-01-31 05:18:59 +13:00
2020-04-11 22:02:21 +12:00
final Map<String, String> headers = {
'content-type': 'application/json',
};
return client.call(HttpMethod.delete, path: path, params: params, headers: headers);
2020-01-31 05:18:59 +13:00
}
2020-04-11 22:02:21 +12:00
/// Update Team Membership Status
///
2020-02-14 19:28:54 +13:00
/// Use this endpoint to allow a user to accept an invitation to join a team
/// after he is being redirected back to your app from the invitation email he
/// was sent.
2020-04-11 22:02:21 +12:00
///
2020-04-06 01:23:15 +12:00
Future<Response> updateMembershipStatus({@required String teamId, @required String inviteId, @required String userId, @required String secret}) {
final String path = '/teams/{teamId}/memberships/{inviteId}/status'.replaceAll(RegExp('{teamId}'), teamId).replaceAll(RegExp('{inviteId}'), inviteId);
2020-01-31 05:18:59 +13:00
2020-04-06 01:23:15 +12:00
final Map<String, dynamic> params = {
'userId': userId,
'secret': secret,
};
2020-01-31 05:18:59 +13:00
2020-04-11 22:02:21 +12:00
final Map<String, String> headers = {
'content-type': 'application/json',
};
return client.call(HttpMethod.patch, path: path, params: params, headers: headers);
2020-01-31 05:18:59 +13:00
}
}