Back

Am I not allowed to set the permission for Role team?

  • 0
  • Databases
Mosh Ontong
4 Dec, 2023, 19:31
TypeScript
  Future<ConsultationThread> createThread({
    required String memberId,
    required String consultationId,
    required String message,
  }) async {
    try {
      _logger.info('Create Thread for $memberId in $consultationId');

      final user = await account.get();

      final response = await databases.createDocument(
        databaseId: consultationThreadCredential.databaseId,
        collectionId: consultationThreadCredential.collectionId,
        documentId: app.ID.unique(),
        data: {
          'id': app.ID.unique(),
          'consultRef': consultationId,
          'authorRef': memberId,
          'author': memberId,
          'message': message,
        },
        permissions: [
          app.Permission.read(
            app.Role.team(
              consultationId,
              ConsultPermission.threadRead.code,
            ),
          ),
          app.Permission.read(
            app.Role.team(
              consultationId,
              'owner',
            ),
          ),
          app.Permission.write(
            app.Role.user(user.$id),
          ),
        ],
      );

      _logger.info('Created Thread for $memberId in $consultationId');

      return ConsultationThread.fromJson(response.data);
    } on app.AppwriteException catch (e, stackTrace) {
      _logger.severe(e.message, e, stackTrace);
      throw CreateThreadException(
        e.message ?? 'Something went wrong, please try again later',
        stackTrace,
      );
    } catch (e, stackTrace) {
      _logger.severe(e.toString(), e, stackTrace);
      throw CreateThreadException(
        e.toString(),
        stackTrace,
      );
    }
  }
TL;DR
The user wants to know if they are allowed to set the permission for Role team. In this case, they are trying to set permissions for a thread in an app. The solution provided is to create an appwrite function to set the permissions. The code snippet provided shows how to create the thread and set the permissions using the appwrite library.
Drake
4 Dec, 2023, 21:14

A user cannot put a role they don't have.

D5
4 Dec, 2023, 22:45

So instead you will need to create an appwrite function in order to set it

Mosh Ontong
5 Dec, 2023, 12:01

is this same to the storage permission?

D5
5 Dec, 2023, 13:19

Yes

Reply

Reply to this thread by joining our Discord

Reply on Discord

Need support?

Join our Discord

Get community support by joining our Discord server.

Join Discord

Get premium support

Join Appwrite Pro and get email support from our team.

Learn more