Skip to content

Commit

Permalink
fix issues with validations, error handling and using correct bot user (
Browse files Browse the repository at this point in the history
#10)

* fix issues with validations, error handling and using correct bot user

* fix linter error and template
  • Loading branch information
darkLord19 authored Jul 29, 2024
1 parent 1bb2d26 commit 8d9cabd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 6 deletions.
8 changes: 4 additions & 4 deletions plugin.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"id": "com.darklord.plugin-google-drive",
"id": "com.mattermost-community.plugin-google-drive",
"name": "Google Drive Plugin",
"description": "This plugin allows you to integrate Google Drive to your Mattermost instance.",
"homepage_url": "https://github.com/darkLord/mattermost-plugin-google-drive",
"support_url": "https://github.com/mattermost/mattermost-plugin-google-drive/issues",
"homepage_url": "https://github.com/mattermost-community/mattermost-plugin-google-drive",
"support_url": "https://github.com/mattermost-community/mattermost-plugin-google-drive/issues",
"icon_path": "assets/icon.svg",
"min_server_version": "6.2.1",
"server": {
Expand All @@ -20,7 +20,7 @@
},
"settings_schema": {
"header": "The Google Drive plugin for Mattermost allows users to create, share files in Google drive and receive notifications for shared files and comments on files to stay up-to-date. \n \n Instructions for setup are [available here](https://github.com/mattermost-community/mattermost-plugin-google-drive#configuration).",
"footer": "* To report an issue, make a suggestion or a contribution, [check the repository](https://github.com/darkLord19/mattermost-plugin-google-drive).",
"footer": "* To report an issue, make a suggestion or a contribution, [check the repository](https://github.com/mattermost-community/mattermost-plugin-google-drive).",
"settings": [
{
"key": "GoogleOAuthClientID",
Expand Down
2 changes: 2 additions & 0 deletions server/plugin/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -668,6 +668,7 @@ func (p *Plugin) handleFileUpload(c *Context, w http.ResponseWriter, r *http.Req
p.API.SendEphemeralPost(c.UserID, &model.Post{
Message: "Successfully uploaded file in Google Drive.",
ChannelId: request.ChannelId,
UserId: p.BotUserID,
})
}

Expand Down Expand Up @@ -728,6 +729,7 @@ func (p *Plugin) handleAllFilesUpload(c *Context, w http.ResponseWriter, r *http
p.API.SendEphemeralPost(c.UserID, &model.Post{
Message: "Successfully uploaded all files in Google Drive.",
ChannelId: request.ChannelId,
UserId: p.BotUserID,
})
}

Expand Down
7 changes: 6 additions & 1 deletion server/plugin/disconnect.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ import (
)

func (p *Plugin) handleDisconnect(c *plugin.Context, args *model.CommandArgs, _ []string) string {
err := p.client.KV.Delete(args.UserId + "_token")
var encryptedToken []byte
_ = p.client.KV.Get(getUserTokenKey(args.UserId), &encryptedToken)
if len(encryptedToken) == 0 {
return "There is no google account connected to your mattermost account."
}
err := p.client.KV.Delete(getUserTokenKey(args.UserId))
if err != nil {
p.client.Log.Error("Failed to disconnect google account", "error", err)
return "Encountered an error disconnecting Google account."
Expand Down
20 changes: 19 additions & 1 deletion server/plugin/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,22 @@ func (p *Plugin) startDriveWatchChannel(userID string) error {
return nil
}

func isWatchChannelDataValid(watchChannelData WatchChannelData) bool {
return watchChannelData.ChannelID != "" && watchChannelData.Expiration != 0 && watchChannelData.MMUserID != "" && watchChannelData.ResourceID != ""
}

func (p *Plugin) startDriveActivityNotifications(userID string) string {
err := p.startDriveWatchChannel(userID)
var watchChannelData WatchChannelData
err := p.client.KV.Get(getWatchChannelDataKey(userID), &watchChannelData)
if err != nil {
return "Something went wrong while starting Drive activity notifications. Please contact your organization admin for support."
}

if isWatchChannelDataValid(watchChannelData) {
return "Drive activity notifications are already enabled for you."
}

err = p.startDriveWatchChannel(userID)
if err != nil {
return "Something went wrong while starting Drive activity notifications. Please contact your organization admin for support."
}
Expand All @@ -306,6 +320,10 @@ func (p *Plugin) stopDriveActivityNotifications(userID string) string {
return "Something went wrong while stopping Drive activity notifications. Please contact your organization admin for support."
}

if !isWatchChannelDataValid(watchChannelData) {
return "Drive activity notifications are not enabled for you."
}

ctx := context.Background()
conf := p.getOAuthConfig()
authToken, _ := p.getGoogleUserToken(userID)
Expand Down

0 comments on commit 8d9cabd

Please sign in to comment.