From 1244cef09b2d4765d4c017e740011b0371fe756e Mon Sep 17 00:00:00 2001 From: scott lee davis Date: Fri, 9 Aug 2019 16:33:52 -0700 Subject: [PATCH] Update to relative plugin action paths. Issue #148 (#150) --- plugin.json | 2 +- server/activate.go | 2 -- server/command_test.go | 7 ------- server/http.go | 4 ++-- server/http_test.go | 14 -------------- server/list.go | 38 +++++++++++++++----------------------- server/manifest.go | 2 +- server/plugin.go | 2 -- server/reminder.go | 13 ++++--------- server/scheduler.go | 6 +++--- 10 files changed, 26 insertions(+), 64 deletions(-) diff --git a/plugin.json b/plugin.json index 13a71e7..01ad43a 100755 --- a/plugin.json +++ b/plugin.json @@ -2,7 +2,7 @@ "id": "com.github.scottleedavis.mattermost-plugin-remind", "name": "Remind Bot", "description": "Sets Reminders for users and channels", - "version": "0.4.3", + "version": "0.4.4", "min_server_version": "5.12.0", "server": { "executables": { diff --git a/server/activate.go b/server/activate.go index 5212958..c673640 100755 --- a/server/activate.go +++ b/server/activate.go @@ -1,7 +1,6 @@ package main import ( - "fmt" "path/filepath" "time" @@ -33,7 +32,6 @@ func (p *Plugin) OnActivate() error { } } - p.URL = fmt.Sprintf("%s", *p.ServerConfig.ServiceSettings.SiteURL) if err := p.TranslationsPreInit(); err != nil { return errors.Wrap(err, "failed to initialize translations") } diff --git a/server/command_test.go b/server/command_test.go index e023263..fc4b2b2 100644 --- a/server/command_test.go +++ b/server/command_test.go @@ -38,7 +38,6 @@ func TestHandleCommand(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -67,7 +66,6 @@ func TestHandleCommand(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -130,7 +128,6 @@ func TestHandleCommand(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -197,7 +194,6 @@ func TestHandleCommand(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -251,7 +247,6 @@ func TestHandleCommand(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -290,7 +285,6 @@ func TestHandleCommand(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -319,7 +313,6 @@ func TestHandleCommand(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api diff --git a/server/http.go b/server/http.go index 1e1cb74..ee167aa 100755 --- a/server/http.go +++ b/server/http.go @@ -142,7 +142,7 @@ func (p *Plugin) handleDialog(w http.ResponseWriter, req *http.Request) { "occurrence_id": r.Reminder.Occurrences[0].Id, "action": "delete/ephemeral", }, - URL: fmt.Sprintf("%s/plugins/%s/delete/ephemeral", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/delete/ephemeral", manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.delete"), @@ -154,7 +154,7 @@ func (p *Plugin) handleDialog(w http.ResponseWriter, req *http.Request) { "occurrence_id": r.Reminder.Occurrences[0].Id, "action": "view/ephemeral", }, - URL: fmt.Sprintf("%s/plugins/%s/view/ephemeral", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/view/ephemeral", manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.view.reminders"), diff --git a/server/http_test.go b/server/http_test.go index 56c8daf..d1fc6a6 100755 --- a/server/http_test.go +++ b/server/http_test.go @@ -3,7 +3,6 @@ package main import ( "bytes" "encoding/json" - "fmt" "io/ioutil" "net/http/httptest" "testing" @@ -38,7 +37,6 @@ func TestHandleDialog(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -115,7 +113,6 @@ func TestHandleViewEphmeral(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -201,7 +198,6 @@ func TestHandleComplete(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -284,7 +280,6 @@ func TestHandleDelete(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -365,7 +360,6 @@ func TestHandleDeleteEphemeral(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -466,7 +460,6 @@ func TestHandleSnooze(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -548,7 +541,6 @@ func TestHandleNextReminders(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -631,7 +623,6 @@ func TestHandleCompleteList(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -711,7 +702,6 @@ func TestHandleViewCompleteList(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -784,7 +774,6 @@ func TestHandleDeleteList(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -865,7 +854,6 @@ func TestHandleDeleteCompleteList(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -966,7 +954,6 @@ func TestHandleSnoozeList(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api @@ -1014,7 +1001,6 @@ func TestHandleCloseList(t *testing.T) { defer api.AssertExpectations(t) p := &Plugin{} - p.URL = fmt.Sprintf("http://localhost/plugins/%s", manifest.Id) p.router = p.InitAPI() p.API = api diff --git a/server/list.go b/server/list.go index e98c834..b5a111e 100755 --- a/server/list.go +++ b/server/list.go @@ -233,10 +233,6 @@ func (p *Plugin) listControl( T, _ := p.translation(user) - if p.URL == "" { - p.API.LogError("URL not set.") - return []*model.SlackAttachment{} - } reminderCount := map[string]interface{}{ "ReminderCount": RemindersPerPage, } @@ -266,7 +262,7 @@ func (p *Plugin) listControl( "action": "next/reminders", "offset": endOffset + 1, }, - URL: fmt.Sprintf("%s/plugins/%s/next/reminders", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/next/reminders", manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.next.reminders", reminderCount), @@ -281,7 +277,7 @@ func (p *Plugin) listControl( "action": "previous/reminders", "offset": offset - RemindersPerPage, }, - URL: fmt.Sprintf("%s/plugins/%s/next/reminders", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/next/reminders", manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.previous.reminders", reminderCount), @@ -296,7 +292,7 @@ func (p *Plugin) listControl( "action": "previous/reminders", "offset": offset - RemindersPerPage, }, - URL: fmt.Sprintf("%s/plugins/%s/next/reminders", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/next/reminders", manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.previous.reminders", reminderCount), @@ -308,7 +304,7 @@ func (p *Plugin) listControl( "action": "next/reminders", "offset": endOffset + 1, }, - URL: fmt.Sprintf("%s/plugins/%s/next/reminders", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/next/reminders", manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.next.reminders", reminderCount), @@ -326,7 +322,7 @@ func (p *Plugin) listControl( Context: model.StringInterface{ "action": "view/complete/list", }, - URL: fmt.Sprintf("%s/plugins/%s/view/complete/list", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/view/complete/list", manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.view.complete"), @@ -339,7 +335,7 @@ func (p *Plugin) listControl( "action": "delete/complete/list", "offset": offset, }, - URL: fmt.Sprintf("%s/plugins/%s/delete/complete/list", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/delete/complete/list", manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.delete.complete"), @@ -353,7 +349,7 @@ func (p *Plugin) listControl( Context: model.StringInterface{ "action": "close/list", }, - URL: fmt.Sprintf("%s/plugins/%s/close/list", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/close/list", manifest.Id), }, Name: T("button.close.list"), Type: "action", @@ -370,10 +366,6 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder location := p.location(user) T, _ := p.translation(user) - if p.URL == "" { - p.API.LogError("URL not set.") - return &model.SlackAttachment{} - } reminder := p.findReminder(reminders, occurrence) t := occurrence.Occurrence @@ -412,7 +404,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "action": "complete/list", "offset": offset, }, - URL: fmt.Sprintf("%s/plugins/%s/complete/list", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/complete/list", manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.complete"), @@ -425,7 +417,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "action": "delete/list", "offset": offset, }, - URL: fmt.Sprintf("%s/plugins/%s/delete/list", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/delete/list", manifest.Id), }, Name: T("button.delete"), Type: model.POST_ACTION_TYPE_BUTTON, @@ -450,7 +442,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "action": "delete/list", "offset": offset, }, - URL: fmt.Sprintf("%s/plugins/%s/delete/list", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/delete/list", manifest.Id), }, Name: T("button.delete"), Type: model.POST_ACTION_TYPE_BUTTON, @@ -475,7 +467,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "action": "complete/list", "offset": offset, }, - URL: fmt.Sprintf("%s/plugins/%s/complete/list", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/complete/list", manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.complete"), @@ -488,7 +480,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "action": "delete/list", "offset": offset, }, - URL: fmt.Sprintf("%s/plugins/%s/delete/list", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/delete/list", manifest.Id), }, Name: T("button.delete"), Type: model.POST_ACTION_TYPE_BUTTON, @@ -501,7 +493,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "action": "snooze/list", "offset": offset, }, - URL: fmt.Sprintf("%s/plugins/%s/snooze/list", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/snooze/list", manifest.Id), }, Name: T("button.snooze"), Type: "select", @@ -548,7 +540,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "action": "complete/list", "offset": offset, }, - URL: fmt.Sprintf("%s/plugins/%s/complete/list", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/complete/list", manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.complete"), @@ -561,7 +553,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "action": "delete/list", "offset": offset, }, - URL: fmt.Sprintf("%s/plugins/%s/delete/list", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/delete/list", manifest.Id), }, Name: T("button.delete"), Type: model.POST_ACTION_TYPE_BUTTON, diff --git a/server/manifest.go b/server/manifest.go index b1b86ec..84f890d 100755 --- a/server/manifest.go +++ b/server/manifest.go @@ -5,5 +5,5 @@ var manifest = struct { Version string }{ Id: "com.github.scottleedavis.mattermost-plugin-remind", - Version: "0.4.3", + Version: "0.4.4", } diff --git a/server/plugin.go b/server/plugin.go index e7ceff0..46c536f 100755 --- a/server/plugin.go +++ b/server/plugin.go @@ -17,8 +17,6 @@ type Plugin struct { ServerConfig *model.Config - URL string - remindUserId string running bool diff --git a/server/reminder.go b/server/reminder.go index 351d255..cc07aad 100755 --- a/server/reminder.go +++ b/server/reminder.go @@ -119,11 +119,6 @@ func (p *Plugin) TriggerReminders() { "Message": reminder.Message, } - if p.URL == "" { - p.API.LogError("URL not set.") - return - } - interactivePost := model.Post{} if occurrence.Repeat == "" { @@ -146,7 +141,7 @@ func (p *Plugin) TriggerReminders() { "occurrence_id": occurrence.Id, "action": "complete", }, - URL: fmt.Sprintf("%s/plugins/%s/complete", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/complete", manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.complete"), @@ -159,7 +154,7 @@ func (p *Plugin) TriggerReminders() { "occurrence_id": occurrence.Id, "action": "delete", }, - URL: fmt.Sprintf("%s/plugins/%s/delete", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/delete", manifest.Id), }, Name: T("button.delete"), Type: "action", @@ -172,7 +167,7 @@ func (p *Plugin) TriggerReminders() { "occurrence_id": occurrence.Id, "action": "snooze", }, - URL: fmt.Sprintf("%s/plugins/%s/snooze", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/snooze", manifest.Id), }, Name: T("button.snooze"), Type: "select", @@ -223,7 +218,7 @@ func (p *Plugin) TriggerReminders() { "occurrence_id": occurrence.Id, "action": "snooze", }, - URL: fmt.Sprintf("%s/plugins/%s/snooze", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/snooze", manifest.Id), }, Name: T("button.snooze"), Type: "select", diff --git a/server/scheduler.go b/server/scheduler.go index 5062eb4..c6b77e3 100755 --- a/server/scheduler.go +++ b/server/scheduler.go @@ -82,7 +82,7 @@ func (p *Plugin) ScheduleReminder(request *ReminderRequest, channelId string) (* "occurrence_id": request.Reminder.Occurrences[0].Id, "action": "delete/ephemeral", }, - URL: fmt.Sprintf("%s/plugins/%s/delete/ephemeral", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/delete/ephemeral", manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.delete"), @@ -95,7 +95,7 @@ func (p *Plugin) ScheduleReminder(request *ReminderRequest, channelId string) (* "occurrence_id": request.Reminder.Occurrences[0].Id, "action": "view/ephemeral", }, - URL: fmt.Sprintf("%s/plugins/%s/view/ephemeral", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/view/ephemeral", manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.view.reminders"), @@ -114,7 +114,7 @@ func (p *Plugin) InteractiveSchedule(triggerId string, user *model.User) { dialogRequest := model.OpenDialogRequest{ TriggerId: triggerId, - URL: fmt.Sprintf("%s/plugins/%s/dialog", p.URL, manifest.Id), + URL: fmt.Sprintf("/plugins/%s/dialog", manifest.Id), Dialog: model.Dialog{ Title: T("schedule.reminder"), CallbackId: model.NewId(),