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

Commit

Permalink
Update to relative plugin action paths. Issue #148
Browse files Browse the repository at this point in the history
  • Loading branch information
scottleedavis committed Aug 9, 2019
1 parent 1d92e1c commit 94d9c4c
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 64 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",
"description": "Sets Reminders for users and channels",
"version": "0.4.3",
"version": "0.4.4",
"min_server_version": "5.12.0",
"server": {
"executables": {
Expand Down
2 changes: 0 additions & 2 deletions server/activate.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"fmt"
"path/filepath"
"time"

Expand Down Expand Up @@ -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")
}
Expand Down
7 changes: 0 additions & 7 deletions server/command_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions server/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand All @@ -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"),
Expand Down
14 changes: 0 additions & 14 deletions server/http_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package main
import (
"bytes"
"encoding/json"
"fmt"
"io/ioutil"
"net/http/httptest"
"testing"
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand Down
38 changes: 15 additions & 23 deletions server/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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),
Expand All @@ -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"),
Expand All @@ -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"),
Expand All @@ -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",
Expand All @@ -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
Expand Down Expand Up @@ -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"),
Expand All @@ -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,
Expand All @@ -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,
Expand All @@ -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"),
Expand All @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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"),
Expand All @@ -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,
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.4.3",
Version: "0.4.4",
}
2 changes: 0 additions & 2 deletions server/plugin.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ type Plugin struct {

ServerConfig *model.Config

URL string

remindUserId string

running bool
Expand Down
Loading

0 comments on commit 94d9c4c

Please sign in to comment.