Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor calendar engine into its own package #267

Merged
merged 63 commits into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
00e1eb0
oauth works
mickmister Dec 11, 2020
742a49c
autocomplete
mickmister Dec 11, 2020
7f238a2
viewcal works
mickmister Dec 11, 2020
19ff374
add unimplemented if blocks
mickmister Feb 20, 2021
38ebd1f
Merge branch 'master' into migrate-to-gcal
mickmister Feb 20, 2021
a88921f
fix tests and lint
mickmister Sep 14, 2021
8259bde
implement CreateMySubscription, RenewSubscription, and DeleteSubscrip…
mickmister Sep 17, 2021
83db731
WIP gcal subs
mickmister Sep 21, 2021
b057dcf
setup-attach make target
mickmister Sep 21, 2021
863cb37
Merge branch 'master' into gcal-merge
mickmister Jul 24, 2023
38f3fdf
fix lint and tests
mickmister Jul 24, 2023
9ed5ee6
chore: more compatible tar command
fmartingr Jul 24, 2023
d78381a
add review comments
mickmister Jul 25, 2023
728630e
[GCAL] Create event logic (#269)
fmartingr Jul 25, 2023
585e821
bug: get timezone from datetime instead of event data (#271)
fmartingr Jul 26, 2023
e30acd4
[GCAL] Allow building two different plugins under the same codebase (…
fmartingr Jul 31, 2023
b139719
[GCAL] Endpoint to autocomplete connected calendar users (#275)
fmartingr Aug 1, 2023
e3d6a94
[GCAL] Refactor Microsoft Calendar references to provider references …
fmartingr Aug 1, 2023
336a906
[GCAL] Enable notifications and reminders when a superuser token is n…
fmartingr Aug 1, 2023
34ca3ed
[GCAL] Added encrypted key value storage (#270)
fmartingr Aug 1, 2023
421c8d5
[GCAL] today/tomorrow commands with styling (#273)
fmartingr Aug 1, 2023
f226b5e
[GCAL] Fix test in main branch from PR merges (#277)
fmartingr Aug 1, 2023
aa14450
[GCAL] Move configuration readyness logic to remotes (#279)
fmartingr Aug 1, 2023
d3fe76b
[GCAL] Remove unused code (#278)
fmartingr Aug 1, 2023
b345fef
[GCAL] Fix event notifications not working due to missing scope permi…
fmartingr Aug 2, 2023
eba9102
[GCAL] Unsubscriptions (#283)
fmartingr Aug 2, 2023
b3f4558
update gcal manifest (#285)
fmartingr Aug 4, 2023
23a3f23
[GCAL] Better logging information (#287)
fmartingr Aug 4, 2023
95c9a44
use correct manifest file on manifest calls (#290)
fmartingr Aug 4, 2023
735fc05
[GCAL] Embed tzdata and correctly parse location from event datetime …
fmartingr Aug 4, 2023
c47dd5e
[GCAL] Event notifications behind a feature flag (#292)
fmartingr Aug 4, 2023
7a45ad0
ignore notifications if there's no processor (#293)
fmartingr Aug 4, 2023
7f673be
[GCAL] Remove join event column (broken from merges) (#294)
fmartingr Aug 4, 2023
2a4ec5d
[GCAL] Channels reminder underlying logic (#274)
fmartingr Aug 7, 2023
1ab957a
Updated google calendar readme
fmartingr Aug 9, 2023
2ddf28b
[GCAL] Summary command fixes (#286)
fmartingr Aug 11, 2023
4eda283
[GCAL] Add a modal to create events (#281)
mickmister Aug 16, 2023
37a55c0
[GCAL/MSCAL] Store linked events per user to remove links on disconne…
fmartingr Aug 16, 2023
aeb352a
[GCAL/MSCAL] Remind only accepted events (#295)
fmartingr Aug 16, 2023
ac12e63
Remove GoogleDomainVerifyKey setting (#299)
fmartingr Aug 16, 2023
f8a8f75
fix: encrypt user store (#297)
fmartingr Aug 16, 2023
dc937e2
feat: send notifications when an event is created (#300)
fmartingr Aug 17, 2023
abd0eec
typo: user already connected message (#301)
fmartingr Aug 18, 2023
1cc2149
typo: user already connected message (#301)
fmartingr Aug 18, 2023
974d5d0
[GCAL/MSCAL] Exclude rejected events from agenda commands (#302)
fmartingr Aug 18, 2023
b6bed01
[GCAL/MSCAL] Create event modal only for connected accounts (#303)
fmartingr Aug 23, 2023
39544fd
updated settings to use style and removed current value line (#305)
fmartingr Aug 23, 2023
9ef367a
show link to connect if not connected (#306)
fmartingr Aug 23, 2023
73dfe63
[GCAL/MSCAL] Reduce welcome steps (#308)
fmartingr Aug 24, 2023
2bb4367
[GCAL/MSCAL] Control start/date times if the selected date is today (…
fmartingr Aug 24, 2023
395cbfa
database replication workaround (#312)
fmartingr Aug 28, 2023
6b8defa
[GCAL/MSCAL] Catch errors when using `findmeetings` commands without …
fmartingr Aug 29, 2023
8a728fd
Replace Equals with ElementsMatch
fmartingr Aug 30, 2023
8925e67
makefile dist build for production (#314)
fmartingr Aug 31, 2023
dfeb3d1
[GCAL/MSCAL] Create event UX improvements (#309)
fmartingr Sep 4, 2023
c1bd4d3
[GCAL] Store conference data (#298)
fmartingr Sep 6, 2023
5ef3953
Common code refactor, back to mscalendar plugin (#334)
fmartingr Oct 4, 2023
8b4065b
apped user to handle after all actions (#335)
fmartingr Oct 10, 2023
3d0dc0b
refactor msgraph to mscalendar
fmartingr Nov 6, 2023
bf4cefe
Merge remote-tracking branch 'origin/master' into migrate-to-gcal
fmartingr Feb 15, 2024
783c2f0
goimports
fmartingr Feb 15, 2024
ae5f3d8
removed apply command from merge
fmartingr Feb 15, 2024
1de44d0
remove "REVIEW:" comments
mickmister Feb 29, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
dist
.DS_Store
.npminstall
111 changes: 105 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,26 @@ CURL ?= $(shell command -v curl 2> /dev/null)
MM_DEBUG ?=
MANIFEST_FILE ?= plugin.json
GOPATH ?= $(shell go env GOPATH)

MANIFEST_FILE ?= plugin.json

GO_TEST_FLAGS ?= -race
GO_BUILD_FLAGS ?=
GO_BUILD_FLAGS ?= -tags timetzdata
MM_UTILITIES_DIR ?= ../mattermost-utilities
DLV_DEBUG_PORT := 2346
DEFAULT_GOOS := $(shell go env GOOS)
DEFAULT_GOARCH := $(shell go env GOARCH)

export GO111MODULE=on

GO_PACKAGES ?= ./server/... ./calendar/... ./msgraph/...

# You can include assets this directory into the bundle. This can be e.g. used to include profile pictures.
ASSETS_DIR ?= assets

# Repository URL
REPOSITORY_URL ?= github.com/mattermost/mattermost-plugin-mscalendar

## Define the default target (make all)
.PHONY: default
default: all
Expand All @@ -41,7 +49,7 @@ endif
.PHONY: all
all: check-style test dist

## Runs eslint and golangci-lint
## Runs golangci-lint and eslint.
.PHONY: check-style
check-style: webapp/node_modules
@echo Checking for style guide compliance
Expand Down Expand Up @@ -94,17 +102,59 @@ webapp: webapp/node_modules
ifneq ($(HAS_WEBAPP),)
ifeq ($(MM_DEBUG),)
cd webapp && $(NPM) run build;
endif

## Builds the webapp in debug mode, if it exists.
.PHONY: webapp-debug
webapp-debug: webapp/.npminstall
ifneq ($(HAS_WEBAPP),)
cd webapp && \
$(NPM) run debug;
endif

# server-debug builds and deploys a debug version of the plugin for your architecture.
# Then resets the plugin to pick up the changes.
.PHONY: server-debug
server-debug: server-debug-deploy reset

.PHONY: server-debug-deploy
server-debug-deploy: validate-go-version
mkdir -p server/dist
ifeq ($(OS),Darwin)
cd server && env GOOS=darwin GOARCH=amd64 $(GOBUILD) -gcflags "all=-N -l" -o dist/plugin-darwin-amd64;
else ifeq ($(OS),Linux)
cd server && env GOOS=linux GOARCH=amd64 $(GOBUILD) -gcflags "all=-N -l" -o dist/plugin-linux-amd64;
else ifeq ($(OS),Windows_NT)
cd server && env GOOS=windows GOARCH=amd64 $(GOBUILD) -gcflags "all=-N -l" -o dist/plugin-windows-amd64.exe;
else
cd webapp && $(NPM) run debug;
endif
endif
rm -rf dist/
mkdir -p dist/$(PLUGIN_ID)/server/dist
cp $(MANIFEST_FILE) dist/$(PLUGIN_ID)/plugin.json
cp -r server/dist/* dist/$(PLUGIN_ID)/server/dist/
mkdir -p ../mattermost-server/plugins
cp -r dist/* ../mattermost-server/plugins/

.PHONY: validate-go-version
validate-go-version: ## Validates the installed version of go against Mattermost's minimum requirement.
@if [ $(GO_MAJOR_VERSION) -gt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
exit 0 ;\
elif [ $(GO_MAJOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MAJOR_VERSION) ]; then \
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
exit 1; \
elif [ $(GO_MINOR_VERSION) -lt $(MINIMUM_SUPPORTED_GO_MINOR_VERSION) ] ; then \
echo '$(GO_VERSION_VALIDATION_ERR_MSG)';\
exit 1; \
fi

## Generates a tar bundle of the plugin for install.
.PHONY: bundle
bundle:
rm -rf dist/
mkdir -p dist/$(PLUGIN_ID)
cp $(MANIFEST_FILE) dist/$(PLUGIN_ID)/
cp $(MANIFEST_FILE) dist/$(PLUGIN_ID)/plugin.json
ifneq ($(wildcard $(ASSETS_DIR)/.),)
cp -r $(ASSETS_DIR) dist/$(PLUGIN_ID)/
endif
Expand All @@ -119,7 +169,7 @@ ifneq ($(HAS_WEBAPP),)
mkdir -p dist/$(PLUGIN_ID)/webapp
cp -r webapp/dist dist/$(PLUGIN_ID)/webapp/
endif
cd dist && tar -cvzf $(BUNDLE_NAME) $(PLUGIN_ID)
cd dist && tar -cvzf $(BUNDLE_NAME) -C $(PLUGIN_ID) .

@echo plugin built at: dist/$(BUNDLE_NAME)

Expand Down Expand Up @@ -190,7 +240,7 @@ detach: setup-attach
.PHONY: test
test: webapp/node_modules
ifneq ($(HAS_SERVER),)
$(GO) test -v $(GO_TEST_FLAGS) ./server/...
$(GO) test -v $(GO_TEST_FLAGS) $(GO_PACKAGES)
endif
ifneq ($(HAS_WEBAPP),)
cd webapp && $(NPM) run test;
Expand All @@ -200,7 +250,7 @@ endif
.PHONY: coverage
coverage: webapp/node_modules
ifneq ($(HAS_SERVER),)
$(GO) test $(GO_TEST_FLAGS) -coverprofile=server/coverage.txt ./server/...
$(GO) test $(GO_TEST_FLAGS) -coverprofile=server/coverage.txt $(GO_PACKAGES)
$(GO) tool cover -html=server/coverage.txt
endif

Expand Down Expand Up @@ -255,6 +305,55 @@ ifneq ($(HAS_WEBAPP),)
endif
rm -fr build/bin/

## Setup dlv for attaching, identifying the plugin PID for other targets.
.PHONY: setup-attach
setup-attach:
$(eval PLUGIN_PID := $(shell ps aux | grep "plugins/${PLUGIN_ID}" | grep -v "grep" | awk -F " " '{print $$2}'))
$(eval NUM_PID := $(shell echo -n ${PLUGIN_PID} | wc -w))

@if [ ${NUM_PID} -gt 2 ]; then \
echo "** There is more than 1 plugin process running. Run 'make kill reset' to restart just one."; \
exit 1; \
fi

## Check if setup-attach succeeded.
.PHONY: check-attach
check-attach:
@if [ -z ${PLUGIN_PID} ]; then \
echo "Could not find plugin PID; the plugin is not running. Exiting."; \
exit 1; \
else \
echo "Located Plugin running with PID: ${PLUGIN_PID}"; \
fi

## Attach dlv to an existing plugin instance.
.PHONY: attach
attach: setup-attach check-attach
dlv attach ${PLUGIN_PID}

## Attach dlv to an existing plugin instance, exposing a headless instance on $DLV_DEBUG_PORT.
.PHONY: attach-headless
attach-headless: setup-attach check-attach
dlv attach ${PLUGIN_PID} --listen :$(DLV_DEBUG_PORT) --headless=true --api-version=2 --accept-multiclient

## Detach dlv from an existing plugin instance, if previously attached.
.PHONY: detach
detach: setup-attach
@DELVE_PID=$(shell ps aux | grep "dlv attach ${PLUGIN_PID}" | grep -v "grep" | awk -F " " '{print $$2}') && \
if [ "$$DELVE_PID" -gt 0 ] > /dev/null 2>&1 ; then \
echo "Located existing delve process running with PID: $$DELVE_PID. Killing." ; \
kill -9 $$DELVE_PID ; \
fi

## Kill all instances of the plugin, detaching any existing dlv instance.
.PHONY: kill
kill: detach
$(eval PLUGIN_PID := $(shell ps aux | grep "plugins/${PLUGIN_ID}" | grep -v "grep" | awk -F " " '{print $$2}'))

@for PID in ${PLUGIN_PID}; do \
echo "Killing plugin pid $$PID"; \
kill -9 $$PID; \
done; \
# Help documentation à la https://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
@cat Makefile build/*.mk | grep -v '\.PHONY' | grep -v '\help:' | grep -B1 -E '^[a-zA-Z0-9_.-]+:.*' | sed -e "s/:.*//" | sed -e "s/^## //" | grep -v '\-\-' | sed '1!G;h;$$!d' | awk 'NR%2{printf "\033[36m%-30s\033[0m",$$0;next;}1' | sort
File renamed without changes
File renamed without changes
36 changes: 18 additions & 18 deletions build/custom.mk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ RUDDER_WRITE_KEY = 1d5bMvdrfWClLxgK1FvV3s4U1tg
ifdef MM_RUDDER_PLUGINS_PROD
RUDDER_WRITE_KEY = $(MM_RUDDER_PLUGINS_PROD)
endif
LDFLAGS += -X "github.com/mattermost/mattermost-plugin-mscalendar/server/telemetry.rudderWriteKey=$(RUDDER_WRITE_KEY)"
LDFLAGS += -X "$(REPOSITORY_URL)/server/telemetry.rudderWriteKey=$(RUDDER_WRITE_KEY)"

# Build info
BUILD_DATE = $(shell date -u)
Expand All @@ -21,25 +21,25 @@ GO_BUILD_FLAGS = -ldflags '$(LDFLAGS)'
mock:
ifneq ($(HAS_SERVER),)
go install github.com/golang/mock/[email protected]
mockgen -destination server/jobs/mock_cluster/mock_cluster.go github.com/mattermost/mattermost/server/public/pluginapi/cluster JobPluginAPI
mockgen -destination server/mscalendar/mock_mscalendar/mock_mscalendar.go github.com/mattermost/mattermost-plugin-mscalendar/server/mscalendar MSCalendar
mockgen -destination server/mscalendar/mock_welcomer/mock_welcomer.go -package mock_welcomer github.com/mattermost/mattermost-plugin-mscalendar/server/mscalendar Welcomer
mockgen -destination server/mscalendar/mock_plugin_api/mock_plugin_api.go -package mock_plugin_api github.com/mattermost/mattermost-plugin-mscalendar/server/mscalendar PluginAPI
mockgen -destination server/remote/mock_remote/mock_remote.go github.com/mattermost/mattermost-plugin-mscalendar/server/remote Remote
mockgen -destination server/remote/mock_remote/mock_client.go github.com/mattermost/mattermost-plugin-mscalendar/server/remote Client
mockgen -destination server/utils/bot/mock_bot/mock_poster.go github.com/mattermost/mattermost-plugin-mscalendar/server/utils/bot Poster
mockgen -destination server/utils/bot/mock_bot/mock_admin.go github.com/mattermost/mattermost-plugin-mscalendar/server/utils/bot Admin
mockgen -destination server/utils/bot/mock_bot/mock_logger.go github.com/mattermost/mattermost-plugin-mscalendar/server/utils/bot Logger
mockgen -destination server/store/mock_store/mock_store.go github.com/mattermost/mattermost-plugin-mscalendar/server/store Store
mockgen -destination calendar/jobs/mock_cluster/mock_cluster.go github.com/mattermost/mattermost-plugin-api/cluster JobPluginAPI
mockgen -destination calendar/engine/mock_engine/mock_engine.go $(REPOSITORY_URL)/calendar/engine Engine
mockgen -destination calendar/engine/mock_welcomer/mock_welcomer.go -package mock_welcomer $(REPOSITORY_URL)/calendar/engine Welcomer
mockgen -destination calendar/engine/mock_plugin_api/mock_plugin_api.go -package mock_plugin_api $(REPOSITORY_URL)/calendar/engine PluginAPI
mockgen -destination calendar/remote/mock_remote/mock_remote.go $(REPOSITORY_URL)/calendar/remote Remote
mockgen -destination calendar/remote/mock_remote/mock_client.go $(REPOSITORY_URL)/calendar/remote Client
mockgen -destination calendar/utils/bot/mock_bot/mock_poster.go $(REPOSITORY_URL)/calendar/utils/bot Poster
mockgen -destination calendar/utils/bot/mock_bot/mock_admin.go $(REPOSITORY_URL)/calendar/utils/bot Admin
mockgen -destination calendar/utils/bot/mock_bot/mock_logger.go $(REPOSITORY_URL)/calendar/utils/bot Logger
mockgen -destination calendar/store/mock_store/mock_store.go $(REPOSITORY_URL)/calendar/store Store
endif

clean_mock:
ifneq ($(HAS_SERVER),)
rm -rf ./server/jobs/mock_cluster
rm -rf ./server/mscalendar/mock_mscalendar
rm -rf ./server/mscalendar/mock_welcomer
rm -rf ./server/mscalendar/mock_plugin_api
rm -rf ./server/remote/mock_remote
rm -rf ./server/utils/bot/mock_bot
rm -rf ./server/store/mock_store
rm -rf ./calendar/jobs/mock_cluster
rm -rf ./calendar/engine/mock_engine
rm -rf ./calendar/engine/mock_welcomer
rm -rf ./calendar/engine/mock_plugin_api
rm -rf ./calendar/remote/mock_remote
rm -rf ./calendar/utils/bot/mock_bot
rm -rf ./calendar/store/mock_store
endif
12 changes: 9 additions & 3 deletions build/manifest/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,16 @@ func main() {
}

func findManifest() (*model.Manifest, error) {
_, manifestFilePath, err := model.FindManifest(".")
if err != nil {
return nil, errors.Wrap(err, "failed to find manifest in current working directory")
manifestFilePath := os.Getenv("MANIFEST_FILE")

if manifestFilePath == "" {
var err error
_, manifestFilePath, err = model.FindManifest(".")
if err != nil {
return nil, errors.Wrap(err, "failed to find manifest in current working directory")
}
}

manifestFile, err := os.Open(manifestFilePath)
if err != nil {
return nil, errors.Wrapf(err, "failed to open %s", manifestFilePath)
Expand Down
9 changes: 5 additions & 4 deletions build/setup.mk
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,23 @@ $(shell cd build/manifest && $(GO) build -o ../bin/manifest)
$(shell cd build/pluginctl && $(GO) build -o ../bin/pluginctl)

# Extract the plugin id from the manifest.
PLUGIN_ID ?= $(shell build/bin/manifest id)
# TODO: Not working
PLUGIN_ID ?= $(shell MANIFEST_FILE=$(MANIFEST_FILE) build/bin/manifest id)
ifeq ($(PLUGIN_ID),)
$(error "Cannot parse id from $(MANIFEST_FILE)")
endif

# Extract the plugin version from the manifest.
PLUGIN_VERSION ?= $(shell build/bin/manifest version)
PLUGIN_VERSION ?= $(shell MANIFEST_FILE=$(MANIFEST_FILE) build/bin/manifest version)
ifeq ($(PLUGIN_VERSION),)
$(error "Cannot parse version from $(MANIFEST_FILE)")
endif

# Determine if a server is defined in the manifest.
HAS_SERVER ?= $(shell build/bin/manifest has_server)
HAS_SERVER ?= $(shell MANIFEST_FILE=$(MANIFEST_FILE) build/bin/manifest has_server)

# Determine if a webapp is defined in the manifest.
HAS_WEBAPP ?= $(shell build/bin/manifest has_webapp)
HAS_WEBAPP ?= $(shell MANIFEST_FILE=$(MANIFEST_FILE) build/bin/manifest has_webapp)

# Determine if a /public folder is in use
HAS_PUBLIC ?= $(wildcard public/.)
Expand Down
3 changes: 3 additions & 0 deletions calendar/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Calendar Plugin API

This file contain the common logic for creating Calendar plugins for Mattermost.
28 changes: 22 additions & 6 deletions server/api/api.go → calendar/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,25 @@
package api

import (
"github.com/mattermost/mattermost-plugin-mscalendar/server/config"
"github.com/mattermost/mattermost-plugin-mscalendar/server/mscalendar"
"github.com/mattermost/mattermost-plugin-mscalendar/server/utils/httputils"
"net/http"

"github.com/mattermost/mattermost-plugin-mscalendar/calendar/config"
"github.com/mattermost/mattermost-plugin-mscalendar/calendar/engine"
"github.com/mattermost/mattermost-plugin-mscalendar/calendar/utils/httputils"
)

type api struct {
mscalendar.Env
mscalendar.NotificationProcessor
engine.Env
engine.NotificationProcessor
}

// Init initializes the router.
func Init(h *httputils.Handler, env mscalendar.Env, notificationProcessor mscalendar.NotificationProcessor) {
func Init(h *httputils.Handler, env engine.Env, notificationProcessor engine.NotificationProcessor) {
api := &api{
Env: env,
NotificationProcessor: notificationProcessor,
}

apiRouter := h.Router.PathPrefix(config.PathAPI).Subrouter()
apiRouter.HandleFunc("/authorized", api.getAuthorized).Methods("GET")

Expand All @@ -32,4 +35,17 @@ func Init(h *httputils.Handler, env mscalendar.Env, notificationProcessor mscale
postActionRouter.HandleFunc(config.PathTentative, api.postActionTentative).Methods("POST")
postActionRouter.HandleFunc(config.PathRespond, api.postActionRespond).Methods("POST")
postActionRouter.HandleFunc(config.PathConfirmStatusChange, api.postActionConfirmStatusChange).Methods("POST")

dialogRouter := h.Router.PathPrefix(config.PathAutocomplete).Subrouter()
dialogRouter.HandleFunc(config.PathUsers, api.autocompleteConnectedUsers)

apiRoutes := h.Router.PathPrefix(config.InternalAPIPath).Subrouter()
eventsRouter := apiRoutes.PathPrefix(config.PathEvents).Subrouter()
eventsRouter.HandleFunc(config.PathCreate, api.createEvent).Methods("POST")
apiRoutes.HandleFunc(config.PathConnectedUser, api.connectedUserHandler)

// Returns provider information for the plugin to use
apiRoutes.HandleFunc(config.PathProvider, func(w http.ResponseWriter, r *http.Request) {
httputils.WriteJSONResponse(w, config.Provider, 200)
})
}
34 changes: 34 additions & 0 deletions calendar/api/autocomplete.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package api

import (
"errors"
"fmt"
"net/http"

"github.com/mattermost/mattermost-plugin-mscalendar/calendar/store"
"github.com/mattermost/mattermost-plugin-mscalendar/calendar/utils"
"github.com/mattermost/mattermost-plugin-mscalendar/calendar/utils/bot"
"github.com/mattermost/mattermost-plugin-mscalendar/calendar/utils/httputils"
)

func (api *api) autocompleteConnectedUsers(w http.ResponseWriter, r *http.Request) {
mattermostUserID := r.Header.Get("Mattermost-User-Id")
_, err := api.Store.LoadUser(mattermostUserID)
if mattermostUserID == "" || errors.Is(err, store.ErrNotFound) {
httputils.WriteUnauthorizedError(w, fmt.Errorf("unauthorized"))
return
}

searchString := r.URL.Query().Get("search")
results, err := api.Store.SearchInUserIndex(searchString, 10)
if err != nil {
utils.SlackAttachmentError(w, "unable to search in user index: "+err.Error())
httputils.WriteInternalServerError(w, err)
return
}

if err := httputils.WriteJSONResponse(w, results.ToDTO(), http.StatusOK); err != nil {
api.Logger.With(bot.LogContext{"err": err.Error()}).Errorf("error sending response to user")
httputils.WriteInternalServerError(w, err)
}
}
Loading
Loading