Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add example use of UserHasBeenDeactivated hook #166

Merged
merged 1 commit into from
Aug 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion server/login_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (p *Plugin) UserHasLoggedIn(c *plugin.Context, user *model.User) {
}

for _, team := range teams {
msg := fmt.Sprintf("User @%s has logged in", user.Username)
msg := fmt.Sprintf("@%s has logged in. ID: `%s`", user.Username, user.Id)
if err := p.postPluginMessage(team.Id, msg); err != nil {
p.API.LogError(
"Failed to post UserHasLoggedIn message",
Expand Down
34 changes: 33 additions & 1 deletion server/user_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ func (p *Plugin) UserHasBeenCreated(c *plugin.Context, user *model.User) {
}

for _, team := range teams {
msg := fmt.Sprintf("User_ID @%s has been created in", user.Id)
msg := fmt.Sprintf("@%s has been created. ID: `%s`", user.Username, user.Id)
if err := p.postPluginMessage(team.Id, msg); err != nil {
p.API.LogError(
"Failed to post UserHasBeenCreated message",
Expand All @@ -38,3 +38,35 @@ func (p *Plugin) UserHasBeenCreated(c *plugin.Context, user *model.User) {
}
}
}

// UserHasBeenDeactivated is invoked when a user is made inactive.
//
// This demo implementation logs a message to the demo channel in the team whenever a user
// is deactivated.
func (p *Plugin) UserHasBeenDeactivated(c *plugin.Context, user *model.User) {
configuration := p.getConfiguration()

if configuration.disabled {
return
}

teams, err := p.API.GetTeams()
if err != nil {
p.API.LogError(
"Failed to query teams UserHasBeenDeactivated",
"error", err.Error(),
)
return
}

for _, team := range teams {
msg := fmt.Sprintf("@%s has been deactivated. ID: `%s`", user.Username, user.Id)
if err := p.postPluginMessage(team.Id, msg); err != nil {
p.API.LogError(
"Failed to post UserHasBeenDeactivated message",
"channel_id", configuration.demoChannelIDs[team.Id],
"error", err.Error(),
)
}
}
}