LCOV - code coverage report
Current view: top level - lib/models - groupmembers.dart (source / functions) Hit Total Coverage
Test: lcov.info Lines: 0 40 0.0 %
Date: 2026-08-30 05:23:47 Functions: 0 0 -

          Line data    Source code
       1             : import 'package:flutter/foundation.dart';
       2             : import 'package:flutter/material.dart';
       3             : 
       4             : import '../cwtch_icons_icons.dart';
       5             : 
       6             : class GroupMember extends ChangeNotifier {
       7             :   late String _onion;
       8             :   late String _role;
       9             :   late Map<String, bool> _acl;
      10             : 
      11           0 :   GroupMember(String onion, Map<String, dynamic> acl) {
      12           0 :     this._onion = onion;
      13           0 :     this._role = acl["AssignedRole"] ?? "unknown";
      14           0 :     acl.remove("AssignedRole");
      15           0 :     this._acl = acl.cast<String, bool>();
      16             :   }
      17             : 
      18           0 :   String get onion => _onion;
      19           0 :   String get role => _role;
      20           0 :   String get aclWIP => _role + " " + _acl.entries.where((x) => x.value).map((x) => x.key).join(", ");
      21             : 
      22           0 :   static String roleL10n(String? role) {
      23             :     switch (role) {
      24           0 :       case 'admin':
      25             :         return "t9n(admin)";
      26           0 :       case 'op':
      27             :         return "t9n(op)";
      28           0 :       case 'mod':
      29             :         return "t9n(mod)";
      30           0 :       case 'voice':
      31             :         return "t9n(voice)";
      32           0 :       case 'user':
      33             :         return "t9n(user)";
      34           0 :       case 'banned':
      35             :         return "t9n(banned)";
      36             :       default:
      37             :         return 't9n(unknown role)';
      38             :     }
      39             :   }
      40             : 
      41           0 :   static Widget roleIcon(String? role, double size) {
      42             :     // *  @  %  +  -
      43           0 :     String semantic = (role ?? "unknown role") + " symbol";
      44             :     switch (role) {
      45           0 :       case 'admin':
      46           0 :         return Icon(CwtchIcons.member_admin, color: Colors.white, size: size, semanticLabel: semantic);
      47           0 :       case 'op':
      48           0 :         return Icon(CwtchIcons.member_op, color: Colors.white, size: size, semanticLabel: semantic);
      49           0 :       case 'mod':
      50           0 :         return Icon(CwtchIcons.member_mod, color: Colors.white, size: size, semanticLabel: semantic);
      51           0 :       case 'voice':
      52           0 :         return Icon(CwtchIcons.member_voice, color: Colors.white, size: size, semanticLabel: semantic);
      53           0 :       case 'user':
      54           0 :         return Icon(CwtchIcons.member_user, color: Colors.white, size: size, semanticLabel: semantic);
      55           0 :       case 'banned':
      56           0 :         return Icon(CwtchIcons.block_peer, color: Colors.white, size: size, semanticLabel: semantic);
      57             :       default:
      58           0 :         return Icon(CwtchIcons.member_user, color: Colors.white, size: size, semanticLabel: semantic);
      59             :     }
      60             :   }
      61             : 
      62             :   // this logic must perfectly match cwtch/models/roles.go::IsAbleToPromoteTo(...)
      63             :   // hence its code is replicated here 1:1 in comments
      64             :   // this client-side check has no security implications -- it is simply used to
      65             :   // prevent allowing users to perform actions that will end up forbidden by the backend
      66           0 :   static bool isAbleToPromoteTo(String? myRole, String? currentRole, String? targetRole, String modeLine) {
      67           0 :     if (myRole == 'admin') {
      68             :       //        if r.IsEffectiveAdmin() {
      69             :       return true; //           return true // admins can do anything
      70             :     } //        }
      71             :     //
      72             :     //  // no one below admin can promote/demote to admin ever
      73           0 :     if (currentRole == 'admin' || targetRole == 'admin') {
      74             :       //        if currentRole == ROLE_ADMIN || targetRole == ROLE_ADMIN {
      75             :       return false; //          return false
      76             :     } //        }
      77             :     //
      78           0 :     if (myRole == 'op') {
      79             :       //        if r == ROLE_OP {
      80           0 :       if (currentRole == 'op' || targetRole == 'op') {
      81             :         //              if currentRole == ROLE_OP || targetRole == ROLE_OP {
      82           0 :         return modeLine.contains('e'); //                       return mode.IsSet(Equality) // ops can only promote/demote ops if equality
      83             :       } else {
      84             :         //              } else {
      85             :         return true; //                 return true // op can always promote/demote below op
      86             :       } //              }
      87             :     } //        }
      88             :     //
      89             :     //  // no one below op can promote/demote op ever
      90           0 :     if (currentRole == 'op' || targetRole == 'op') {
      91             :       //        if currentRole == ROLE_OP || targetRole == ROLE_OP {
      92             :       return false; //          return false
      93             :     } //        }
      94             :     //
      95           0 :     if (myRole == 'mod') {
      96             :       //        if r == ROLE_MOD {
      97           0 :       if (currentRole == 'mod' || targetRole == 'mod') {
      98             :         //              if currentRole == ROLE_MOD || targetRole == ROLE_MOD {
      99           0 :         return modeLine.contains('e'); //                       return mode.IsSet(Equality) // ops can only promote/demote mod if equality
     100             :       } else {
     101             :         //              } else {
     102             :         return true; //                 return true // mod can always promote/demote below mode
     103             :       } //              }
     104             :     } //        }
     105             :     //
     106             :     return false; //    return false // not an admin, operator, or mod means we can never promote/demote
     107             :   }
     108             : }

Generated by: LCOV version 1.14