From d0b21f3c5a29d40a03919000f23943c66a2766e7 Mon Sep 17 00:00:00 2001 From: Scott Lee Davis Date: Sat, 4 May 2019 20:22:30 -0700 Subject: [PATCH 1/2] centralized siteURL. Use 127.0.0.1 + ListenAddress for plugin URL --- plugin.json | 2 +- server/activate.go | 1 + server/http.go | 6 ++---- server/list.go | 37 ++++++++++++++++++------------------- server/manifest.go | 2 +- server/plugin.go | 2 ++ server/reminder.go | 11 +++++------ server/scheduler.go | 9 +++------ 8 files changed, 33 insertions(+), 37 deletions(-) diff --git a/plugin.json b/plugin.json index 92e1cb8..440cb45 100755 --- a/plugin.json +++ b/plugin.json @@ -2,7 +2,7 @@ "id": "com.github.scottleedavis.mattermost-plugin-remind", "name": "Remind Bot Mattermost Plugin", "description": "Sets Reminders", - "version": "0.2.1", + "version": "0.2.1-issue_88", "server": { "executables": { "linux-amd64": "server/dist/plugin-linux-amd64", diff --git a/server/activate.go b/server/activate.go index b7244ca..e82b66d 100755 --- a/server/activate.go +++ b/server/activate.go @@ -54,6 +54,7 @@ func (p *Plugin) OnActivate() error { p.emptyTime = time.Time{}.AddDate(1, 1, 1) p.supportedLocales = []string{"en"} p.ServerConfig = p.API.GetConfig() + p.siteURL = "http://127.0.0.1" + fmt.Sprintf("%s", *p.ServerConfig.ServiceSettings.ListenAddress) p.Run() diff --git a/server/http.go b/server/http.go index 7b7cc54..9a6421b 100755 --- a/server/http.go +++ b/server/http.go @@ -127,8 +127,6 @@ func (p *Plugin) handleDialog(w http.ResponseWriter, req *http.Request) { ), } - siteURL := fmt.Sprintf("%s", *p.ServerConfig.ServiceSettings.SiteURL) - reminder := &model.Post{ ChannelId: request.ChannelId, UserId: p.remindUserId, @@ -145,7 +143,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", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/delete/ephemeral", p.siteURL, manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.delete"), @@ -158,7 +156,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", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/view/ephemeral", p.siteURL, manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.view.reminders"), diff --git a/server/list.go b/server/list.go index 55ca3d8..41496ac 100755 --- a/server/list.go +++ b/server/list.go @@ -246,8 +246,8 @@ func (p *Plugin) listControl( attachments []*model.SlackAttachment) []*model.SlackAttachment { T, _ := p.translation(user) - siteURL := fmt.Sprintf("%s", *p.ServerConfig.ServiceSettings.SiteURL) - if siteURL == "" { + + if p.siteURL == "" { p.API.LogError("SiteURL not set.") return []*model.SlackAttachment{} } @@ -280,7 +280,7 @@ func (p *Plugin) listControl( "action": "next/reminders", "offset": endOffset + 1, }, - URL: fmt.Sprintf("%s/plugins/%s/next/reminders", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/next/reminders", p.siteURL, manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.next.reminders", reminderCount), @@ -295,7 +295,7 @@ func (p *Plugin) listControl( "action": "previous/reminders", "offset": offset - RemindersPerPage, }, - URL: fmt.Sprintf("%s/plugins/%s/next/reminders", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/next/reminders", p.siteURL, manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.previous.reminders", reminderCount), @@ -310,7 +310,7 @@ func (p *Plugin) listControl( "action": "previous/reminders", "offset": offset - RemindersPerPage, }, - URL: fmt.Sprintf("%s/plugins/%s/next/reminders", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/next/reminders", p.siteURL, manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.previous.reminders", reminderCount), @@ -322,7 +322,7 @@ func (p *Plugin) listControl( "action": "next/reminders", "offset": endOffset + 1, }, - URL: fmt.Sprintf("%s/plugins/%s/next/reminders", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/next/reminders", p.siteURL, manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.next.reminders", reminderCount), @@ -340,7 +340,7 @@ func (p *Plugin) listControl( Context: model.StringInterface{ "action": "view/complete/list", }, - URL: fmt.Sprintf("%s/plugins/%s/view/complete/list", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/view/complete/list", p.siteURL, manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.view.complete"), @@ -352,7 +352,7 @@ func (p *Plugin) listControl( Context: model.StringInterface{ "action": "delete/complete/list", }, - URL: fmt.Sprintf("%s/plugins/%s/delete/complete/list", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/delete/complete/list", p.siteURL, manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.delete.complete"), @@ -366,7 +366,7 @@ func (p *Plugin) listControl( Context: model.StringInterface{ "action": "close/list", }, - URL: fmt.Sprintf("%s/plugins/%s/close/list", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/close/list", p.siteURL, manifest.Id), }, Name: T("button.close.list"), Type: "action", @@ -383,8 +383,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder location := p.location(user) T, _ := p.translation(user) - siteURL := fmt.Sprintf("%s", *p.ServerConfig.ServiceSettings.SiteURL) - if siteURL == "" { + if p.siteURL == "" { p.API.LogError("SiteURL not set.") return &model.SlackAttachment{} } @@ -425,7 +424,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "occurrence_id": occurrence.Id, "action": "complete/list", }, - URL: fmt.Sprintf("%s/plugins/%s/complete/list", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/complete/list", p.siteURL, manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.complete"), @@ -437,7 +436,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "occurrence_id": occurrence.Id, "action": "delete/list", }, - URL: fmt.Sprintf("%s/plugins/%s/delete/list", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/delete/list", p.siteURL, manifest.Id), }, Name: T("button.delete"), Type: model.POST_ACTION_TYPE_BUTTON, @@ -461,7 +460,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "occurrence_id": occurrence.Id, "action": "delete/list", }, - URL: fmt.Sprintf("%s/plugins/%s/delete/list", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/delete/list", p.siteURL, manifest.Id), }, Name: T("button.delete"), Type: model.POST_ACTION_TYPE_BUTTON, @@ -485,7 +484,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "occurrence_id": occurrence.Id, "action": "complete/list", }, - URL: fmt.Sprintf("%s/plugins/%s/complete/list", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/complete/list", p.siteURL, manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.complete"), @@ -497,7 +496,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "occurrence_id": occurrence.Id, "action": "delete/list", }, - URL: fmt.Sprintf("%s/plugins/%s/delete/list", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/delete/list", p.siteURL, manifest.Id), }, Name: T("button.delete"), Type: model.POST_ACTION_TYPE_BUTTON, @@ -509,7 +508,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "occurrence_id": occurrence.Id, "action": "snooze/list", }, - URL: fmt.Sprintf("%s/plugins/%s/snooze/list", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/snooze/list", p.siteURL, manifest.Id), }, Name: T("button.snooze"), Type: "select", @@ -555,7 +554,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "occurrence_id": occurrence.Id, "action": "complete/list", }, - URL: fmt.Sprintf("%s/plugins/%s/complete/list", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/complete/list", p.siteURL, manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.complete"), @@ -567,7 +566,7 @@ func (p *Plugin) addAttachment(user *model.User, occurrence Occurrence, reminder "occurrence_id": occurrence.Id, "action": "delete/list", }, - URL: fmt.Sprintf("%s/plugins/%s/delete/list", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/delete/list", p.siteURL, manifest.Id), }, Name: T("button.delete"), Type: model.POST_ACTION_TYPE_BUTTON, diff --git a/server/manifest.go b/server/manifest.go index c964d8e..e04bb5d 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.2.1", + Version: "0.2.1-issue_88", } diff --git a/server/plugin.go b/server/plugin.go index 229d5c1..3830e3a 100755 --- a/server/plugin.go +++ b/server/plugin.go @@ -16,6 +16,8 @@ type Plugin struct { ServerConfig *model.Config + siteURL string + remindUserId string running bool diff --git a/server/reminder.go b/server/reminder.go index f1089cb..3b7a642 100755 --- a/server/reminder.go +++ b/server/reminder.go @@ -114,8 +114,7 @@ func (p *Plugin) TriggerReminders() { "Message": reminder.Message, } - siteURL := fmt.Sprintf("%s", *p.ServerConfig.ServiceSettings.SiteURL) - if siteURL == "" { + if p.siteURL == "" { p.API.LogError("SiteURL not set.") return } @@ -141,7 +140,7 @@ func (p *Plugin) TriggerReminders() { "occurrence_id": occurrence.Id, "action": "complete", }, - URL: fmt.Sprintf("%s/plugins/%s/complete", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/complete", p.siteURL, manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.complete"), @@ -153,7 +152,7 @@ func (p *Plugin) TriggerReminders() { "occurrence_id": occurrence.Id, "action": "delete", }, - URL: fmt.Sprintf("%s/plugins/%s/delete", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/delete", p.siteURL, manifest.Id), }, Name: T("button.delete"), Type: "action", @@ -165,7 +164,7 @@ func (p *Plugin) TriggerReminders() { "occurrence_id": occurrence.Id, "action": "snooze", }, - URL: fmt.Sprintf("%s/plugins/%s/snooze", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/snooze", p.siteURL, manifest.Id), }, Name: T("button.snooze"), Type: "select", @@ -216,7 +215,7 @@ func (p *Plugin) TriggerReminders() { "occurrence_id": occurrence.Id, "action": "snooze", }, - URL: fmt.Sprintf("%s/plugins/%s/snooze", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/snooze", p.siteURL, manifest.Id), }, Name: T("button.snooze"), Type: "select", diff --git a/server/scheduler.go b/server/scheduler.go index 5b22075..0265f83 100755 --- a/server/scheduler.go +++ b/server/scheduler.go @@ -69,8 +69,6 @@ func (p *Plugin) ScheduleReminder(request *ReminderRequest, channelId string) (* ), } - siteURL := fmt.Sprintf("%s", *p.ServerConfig.ServiceSettings.SiteURL) - return &model.Post{ ChannelId: channelId, UserId: p.remindUserId, @@ -87,7 +85,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", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/delete/ephemeral", p.siteURL, manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.delete"), @@ -100,7 +98,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", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/view/ephemeral", p.siteURL, manifest.Id), }, Type: model.POST_ACTION_TYPE_BUTTON, Name: T("button.view.reminders"), @@ -116,11 +114,10 @@ func (p *Plugin) ScheduleReminder(request *ReminderRequest, channelId string) (* func (p *Plugin) InteractiveSchedule(triggerId string, user *model.User) { T, _ := p.translation(user) - siteURL := fmt.Sprintf("%s", *p.ServerConfig.ServiceSettings.SiteURL) dialogRequest := model.OpenDialogRequest{ TriggerId: triggerId, - URL: fmt.Sprintf("%s/plugins/%s/dialog", siteURL, manifest.Id), + URL: fmt.Sprintf("%s/plugins/%s/dialog", p.siteURL, manifest.Id), Dialog: model.Dialog{ Title: T("schedule.reminder"), CallbackId: model.NewId(), From 249a3a8566bc59ce92676f200091d0aa01843c20 Mon Sep 17 00:00:00 2001 From: Scott Lee Davis Date: Sat, 4 May 2019 20:30:43 -0700 Subject: [PATCH 2/2] version bump --- plugin.json | 2 +- server/manifest.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/plugin.json b/plugin.json index 440cb45..c83e9ef 100755 --- a/plugin.json +++ b/plugin.json @@ -2,7 +2,7 @@ "id": "com.github.scottleedavis.mattermost-plugin-remind", "name": "Remind Bot Mattermost Plugin", "description": "Sets Reminders", - "version": "0.2.1-issue_88", + "version": "0.2.2", "server": { "executables": { "linux-amd64": "server/dist/plugin-linux-amd64", diff --git a/server/manifest.go b/server/manifest.go index e04bb5d..b10df54 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.2.1-issue_88", + Version: "0.2.2", }