Skip to content
This repository has been archived by the owner on Dec 6, 2023. It is now read-only.

Commit

Permalink
centralized siteURL. Use 127.0.0.1 + ListenAddress for plugin URL
Browse files Browse the repository at this point in the history
  • Loading branch information
scottleedavis committed May 5, 2019
1 parent 99f5c1e commit d0b21f3
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 37 deletions.
2 changes: 1 addition & 1 deletion plugin.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 1 addition & 0 deletions server/activate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down
6 changes: 2 additions & 4 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"),
Expand All @@ -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"),
Expand Down
37 changes: 18 additions & 19 deletions server/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
}
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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",
Expand All @@ -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{}
}
Expand Down Expand Up @@ -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"),
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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"),
Expand All @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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"),
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion server/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
2 changes: 2 additions & 0 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ type Plugin struct {

ServerConfig *model.Config

siteURL string

remindUserId string

running bool
Expand Down
11 changes: 5 additions & 6 deletions server/reminder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand All @@ -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"),
Expand All @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
9 changes: 3 additions & 6 deletions server/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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(),
Expand Down

0 comments on commit d0b21f3

Please sign in to comment.