Skip to content

Commit

Permalink
Merge pull request #5 from mattermost/various-fixes
Browse files Browse the repository at this point in the history
Various fixes
  • Loading branch information
cpanato authored Aug 8, 2018
2 parents 9a88d56 + 52298a1 commit 4219038
Show file tree
Hide file tree
Showing 10 changed files with 71 additions and 47 deletions.
2 changes: 1 addition & 1 deletion server/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ This demo implementation logs a message to the demo channel whenever the plugin

### OnDeactivate

This demo implementation logs a debug message to the server logs whenever the plugin is activated.
This demo implementation logs a message to the demo channel whenever the plugin is deactivated.

## [configuration.go](configuration.go)

Expand Down
106 changes: 64 additions & 42 deletions server/activate_hooks.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,63 +8,85 @@ import (

// OnActivate is invoked when the plugin is activated.
//
// This demo implementation logs a message to the demo channel whenever the plugin is
// activated.
// This demo implementation logs a message to the demo channel whenever the plugin is activated.
func (p *Plugin) OnActivate() error {
// It's necessary to do this asynchronously, so as to avoid CreatePost triggering a call
// to MessageWillBePosted and deadlocking the plugin.
//
// See https://mattermost.atlassian.net/browse/MM-11431
go func() {
teams, err := p.API.GetTeams()
if err != nil {
teams, err := p.API.GetTeams()
if err != nil {
p.API.LogError(
"failed to query teams OnActivate",
"error", err.Error(),
)
}

for _, team := range teams {
if _, err := p.API.CreatePost(&model.Post{
UserId: p.demoUserId,
ChannelId: p.demoChannelIds[team.Id],
Message: fmt.Sprintf(
"OnActivate: %s", PluginId,
),
Type: "custom_demo_plugin",
Props: map[string]interface{}{
"username": p.Username,
"channel_name": p.ChannelName,
},
}); err != nil {
p.API.LogError(
"failed to query teams OnActivate",
"failed to post OnActivate message",
"error", err.Error(),
)
}

for _, team := range teams {
if _, err := p.API.CreatePost(&model.Post{
UserId: p.demoUserId,
ChannelId: p.demoChannelIds[team.Id],
Message: fmt.Sprintf(
"OnActivate: %s", PluginId,
),
Type: "custom_demo_plugin",
Props: map[string]interface{}{
"username": p.Username,
"channel_name": p.ChannelName,
},
}); err != nil {
p.API.LogError(
"failed to post OnActivate message",
"error", err.Error(),
)
}

if err := p.registerCommand(team.Id); err != nil {
p.API.LogError(
"failed to register command",
"error", err.Error(),
)
}
if err := p.registerCommand(team.Id); err != nil {
p.API.LogError(
"failed to register command",
"error", err.Error(),
)
}

}()
}

return nil
}

// OnDeactivate is invoked when the plugin is deactivated. This is the plugin's last chance to use
// the API, and the plugin will be terminated shortly after this invocation.
//
// This demo implementation logs a debug message to the server logs whenever the plugin is
// activated.
// This demo implementation logs a message to the demo channel whenever the plugin is deactivated.
func (p *Plugin) OnDeactivate() error {
// Ideally, we'd post an on deactivate message like in OnActivate, but this is hampered by
// https://mattermost.atlassian.net/browse/MM-11431?filter=15018
p.API.LogDebug("OnDeactivate")
teams, err := p.API.GetTeams()
if err != nil {
p.API.LogError(
"failed to query teams OnDeactivate",
"error", err.Error(),
)
}

for _, team := range teams {
if _, err := p.API.CreatePost(&model.Post{
UserId: p.demoUserId,
ChannelId: p.demoChannelIds[team.Id],
Message: fmt.Sprintf(
"OnDeactivate: %s", PluginId,
),
Type: "custom_demo_plugin",
Props: map[string]interface{}{
"username": p.Username,
"channel_name": p.ChannelName,
},
}); err != nil {
p.API.LogError(
"failed to post OnDeactivate message",
"error", err.Error(),
)
}

if err := p.registerCommand(team.Id); err != nil {
p.API.LogError(
"failed to register command",
"error", err.Error(),
)
}
}

return nil
}
6 changes: 2 additions & 4 deletions server/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@ func (p *Plugin) ensureDemoUser() *model.AppError {
// Ensure the configured user exists.
if user == nil {
user, err = p.API.CreateUser(&model.User{
Username: p.Username,
Password: "password",
// AuthData *string `json:"auth_data,omitempty"`
// AuthService string `json:"auth_service"`
Username: p.Username,
Password: "password",
Email: fmt.Sprintf("%[email protected]", p.Username),
Nickname: "Demo Day",
FirstName: "Demo",
Expand Down
Binary file modified webapp/docs/left_sidebar_header.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified webapp/docs/main_menu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified webapp/docs/post_type.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified webapp/docs/root.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified webapp/docs/user_actions.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified webapp/docs/user_attributes.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions webapp/src/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ export const getPluginServerRoute = (state) => {
let basePath = '/';
if (config && config.SiteURL) {
basePath = new URL(config.SiteURL).pathname;

if (basePath && basePath[basePath.length-1] === '/') {
basePath = basePath.substr(0, basePath.length-1);
}
}

return basePath + '/plugins/' + PluginId;
Expand Down

0 comments on commit 4219038

Please sign in to comment.