Skip to content

Commit 2bb3d50

Browse files
committed
Add settings to enable/disable user/group sync
1 parent a915b22 commit 2bb3d50

File tree

3 files changed

+68
-40
lines changed

3 files changed

+68
-40
lines changed

plugin.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,20 @@
2222
"header": "",
2323
"footer": "",
2424
"settings": [
25+
{
26+
"key": "EnableUserSync",
27+
"display_name": "Whether or not user sync is enabled",
28+
"type": "bool",
29+
"help_text": "If enabled, new users will be created and removed users will be disabled. If disabled, user information will not be synced. Disabling this may lead to users that log in via OIDC SSO to end up with incorrect or surprising information in their profile.",
30+
"default": true
31+
},
32+
{
33+
"key": "EnableGroupSync",
34+
"display_name": "Whether or not group sync is enabled",
35+
"type": "bool",
36+
"help_text": "If enabled, users will be added/removed from teams, channels, and system roles according to their group membership. Note that if user sync is disabled, users will be synced according to their group membership as of the last time user sync was enabled.",
37+
"default": true
38+
},
2539
{
2640
"key": "EnabledGroup",
2741
"display_name": "Name of group that gates access to Mattermost in uffd",

server/configuration.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,12 @@ func (c *configurationDuration) UnmarshalJSON(data []byte) error {
3939
// If you add non-reference types to your configuration struct, be sure to rewrite Clone as a deep
4040
// copy appropriate for your types.
4141
type configuration struct {
42+
// Whether or not user sync is enabled.
43+
EnableUserSync bool
44+
45+
// Whether or not group sync is enabled.
46+
EnableGroupSync bool
47+
4248
// EnabledGroup defines the name of a group that, if a user is present in it,
4349
// causes the user to be enabled for Mattermost.
4450
// This should usually match how the OIDC service is configured in uffd.

server/job.go

Lines changed: 48 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -29,50 +29,58 @@ func (p *Plugin) runSync(ctx context.Context, trigger string) error {
2929

3030
cfg := p.getConfiguration()
3131

32-
l.Info("Performing UFFD group sync")
32+
if cfg.EnableUserSync {
33+
l.Info("Performing UFFD sync")
3334

34-
var additionalGroups []string
35-
if cfg.SystemAdminGroup != "" {
36-
additionalGroups = append(additionalGroups, cfg.SystemAdminGroup)
35+
var additionalGroups []string
36+
if cfg.SystemAdminGroup != "" {
37+
additionalGroups = append(additionalGroups, cfg.SystemAdminGroup)
38+
}
39+
se := &syncengine.SyncEngine{
40+
IDP: &syncengine.UffdIDP{
41+
API: p.uffd,
42+
EnabledGroup: cfg.EnabledGroup,
43+
},
44+
Service: &syncengine.MattermostService{
45+
API: p.API,
46+
},
47+
GroupStore: &datastore.MattermostDataStore{
48+
API: p.API,
49+
},
50+
AdditionalGroups: additionalGroups,
51+
}
52+
out, err := se.FullSync(ctx)
53+
if err != nil {
54+
l.WithError(err).Error("UFFD sync failed")
55+
return err
56+
}
57+
l.WithFields(log.Fields{"outcome": out}).Info("UFFD sync complete")
58+
} else {
59+
l.Info("UFFD sync disabled in settings")
3760
}
38-
se := &syncengine.SyncEngine{
39-
IDP: &syncengine.UffdIDP{
40-
API: p.uffd,
41-
EnabledGroup: cfg.EnabledGroup,
42-
},
43-
Service: &syncengine.MattermostService{
44-
API: p.API,
45-
},
46-
GroupStore: &datastore.MattermostDataStore{
47-
API: p.API,
48-
},
49-
AdditionalGroups: additionalGroups,
50-
}
51-
out, err := se.FullSync(ctx)
52-
if err != nil {
53-
l.WithError(err).Error("UFFD group sync failed")
54-
return err
55-
}
56-
l.WithFields(log.Fields{"outcome": out}).Info("UFFD group sync complete")
5761

58-
l.Info("Performing syncables sync")
59-
siteURL := p.API.GetConfig().ServiceSettings.SiteURL
60-
if siteURL == nil {
61-
return fmt.Errorf("site url setting is missing")
62-
}
63-
ss := &syncablesync.Engine{
64-
API: &syncablesync.Mattermost{
65-
API: p.API,
66-
REST: model.NewAPIv4Client(*siteURL),
67-
GroupStore: p.datastore(),
68-
SystemAdminGroup: cfg.SystemAdminGroup,
69-
ManagedTeam: cfg.ManagedTeam,
70-
},
71-
}
72-
if err := ss.FullSync(ctx); err != nil {
73-
l.WithError(err).Error("Syncables sync failed")
62+
if cfg.EnableGroupSync {
63+
l.Info("Performing syncables sync")
64+
siteURL := p.API.GetConfig().ServiceSettings.SiteURL
65+
if siteURL == nil {
66+
return fmt.Errorf("site url setting is missing")
67+
}
68+
ss := &syncablesync.Engine{
69+
API: &syncablesync.Mattermost{
70+
API: p.API,
71+
REST: model.NewAPIv4Client(*siteURL),
72+
GroupStore: p.datastore(),
73+
SystemAdminGroup: cfg.SystemAdminGroup,
74+
ManagedTeam: cfg.ManagedTeam,
75+
},
76+
}
77+
if err := ss.FullSync(ctx); err != nil {
78+
l.WithError(err).Error("Syncables sync failed")
79+
}
80+
l.Info("Syncables sync complete")
81+
} else {
82+
l.Info("Syncable sync disabled in settings")
7483
}
75-
l.Info("Syncables sync complete")
7684

7785
return nil
7886
}

0 commit comments

Comments
 (0)