@@ -31,7 +31,6 @@ use super::{
31
31
} ;
32
32
use crate :: configuration:: { GROUP_PERMISSIONS_EXTENSION_ID , SUPER_ADMIN_METADATA_PREFIX } ;
33
33
use crate :: groups:: group_mutable_metadata:: MetadataField ;
34
- use crate :: groups:: group_mutable_metadata:: MetadataField :: MessageDisappearInNS ;
35
34
36
35
/// Errors that can occur when working with GroupMutablePermissions.
37
36
#[ derive( Debug , Error ) ]
@@ -228,10 +227,22 @@ impl MetadataPolicies {
228
227
pub fn default_map ( policies : MetadataPolicies ) -> HashMap < String , MetadataPolicies > {
229
228
let mut map: HashMap < String , MetadataPolicies > = HashMap :: new ( ) ;
230
229
for field in GroupMutableMetadata :: supported_fields ( ) {
231
- if field == MessageDisappearInNS {
232
- map. insert ( field. to_string ( ) , MetadataPolicies :: allow_if_actor_admin ( ) ) ;
233
- } else {
234
- map. insert ( field. to_string ( ) , policies. clone ( ) ) ;
230
+ match field {
231
+ MetadataField :: MessageDisappearInNS => {
232
+ map. insert ( field. to_string ( ) , MetadataPolicies :: allow_if_actor_admin ( ) ) ;
233
+ }
234
+ MetadataField :: MessageDisappearFromNS => {
235
+ map. insert ( field. to_string ( ) , MetadataPolicies :: allow_if_actor_admin ( ) ) ;
236
+ }
237
+ MetadataField :: MinimumSupportedProtocolVersion => {
238
+ map. insert (
239
+ field. to_string ( ) ,
240
+ MetadataPolicies :: allow_if_actor_super_admin ( ) ,
241
+ ) ;
242
+ }
243
+ _ => {
244
+ map. insert ( field. to_string ( ) , policies. clone ( ) ) ;
245
+ }
235
246
}
236
247
}
237
248
map
@@ -960,27 +971,37 @@ impl PolicySet {
960
971
961
972
// Verify that update metadata policy was not violated
962
973
let metadata_changes_valid = self . evaluate_metadata_policy (
963
- commit. metadata_changes . metadata_field_changes . iter ( ) ,
974
+ commit
975
+ . metadata_validation_info
976
+ . metadata_field_changes
977
+ . iter ( ) ,
964
978
& self . update_metadata_policy ,
965
979
& commit. actor ,
966
980
) ;
967
981
968
982
// Verify that add admin policy was not violated
969
- let added_admins_valid = commit. metadata_changes . admins_added . is_empty ( )
983
+ let added_admins_valid = commit. metadata_validation_info . admins_added . is_empty ( )
970
984
|| self . add_admin_policy . evaluate ( & commit. actor ) ;
971
985
972
986
// Verify that remove admin policy was not violated
973
- let removed_admins_valid = commit. metadata_changes . admins_removed . is_empty ( )
987
+ let removed_admins_valid = commit. metadata_validation_info . admins_removed . is_empty ( )
974
988
|| self . remove_admin_policy . evaluate ( & commit. actor ) ;
975
989
976
990
// Verify that super admin add policy was not violated
977
- let super_admin_add_valid =
978
- commit. metadata_changes . super_admins_added . is_empty ( ) || commit. actor . is_super_admin ;
991
+ let super_admin_add_valid = commit
992
+ . metadata_validation_info
993
+ . super_admins_added
994
+ . is_empty ( )
995
+ || commit. actor . is_super_admin ;
979
996
980
997
// Verify that super admin remove policy was not violated
981
998
// You can never remove the last super admin
982
- let super_admin_remove_valid = commit. metadata_changes . super_admins_removed . is_empty ( )
983
- || ( commit. actor . is_super_admin && commit. metadata_changes . num_super_admins > 0 ) ;
999
+ let super_admin_remove_valid = commit
1000
+ . metadata_validation_info
1001
+ . super_admins_removed
1002
+ . is_empty ( )
1003
+ || ( commit. actor . is_super_admin
1004
+ && commit. metadata_validation_info . num_super_admins > 0 ) ;
984
1005
985
1006
// Permissions can only be changed by the super admin
986
1007
let permissions_changes_valid = !commit. permissions_changed || commit. actor . is_super_admin ;
@@ -1158,9 +1179,14 @@ pub fn is_policy_default(policy: &PolicySet) -> Result<bool, PolicyError> {
1158
1179
name : field_name. to_string ( ) ,
1159
1180
} ,
1160
1181
) ?;
1161
- if field_name == MessageDisappearInNS . as_str ( ) {
1182
+ if field_name == MetadataField :: MessageDisappearInNS . as_str ( )
1183
+ || field_name == MetadataField :: MessageDisappearFromNS . as_str ( )
1184
+ {
1162
1185
metadata_policies_equal = metadata_policies_equal
1163
1186
&& metadata_policy. eq ( & MetadataPolicies :: allow_if_actor_admin ( ) ) ;
1187
+ } else if field_name == MetadataField :: MinimumSupportedProtocolVersion . as_str ( ) {
1188
+ metadata_policies_equal = metadata_policies_equal
1189
+ && metadata_policy. eq ( & MetadataPolicies :: allow_if_actor_super_admin ( ) ) ;
1164
1190
} else {
1165
1191
metadata_policies_equal =
1166
1192
metadata_policies_equal && metadata_policy. eq ( & MetadataPolicies :: allow ( ) ) ;
@@ -1188,8 +1214,13 @@ pub fn is_policy_admin_only(policy: &PolicySet) -> Result<bool, PolicyError> {
1188
1214
name : field_name. to_string ( ) ,
1189
1215
} ,
1190
1216
) ?;
1191
- metadata_policies_equal = metadata_policies_equal
1192
- && metadata_policy. eq ( & MetadataPolicies :: allow_if_actor_admin ( ) ) ;
1217
+ if field_name == MetadataField :: MinimumSupportedProtocolVersion . as_str ( ) {
1218
+ metadata_policies_equal = metadata_policies_equal
1219
+ && metadata_policy. eq ( & MetadataPolicies :: allow_if_actor_super_admin ( ) ) ;
1220
+ } else {
1221
+ metadata_policies_equal = metadata_policies_equal
1222
+ && metadata_policy. eq ( & MetadataPolicies :: allow_if_actor_admin ( ) ) ;
1223
+ }
1193
1224
}
1194
1225
Ok ( metadata_policies_equal
1195
1226
&& policy. add_member_policy == MembershipPolicies :: allow_if_actor_admin ( )
@@ -1205,12 +1236,26 @@ pub fn is_policy_admin_only(policy: &PolicySet) -> Result<bool, PolicyError> {
1205
1236
pub ( crate ) fn default_policy ( ) -> PolicySet {
1206
1237
let mut metadata_policies_map: HashMap < String , MetadataPolicies > = HashMap :: new ( ) ;
1207
1238
for field in GroupMutableMetadata :: supported_fields ( ) {
1208
- metadata_policies_map. insert ( field. to_string ( ) , MetadataPolicies :: allow ( ) ) ;
1239
+ match field {
1240
+ MetadataField :: MessageDisappearInNS => {
1241
+ metadata_policies_map
1242
+ . insert ( field. to_string ( ) , MetadataPolicies :: allow_if_actor_admin ( ) ) ;
1243
+ }
1244
+ MetadataField :: MessageDisappearFromNS => {
1245
+ metadata_policies_map
1246
+ . insert ( field. to_string ( ) , MetadataPolicies :: allow_if_actor_admin ( ) ) ;
1247
+ }
1248
+ MetadataField :: MinimumSupportedProtocolVersion => {
1249
+ metadata_policies_map. insert (
1250
+ field. to_string ( ) ,
1251
+ MetadataPolicies :: allow_if_actor_super_admin ( ) ,
1252
+ ) ;
1253
+ }
1254
+ _ => {
1255
+ metadata_policies_map. insert ( field. to_string ( ) , MetadataPolicies :: allow ( ) ) ;
1256
+ }
1257
+ }
1209
1258
}
1210
- metadata_policies_map. insert (
1211
- MessageDisappearInNS . to_string ( ) ,
1212
- MetadataPolicies :: allow_if_actor_admin ( ) ,
1213
- ) ;
1214
1259
1215
1260
PolicySet :: new (
1216
1261
MembershipPolicies :: allow ( ) ,
@@ -1228,12 +1273,27 @@ pub(crate) fn default_policy() -> PolicySet {
1228
1273
pub ( crate ) fn policy_admin_only ( ) -> PolicySet {
1229
1274
let mut metadata_policies_map: HashMap < String , MetadataPolicies > = HashMap :: new ( ) ;
1230
1275
for field in GroupMutableMetadata :: supported_fields ( ) {
1231
- metadata_policies_map. insert ( field. to_string ( ) , MetadataPolicies :: allow_if_actor_admin ( ) ) ;
1276
+ match field {
1277
+ MetadataField :: MessageDisappearInNS => {
1278
+ metadata_policies_map
1279
+ . insert ( field. to_string ( ) , MetadataPolicies :: allow_if_actor_admin ( ) ) ;
1280
+ }
1281
+ MetadataField :: MessageDisappearFromNS => {
1282
+ metadata_policies_map
1283
+ . insert ( field. to_string ( ) , MetadataPolicies :: allow_if_actor_admin ( ) ) ;
1284
+ }
1285
+ MetadataField :: MinimumSupportedProtocolVersion => {
1286
+ metadata_policies_map. insert (
1287
+ field. to_string ( ) ,
1288
+ MetadataPolicies :: allow_if_actor_super_admin ( ) ,
1289
+ ) ;
1290
+ }
1291
+ _ => {
1292
+ metadata_policies_map
1293
+ . insert ( field. to_string ( ) , MetadataPolicies :: allow_if_actor_admin ( ) ) ;
1294
+ }
1295
+ }
1232
1296
}
1233
- metadata_policies_map. insert (
1234
- MetadataField :: MessageDisappearInNS . to_string ( ) ,
1235
- MetadataPolicies :: allow_if_actor_admin ( ) ,
1236
- ) ;
1237
1297
1238
1298
PolicySet :: new (
1239
1299
MembershipPolicies :: allow_if_actor_admin ( ) ,
@@ -1297,7 +1357,7 @@ pub(crate) mod tests {
1297
1357
1298
1358
use crate :: groups:: {
1299
1359
group_metadata:: DmMembers , group_mutable_metadata:: MetadataField ,
1300
- validated_commit:: MutableMetadataChanges ,
1360
+ validated_commit:: MutableMetadataValidationInfo ,
1301
1361
} ;
1302
1362
use xmtp_common:: { rand_string, rand_vec} ;
1303
1363
@@ -1388,7 +1448,7 @@ pub(crate) mod tests {
1388
1448
removed_inboxes : member_removed
1389
1449
. map ( build_membership_change)
1390
1450
. unwrap_or_default ( ) ,
1391
- metadata_changes : MutableMetadataChanges {
1451
+ metadata_validation_info : MutableMetadataValidationInfo {
1392
1452
metadata_field_changes : field_changes,
1393
1453
..Default :: default ( )
1394
1454
} ,
0 commit comments