Skip to content

Commit a915b22

Browse files
committed
Use the actual 'should be system admin' group instead of the system admin role
This allows us to demote system admins again if they're no longer in the group, as intended.
1 parent 6d6d6de commit a915b22

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

server/syncablesync/mattermostservice.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -442,16 +442,15 @@ func (m *Mattermost) UnremovableUserIDs(ctx context.Context) ([]string, error) {
442442

443443
// For Mattermost, just use 'is system admin' as a proxy for 'should not be automatically removed from channels they shouldn't be in'.
444444
// Note that if someone is promoted to a system admin at the same time as they would be removed from channels, then they will be removed in _that_ sync run.
445-
srh := &mattermostSystemRoleHandler{api: m.API}
446-
systemAdmins, err := srh.FetchRoster(ctx, SyncableTarget{
447-
Type: mattermostSyncableTypeSystemRole,
448-
ID: "system_admin",
449-
})
450-
if err != nil {
451-
return nil, err
452-
}
453-
for _, rm := range systemAdmins {
454-
out.Add(rm.UserID)
445+
if m.SystemAdminGroup != "" {
446+
sg, ok, err := m.GroupStore.LoadGroup(ctx, m.SystemAdminGroup)
447+
if err != nil {
448+
return nil, fmt.Errorf("failed to load SystemAdminGroup %q: %w", m.SystemAdminGroup, err)
449+
} else if !ok {
450+
return nil, fmt.Errorf("SystemAdminGroup set to %q but no group by that name in the KV store - does it actually exist?", m.SystemAdminGroup)
451+
}
452+
453+
out.Add(sg.MemberUserIDs...)
455454
}
456455

457456
// Exempt bots from being removed from things too.

0 commit comments

Comments
 (0)