diff --git a/crm/rest/handlers/attachment.go b/crm/rest/handlers/attachment.go index 6090c44f4..675f5919a 100644 --- a/crm/rest/handlers/attachment.go +++ b/crm/rest/handlers/attachment.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/crm/rest/request" @@ -77,11 +78,9 @@ func NewAttachment(ah AttachmentAPI) *Attachment { func (ah *Attachment) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/attachment/{kind}", func(r chi.Router) { - r.Get("/", ah.List) - r.Get("/{attachmentID}", ah.Details) - r.Get("/{attachmentID}/original/{name}", ah.Original) - r.Get("/{attachmentID}/preview.{ext}", ah.Preview) - }) + r.Get("/attachment/{kind}/", ah.List) + r.Get("/attachment/{kind}/{attachmentID}", ah.Details) + r.Get("/attachment/{kind}/{attachmentID}/original/{name}", ah.Original) + r.Get("/attachment/{kind}/{attachmentID}/preview.{ext}", ah.Preview) }) } diff --git a/crm/rest/handlers/chart.go b/crm/rest/handlers/chart.go index bc074559d..3ed4ffc01 100644 --- a/crm/rest/handlers/chart.go +++ b/crm/rest/handlers/chart.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/crm/rest/request" @@ -86,12 +87,10 @@ func NewChart(ch ChartAPI) *Chart { func (ch *Chart) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/chart", func(r chi.Router) { - r.Get("/", ch.List) - r.Post("/", ch.Create) - r.Get("/{chartID}", ch.Read) - r.Post("/{chartID}", ch.Update) - r.Delete("/{chartID}", ch.Delete) - }) + r.Get("/chart/", ch.List) + r.Post("/chart/", ch.Create) + r.Get("/chart/{chartID}", ch.Read) + r.Post("/chart/{chartID}", ch.Update) + r.Delete("/chart/{chartID}", ch.Delete) }) } diff --git a/crm/rest/handlers/module.go b/crm/rest/handlers/module.go index 72e47e53e..13163c590 100644 --- a/crm/rest/handlers/module.go +++ b/crm/rest/handlers/module.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/crm/rest/request" @@ -86,12 +87,10 @@ func NewModule(mh ModuleAPI) *Module { func (mh *Module) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/module", func(r chi.Router) { - r.Get("/", mh.List) - r.Post("/", mh.Create) - r.Get("/{moduleID}", mh.Read) - r.Post("/{moduleID}", mh.Update) - r.Delete("/{moduleID}", mh.Delete) - }) + r.Get("/module/", mh.List) + r.Post("/module/", mh.Create) + r.Get("/module/{moduleID}", mh.Read) + r.Post("/module/{moduleID}", mh.Update) + r.Delete("/module/{moduleID}", mh.Delete) }) } diff --git a/crm/rest/handlers/notification.go b/crm/rest/handlers/notification.go index 362143ae4..b59a33e0d 100644 --- a/crm/rest/handlers/notification.go +++ b/crm/rest/handlers/notification.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/crm/rest/request" @@ -50,8 +51,6 @@ func NewNotification(nh NotificationAPI) *Notification { func (nh *Notification) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/notification", func(r chi.Router) { - r.Post("/email", nh.EmailSend) - }) + r.Post("/notification/email", nh.EmailSend) }) } diff --git a/crm/rest/handlers/page.go b/crm/rest/handlers/page.go index 15235402e..27a6c3729 100644 --- a/crm/rest/handlers/page.go +++ b/crm/rest/handlers/page.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/crm/rest/request" @@ -113,15 +114,13 @@ func NewPage(ph PageAPI) *Page { func (ph *Page) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/page", func(r chi.Router) { - r.Get("/", ph.List) - r.Post("/", ph.Create) - r.Get("/{pageID}", ph.Read) - r.Get("/tree", ph.Tree) - r.Post("/{pageID}", ph.Update) - r.Post("/{selfID}/reorder", ph.Reorder) - r.Delete("/{pageID}", ph.Delete) - r.Post("/{pageID}/attachment", ph.Upload) - }) + r.Get("/page/", ph.List) + r.Post("/page/", ph.Create) + r.Get("/page/{pageID}", ph.Read) + r.Get("/page/tree", ph.Tree) + r.Post("/page/{pageID}", ph.Update) + r.Post("/page/{selfID}/reorder", ph.Reorder) + r.Delete("/page/{pageID}", ph.Delete) + r.Post("/page/{pageID}/attachment", ph.Upload) }) } diff --git a/crm/rest/handlers/permissions.go b/crm/rest/handlers/permissions.go index 7338cab52..e5fef112d 100644 --- a/crm/rest/handlers/permissions.go +++ b/crm/rest/handlers/permissions.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/crm/rest/request" @@ -50,8 +51,6 @@ func NewPermissions(ph PermissionsAPI) *Permissions { func (ph *Permissions) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/permissions", func(r chi.Router) { - r.Get("/effective", ph.Effective) - }) + r.Get("/permissions/effective", ph.Effective) }) } diff --git a/crm/rest/handlers/record.go b/crm/rest/handlers/record.go index 103c240d8..7033ec014 100644 --- a/crm/rest/handlers/record.go +++ b/crm/rest/handlers/record.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/crm/rest/request" @@ -104,14 +105,12 @@ func NewRecord(rh RecordAPI) *Record { func (rh *Record) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/module/{moduleID}/record", func(r chi.Router) { - r.Get("/report", rh.Report) - r.Get("/", rh.List) - r.Post("/", rh.Create) - r.Get("/{recordID}", rh.Read) - r.Post("/{recordID}", rh.Update) - r.Delete("/{recordID}", rh.Delete) - r.Post("/{recordID}/{fieldName}/attachment", rh.Upload) - }) + r.Get("/module/{moduleID}/record/report", rh.Report) + r.Get("/module/{moduleID}/record/", rh.List) + r.Post("/module/{moduleID}/record/", rh.Create) + r.Get("/module/{moduleID}/record/{recordID}", rh.Read) + r.Post("/module/{moduleID}/record/{recordID}", rh.Update) + r.Delete("/module/{moduleID}/record/{recordID}", rh.Delete) + r.Post("/module/{moduleID}/record/{recordID}/{fieldName}/attachment", rh.Upload) }) } diff --git a/crm/rest/handlers/trigger.go b/crm/rest/handlers/trigger.go index e982c53d5..9eda061dd 100644 --- a/crm/rest/handlers/trigger.go +++ b/crm/rest/handlers/trigger.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/crm/rest/request" @@ -86,12 +87,10 @@ func NewTrigger(th TriggerAPI) *Trigger { func (th *Trigger) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/trigger", func(r chi.Router) { - r.Get("/", th.List) - r.Post("/", th.Create) - r.Get("/{triggerID}", th.Read) - r.Post("/{triggerID}", th.Update) - r.Delete("/{triggerID}", th.Delete) - }) + r.Get("/trigger/", th.List) + r.Post("/trigger/", th.Create) + r.Get("/trigger/{triggerID}", th.Read) + r.Post("/trigger/{triggerID}", th.Update) + r.Delete("/trigger/{triggerID}", th.Delete) }) } diff --git a/crm/rest/request/attachment.go b/crm/rest/request/attachment.go index b4e04341c..20cbad39e 100644 --- a/crm/rest/request/attachment.go +++ b/crm/rest/request/attachment.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/crm/rest/request/chart.go b/crm/rest/request/chart.go index 69a0274d7..1437af312 100644 --- a/crm/rest/request/chart.go +++ b/crm/rest/request/chart.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/crm/rest/request/module.go b/crm/rest/request/module.go index c3d3bf86f..28cdd1e3c 100644 --- a/crm/rest/request/module.go +++ b/crm/rest/request/module.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/crm/rest/request/notification.go b/crm/rest/request/notification.go index 713846379..cc29b8ce6 100644 --- a/crm/rest/request/notification.go +++ b/crm/rest/request/notification.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/crm/rest/request/page.go b/crm/rest/request/page.go index 53dd70918..7d0727fb0 100644 --- a/crm/rest/request/page.go +++ b/crm/rest/request/page.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/crm/rest/request/permissions.go b/crm/rest/request/permissions.go index 1d2c9889b..a6a0f6498 100644 --- a/crm/rest/request/permissions.go +++ b/crm/rest/request/permissions.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/crm/rest/request/record.go b/crm/rest/request/record.go index d1717536e..1cf3164db 100644 --- a/crm/rest/request/record.go +++ b/crm/rest/request/record.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/crm/rest/request/trigger.go b/crm/rest/request/trigger.go index 265a6123d..eec77f593 100644 --- a/crm/rest/request/trigger.go +++ b/crm/rest/request/trigger.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/docs/crm/README.md b/docs/crm/README.md index f7a5f2c34..b40b14413 100644 --- a/docs/crm/README.md +++ b/docs/crm/README.md @@ -1,5 +1,12 @@ # Attachments +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/attachment/{kind}/` | List, filter all page attachments | +| `GET` | `/attachment/{kind}/{attachmentID}` | Attachment details | +| `GET` | `/attachment/{kind}/{attachmentID}/original/{name}` | Serves attached file | +| `GET` | `/attachment/{kind}/{attachmentID}/preview.{ext}` | Serves preview of an attached file | + ## List, filter all page attachments #### Method @@ -68,11 +75,21 @@ | ext | string | PATH | Preview extension/format | N/A | YES | | kind | string | PATH | Attachment kind | N/A | YES | +--- + # Charts +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/chart/` | List/read charts from module section | +| `POST` | `/chart/` | List/read charts from module section | +| `GET` | `/chart/{chartID}` | Read charts by ID from module section | +| `POST` | `/chart/{chartID}` | Add/update charts in module section | +| `DELETE` | `/chart/{chartID}` | Delete chart | + ## List/read charts from module section #### Method @@ -145,6 +162,8 @@ | --------- | ---- | ------ | ----------- | ------- | --------- | | chartID | uint64 | PATH | Chart ID | N/A | YES | +--- + @@ -152,6 +171,14 @@ CRM module definitions +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/module/` | List modules | +| `POST` | `/module/` | Create module | +| `GET` | `/module/{moduleID}` | Read module | +| `POST` | `/module/{moduleID}` | Update module | +| `DELETE` | `/module/{moduleID}` | Delete module | + ## List modules #### Method @@ -227,6 +254,8 @@ CRM module definitions | --------- | ---- | ------ | ----------- | ------- | --------- | | moduleID | uint64 | PATH | Module ID | N/A | YES | +--- + @@ -234,6 +263,10 @@ CRM module definitions CRM Notifications +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `POST` | `/notification/email` | Send email from the CRM | + ## Send email from the CRM #### Method @@ -252,6 +285,8 @@ CRM Notifications | subject | string | POST | Email subject | N/A | NO | | content | sqlxTypes.JSONText | POST | Message content | N/A | YES | +--- + @@ -259,6 +294,17 @@ CRM Notifications CRM module pages +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/page/` | List available pages | +| `POST` | `/page/` | Create page | +| `GET` | `/page/{pageID}` | Get page details | +| `GET` | `/page/tree` | Get page all (non-record) pages, hierarchically | +| `POST` | `/page/{pageID}` | Update page | +| `POST` | `/page/{selfID}/reorder` | Reorder pages | +| `Delete` | `/page/{pageID}` | Delete page | +| `POST` | `/page/{pageID}/attachment` | Uploads attachment to page | + ## List available pages #### Method @@ -383,11 +429,17 @@ CRM module pages | pageID | uint64 | PATH | Page ID | N/A | YES | | upload | *multipart.FileHeader | POST | File to upload | N/A | YES | +--- + # Permissions +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/permissions/effective` | Effective rules for current user | + ## Effective rules for current user #### Method @@ -402,6 +454,8 @@ CRM module pages | --------- | ---- | ------ | ----------- | ------- | --------- | | resource | string | GET | Show only rules for a specific resource | N/A | NO | +--- + @@ -409,6 +463,16 @@ CRM module pages CRM records +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/module/{moduleID}/record/report` | Generates report from module records | +| `GET` | `/module/{moduleID}/record/` | List/read records from module section | +| `POST` | `/module/{moduleID}/record/` | Create record in module section | +| `GET` | `/module/{moduleID}/record/{recordID}` | Read records by ID from module section | +| `POST` | `/module/{moduleID}/record/{recordID}` | Update records in module section | +| `DELETE` | `/module/{moduleID}/record/{recordID}` | Delete record row from module section | +| `POST` | `/module/{moduleID}/record/{recordID}/{fieldName}/attachment` | Uploads attachment and validates it against record field requirements | + ## Generates report from module records #### Method @@ -522,6 +586,8 @@ CRM records | moduleID | uint64 | PATH | Module ID | N/A | YES | | upload | *multipart.FileHeader | POST | File to upload | N/A | YES | +--- + @@ -529,6 +595,14 @@ CRM records CRM Triggers +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/trigger/` | List available triggers | +| `POST` | `/trigger/` | Create trigger | +| `GET` | `/trigger/{triggerID}` | Get trigger details | +| `POST` | `/trigger/{triggerID}` | Update trigger | +| `Delete` | `/trigger/{triggerID}` | Delete trigger | + ## List available triggers #### Method @@ -606,4 +680,6 @@ CRM Triggers | Parameter | Type | Method | Description | Default | Required? | | --------- | ---- | ------ | ----------- | ------- | --------- | -| triggerID | uint64 | PATH | Trigger ID | N/A | YES | \ No newline at end of file +| triggerID | uint64 | PATH | Trigger ID | N/A | YES | + +--- \ No newline at end of file diff --git a/docs/messaging/README.md b/docs/messaging/README.md index 474bf3f3c..35f064e8a 100644 --- a/docs/messaging/README.md +++ b/docs/messaging/README.md @@ -1,5 +1,10 @@ # Attachments +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/attachment/{attachmentID}/original/{name}` | Serves attached file | +| `GET` | `/attachment/{attachmentID}/preview.{ext}` | Serves preview of an attached file | + ## Serves attached file #### Method @@ -31,6 +36,8 @@ | ext | string | PATH | Preview extension/format | N/A | YES | | attachmentID | uint64 | PATH | Attachment ID | N/A | YES | +--- + @@ -38,6 +45,21 @@ A channel is a representation of a sequence of messages. It has meta data like channel subject. Channels may be public, private or group. +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/channels/` | List channels | +| `POST` | `/channels/` | Create new channel | +| `PUT` | `/channels/{channelID}` | Update channel details | +| `PUT` | `/channels/{channelID}/state` | Update channel state | +| `PUT` | `/channels/{channelID}/flag` | Update channel membership flag | +| `DELETE` | `/channels/{channelID}/flag` | Remove channel membership flag | +| `GET` | `/channels/{channelID}` | Read channel details | +| `GET` | `/channels/{channelID}/members` | List channel members | +| `PUT` | `/channels/{channelID}/members/{userID}` | Join channel | +| `DELETE` | `/channels/{channelID}/members/{userID}` | Remove member from channel | +| `POST` | `/channels/{channelID}/invite` | Join channel | +| `POST` | `/channels/{channelID}/attach` | Attach file to channel | + ## List channels #### Method @@ -220,6 +242,8 @@ A channel is a representation of a sequence of messages. It has meta data like c | replyTo | uint64 | POST | Upload as a reply | N/A | NO | | upload | *multipart.FileHeader | POST | File to upload | N/A | YES | +--- + @@ -245,6 +269,22 @@ The following event types may be sent with a message event: | EDITED | A message has been edited by the sender | | REMOVED | A message has been removed by the sender | +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `POST` | `/channels/{channelID}/messages/` | Post new message to the channel | +| `GET` | `/channels/{channelID}/messages/` | All messages (channel history) | +| `GET` | `/channels/{channelID}/messages/mark-as-read` | Manages read/unread messages in a channel or a thread | +| `PUT` | `/channels/{channelID}/messages/{messageID}` | Edit existing message | +| `DELETE` | `/channels/{channelID}/messages/{messageID}` | Delete existing message | +| `GET` | `/channels/{channelID}/messages/{messageID}/replies` | Returns all replies to a message | +| `POST` | `/channels/{channelID}/messages/{messageID}/replies` | Reply to a message | +| `POST` | `/channels/{channelID}/messages/{messageID}/pin` | Pin message to channel (public bookmark) | +| `DELETE` | `/channels/{channelID}/messages/{messageID}/pin` | Pin message to channel (public bookmark) | +| `POST` | `/channels/{channelID}/messages/{messageID}/bookmark` | Bookmark a message (private bookmark) | +| `DELETE` | `/channels/{channelID}/messages/{messageID}/bookmark` | Remove boomark from message (private bookmark) | +| `POST` | `/channels/{channelID}/messages/{messageID}/reaction/{reaction}` | React to a message | +| `DELETE` | `/channels/{channelID}/messages/{messageID}/reaction/{reaction}` | Delete reaction from a message | + ## Post new message to the channel #### Method @@ -445,11 +485,17 @@ The following event types may be sent with a message event: | reaction | string | PATH | Reaction | N/A | YES | | channelID | uint64 | PATH | Channel ID | N/A | YES | +--- + # Permissions +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/permissions/effective` | Effective rules for current user | + ## Effective rules for current user #### Method @@ -464,11 +510,17 @@ The following event types may be sent with a message event: | --------- | ---- | ------ | ----------- | ------- | --------- | | resource | string | GET | Show only rules for a specific resource | N/A | NO | +--- + # Search entry point +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/search/messages` | Search for messages | + ## Search for messages #### Method @@ -485,4 +537,6 @@ The following event types may be sent with a message event: | fromUser | uint64 | GET | Search only from one user | N/A | NO | | firstID | uint64 | GET | Paging; return newer messages only (higher id) | N/A | NO | | lastID | uint64 | GET | Paging; return older messages only (lower id) | N/A | NO | -| query | string | GET | Search query | N/A | NO | \ No newline at end of file +| query | string | GET | Search query | N/A | NO | + +--- \ No newline at end of file diff --git a/docs/system/README.md b/docs/system/README.md index a37815531..c8cdc347e 100644 --- a/docs/system/README.md +++ b/docs/system/README.md @@ -1,5 +1,13 @@ # Applications +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/application/` | List applications | +| `POST` | `/application/` | Create application | +| `PUT` | `/application/{applicationID}` | Update user details | +| `GET` | `/application/{applicationID}` | Read application details | +| `DELETE` | `/application/{applicationID}` | Remove application | + ## List applications #### Method @@ -76,11 +84,19 @@ | --------- | ---- | ------ | ----------- | ------- | --------- | | applicationID | uint64 | PATH | Application ID | N/A | YES | +--- + # Authentication +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/auth/check` | Check JWT token | +| `POST` | `/auth/login` | Login user | +| `GET` | `/auth/logout` | Delete JWT token (Sign Out) | + ## Check JWT token #### Method @@ -122,6 +138,8 @@ | Parameter | Type | Method | Description | Default | Required? | | --------- | ---- | ------ | ----------- | ------- | --------- | +--- + @@ -129,6 +147,15 @@ Organisations represent a top-level grouping entity. There may be many organisations defined in a single deployment. +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/organisations/` | List organisations | +| `POST` | `/organisations/` | Create organisation | +| `PUT` | `/organisations/{id}` | Update organisation details | +| `DELETE` | `/organisations/{id}` | Remove organisation | +| `GET` | `/organisations/{id}` | Read organisation details | +| `POST` | `/organisations/{id}/archive` | Archive organisation | + ## List organisations #### Method @@ -214,11 +241,21 @@ Organisations represent a top-level grouping entity. There may be many organisat | --------- | ---- | ------ | ----------- | ------- | --------- | | id | uint64 | PATH | Organisation ID | N/A | YES | +--- + # Permissions +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/permissions/` | Retrieve defined permissions | +| `GET` | `/permissions/effective` | Effective rules for current user | +| `GET` | `/permissions/{roleID}/rules` | Retrieve role permissions | +| `DELETE` | `/permissions/{roleID}/rules` | Remove all defined role permissions | +| `PATCH` | `/permissions/{roleID}/rules` | Update permission settings | + ## Retrieve defined permissions #### Method @@ -289,6 +326,8 @@ Organisations represent a top-level grouping entity. There may be many organisat | roleID | uint64 | PATH | Role ID | N/A | YES | | permissions | []rules.Rule | POST | List of permissions to set | N/A | YES | +--- + @@ -296,6 +335,20 @@ Organisations represent a top-level grouping entity. There may be many organisat An organisation may have many roles. Roles may have many channels available. Access to channels may be shared between roles. +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/roles/` | List roles | +| `POST` | `/roles/` | Update role details | +| `PUT` | `/roles/{roleID}` | Update role details | +| `GET` | `/roles/{roleID}` | Read role details and memberships | +| `DELETE` | `/roles/{roleID}` | Remove role | +| `POST` | `/roles/{roleID}/archive` | Archive role | +| `POST` | `/roles/{roleID}/move` | Move role to different organisation | +| `POST` | `/roles/{roleID}/merge` | Merge one role into another | +| `GET` | `/roles/{roleID}/members` | Returns all role members | +| `POST` | `/roles/{roleID}/member/{userID}` | Add member to a role | +| `DELETE` | `/roles/{roleID}/member/{userID}` | Remove member from a role | + ## List roles #### Method @@ -457,11 +510,23 @@ An organisation may have many roles. Roles may have many channels available. Acc | roleID | uint64 | PATH | Source Role ID | N/A | YES | | userID | uint64 | PATH | User ID | N/A | YES | +--- + # Users +| Method | Endpoint | Purpose | +| ------ | -------- | ------- | +| `GET` | `/users/` | Search users (Directory) | +| `POST` | `/users/` | Create user | +| `PUT` | `/users/{userID}` | Update user details | +| `GET` | `/users/{userID}` | Read user details and memberships | +| `DELETE` | `/users/{userID}` | Remove user | +| `POST` | `/users/{userID}/suspend` | Suspend user | +| `POST` | `/users/{userID}/unsuspend` | Unsuspend user | + ## Search users (Directory) #### Method @@ -567,4 +632,6 @@ An organisation may have many roles. Roles may have many channels available. Acc | Parameter | Type | Method | Description | Default | Required? | | --------- | ---- | ------ | ----------- | ------- | --------- | -| userID | uint64 | PATH | User ID | N/A | YES | \ No newline at end of file +| userID | uint64 | PATH | User ID | N/A | YES | + +--- \ No newline at end of file diff --git a/messaging/rest/handlers/attachment.go b/messaging/rest/handlers/attachment.go index aee0618eb..8ddbcf0d1 100644 --- a/messaging/rest/handlers/attachment.go +++ b/messaging/rest/handlers/attachment.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/messaging/rest/request" @@ -59,9 +60,7 @@ func NewAttachment(ah AttachmentAPI) *Attachment { func (ah *Attachment) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/attachment/{attachmentID}", func(r chi.Router) { - r.Get("/original/{name}", ah.Original) - r.Get("/preview.{ext}", ah.Preview) - }) + r.Get("/attachment/{attachmentID}/original/{name}", ah.Original) + r.Get("/attachment/{attachmentID}/preview.{ext}", ah.Preview) }) } diff --git a/messaging/rest/handlers/channel.go b/messaging/rest/handlers/channel.go index 7a0bf9903..b64f7b55e 100644 --- a/messaging/rest/handlers/channel.go +++ b/messaging/rest/handlers/channel.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/messaging/rest/request" @@ -149,19 +150,17 @@ func NewChannel(ch ChannelAPI) *Channel { func (ch *Channel) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/channels", func(r chi.Router) { - r.Get("/", ch.List) - r.Post("/", ch.Create) - r.Put("/{channelID}", ch.Update) - r.Put("/{channelID}/state", ch.State) - r.Put("/{channelID}/flag", ch.SetFlag) - r.Delete("/{channelID}/flag", ch.RemoveFlag) - r.Get("/{channelID}", ch.Read) - r.Get("/{channelID}/members", ch.Members) - r.Put("/{channelID}/members/{userID}", ch.Join) - r.Delete("/{channelID}/members/{userID}", ch.Part) - r.Post("/{channelID}/invite", ch.Invite) - r.Post("/{channelID}/attach", ch.Attach) - }) + r.Get("/channels/", ch.List) + r.Post("/channels/", ch.Create) + r.Put("/channels/{channelID}", ch.Update) + r.Put("/channels/{channelID}/state", ch.State) + r.Put("/channels/{channelID}/flag", ch.SetFlag) + r.Delete("/channels/{channelID}/flag", ch.RemoveFlag) + r.Get("/channels/{channelID}", ch.Read) + r.Get("/channels/{channelID}/members", ch.Members) + r.Put("/channels/{channelID}/members/{userID}", ch.Join) + r.Delete("/channels/{channelID}/members/{userID}", ch.Part) + r.Post("/channels/{channelID}/invite", ch.Invite) + r.Post("/channels/{channelID}/attach", ch.Attach) }) } diff --git a/messaging/rest/handlers/message.go b/messaging/rest/handlers/message.go index ca061deb4..829b54c16 100644 --- a/messaging/rest/handlers/message.go +++ b/messaging/rest/handlers/message.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/messaging/rest/request" @@ -158,20 +159,18 @@ func NewMessage(mh MessageAPI) *Message { func (mh *Message) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/channels/{channelID}/messages", func(r chi.Router) { - r.Post("/", mh.Create) - r.Get("/", mh.History) - r.Get("/mark-as-read", mh.MarkAsRead) - r.Put("/{messageID}", mh.Edit) - r.Delete("/{messageID}", mh.Delete) - r.Get("/{messageID}/replies", mh.ReplyGet) - r.Post("/{messageID}/replies", mh.ReplyCreate) - r.Post("/{messageID}/pin", mh.PinCreate) - r.Delete("/{messageID}/pin", mh.PinRemove) - r.Post("/{messageID}/bookmark", mh.BookmarkCreate) - r.Delete("/{messageID}/bookmark", mh.BookmarkRemove) - r.Post("/{messageID}/reaction/{reaction}", mh.ReactionCreate) - r.Delete("/{messageID}/reaction/{reaction}", mh.ReactionRemove) - }) + r.Post("/channels/{channelID}/messages/", mh.Create) + r.Get("/channels/{channelID}/messages/", mh.History) + r.Get("/channels/{channelID}/messages/mark-as-read", mh.MarkAsRead) + r.Put("/channels/{channelID}/messages/{messageID}", mh.Edit) + r.Delete("/channels/{channelID}/messages/{messageID}", mh.Delete) + r.Get("/channels/{channelID}/messages/{messageID}/replies", mh.ReplyGet) + r.Post("/channels/{channelID}/messages/{messageID}/replies", mh.ReplyCreate) + r.Post("/channels/{channelID}/messages/{messageID}/pin", mh.PinCreate) + r.Delete("/channels/{channelID}/messages/{messageID}/pin", mh.PinRemove) + r.Post("/channels/{channelID}/messages/{messageID}/bookmark", mh.BookmarkCreate) + r.Delete("/channels/{channelID}/messages/{messageID}/bookmark", mh.BookmarkRemove) + r.Post("/channels/{channelID}/messages/{messageID}/reaction/{reaction}", mh.ReactionCreate) + r.Delete("/channels/{channelID}/messages/{messageID}/reaction/{reaction}", mh.ReactionRemove) }) } diff --git a/messaging/rest/handlers/permissions.go b/messaging/rest/handlers/permissions.go index 2f258e641..e6f4e7948 100644 --- a/messaging/rest/handlers/permissions.go +++ b/messaging/rest/handlers/permissions.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/messaging/rest/request" @@ -50,8 +51,6 @@ func NewPermissions(ph PermissionsAPI) *Permissions { func (ph *Permissions) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/permissions", func(r chi.Router) { - r.Get("/effective", ph.Effective) - }) + r.Get("/permissions/effective", ph.Effective) }) } diff --git a/messaging/rest/handlers/search.go b/messaging/rest/handlers/search.go index c32d46055..db2f8c30b 100644 --- a/messaging/rest/handlers/search.go +++ b/messaging/rest/handlers/search.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/messaging/rest/request" @@ -50,8 +51,6 @@ func NewSearch(sh SearchAPI) *Search { func (sh *Search) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/search", func(r chi.Router) { - r.Get("/messages", sh.Messages) - }) + r.Get("/search/messages", sh.Messages) }) } diff --git a/messaging/rest/request/attachment.go b/messaging/rest/request/attachment.go index ccab60d20..70064d27e 100644 --- a/messaging/rest/request/attachment.go +++ b/messaging/rest/request/attachment.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/messaging/rest/request/channel.go b/messaging/rest/request/channel.go index 621f6c0bf..ffc4873b1 100644 --- a/messaging/rest/request/channel.go +++ b/messaging/rest/request/channel.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/messaging/rest/request/message.go b/messaging/rest/request/message.go index 53a044724..5181d5b20 100644 --- a/messaging/rest/request/message.go +++ b/messaging/rest/request/message.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/messaging/rest/request/permissions.go b/messaging/rest/request/permissions.go index 1d2c9889b..a6a0f6498 100644 --- a/messaging/rest/request/permissions.go +++ b/messaging/rest/request/permissions.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/messaging/rest/request/search.go b/messaging/rest/request/search.go index 1f4176d10..0cf52bb6e 100644 --- a/messaging/rest/request/search.go +++ b/messaging/rest/request/search.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/system/rest/handlers/application.go b/system/rest/handlers/application.go index 8b7b0d394..4b640321e 100644 --- a/system/rest/handlers/application.go +++ b/system/rest/handlers/application.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/system/rest/request" @@ -86,12 +87,10 @@ func NewApplication(ah ApplicationAPI) *Application { func (ah *Application) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/application", func(r chi.Router) { - r.Get("/", ah.List) - r.Post("/", ah.Create) - r.Put("/{applicationID}", ah.Update) - r.Get("/{applicationID}", ah.Read) - r.Delete("/{applicationID}", ah.Delete) - }) + r.Get("/application/", ah.List) + r.Post("/application/", ah.Create) + r.Put("/application/{applicationID}", ah.Update) + r.Get("/application/{applicationID}", ah.Read) + r.Delete("/application/{applicationID}", ah.Delete) }) } diff --git a/system/rest/handlers/auth.go b/system/rest/handlers/auth.go index 96a561153..c167365a5 100644 --- a/system/rest/handlers/auth.go +++ b/system/rest/handlers/auth.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/system/rest/request" @@ -68,10 +69,8 @@ func NewAuth(ah AuthAPI) *Auth { func (ah *Auth) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/auth", func(r chi.Router) { - r.Get("/check", ah.Check) - r.Post("/login", ah.Login) - r.Get("/logout", ah.Logout) - }) + r.Get("/auth/check", ah.Check) + r.Post("/auth/login", ah.Login) + r.Get("/auth/logout", ah.Logout) }) } diff --git a/system/rest/handlers/organisation.go b/system/rest/handlers/organisation.go index 52917cd04..84a86acd7 100644 --- a/system/rest/handlers/organisation.go +++ b/system/rest/handlers/organisation.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/system/rest/request" @@ -95,13 +96,11 @@ func NewOrganisation(oh OrganisationAPI) *Organisation { func (oh *Organisation) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/organisations", func(r chi.Router) { - r.Get("/", oh.List) - r.Post("/", oh.Create) - r.Put("/{id}", oh.Update) - r.Delete("/{id}", oh.Delete) - r.Get("/{id}", oh.Read) - r.Post("/{id}/archive", oh.Archive) - }) + r.Get("/organisations/", oh.List) + r.Post("/organisations/", oh.Create) + r.Put("/organisations/{id}", oh.Update) + r.Delete("/organisations/{id}", oh.Delete) + r.Get("/organisations/{id}", oh.Read) + r.Post("/organisations/{id}/archive", oh.Archive) }) } diff --git a/system/rest/handlers/permissions.go b/system/rest/handlers/permissions.go index 7996e53d2..c97a41b21 100644 --- a/system/rest/handlers/permissions.go +++ b/system/rest/handlers/permissions.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/system/rest/request" @@ -86,12 +87,10 @@ func NewPermissions(ph PermissionsAPI) *Permissions { func (ph *Permissions) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/permissions", func(r chi.Router) { - r.Get("/", ph.List) - r.Get("/effective", ph.Effective) - r.Get("/{roleID}/rules", ph.Read) - r.Delete("/{roleID}/rules", ph.Delete) - r.Patch("/{roleID}/rules", ph.Update) - }) + r.Get("/permissions/", ph.List) + r.Get("/permissions/effective", ph.Effective) + r.Get("/permissions/{roleID}/rules", ph.Read) + r.Delete("/permissions/{roleID}/rules", ph.Delete) + r.Patch("/permissions/{roleID}/rules", ph.Update) }) } diff --git a/system/rest/handlers/role.go b/system/rest/handlers/role.go index 2e26f5400..a3573d656 100644 --- a/system/rest/handlers/role.go +++ b/system/rest/handlers/role.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/system/rest/request" @@ -140,18 +141,16 @@ func NewRole(rh RoleAPI) *Role { func (rh *Role) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/roles", func(r chi.Router) { - r.Get("/", rh.List) - r.Post("/", rh.Create) - r.Put("/{roleID}", rh.Update) - r.Get("/{roleID}", rh.Read) - r.Delete("/{roleID}", rh.Delete) - r.Post("/{roleID}/archive", rh.Archive) - r.Post("/{roleID}/move", rh.Move) - r.Post("/{roleID}/merge", rh.Merge) - r.Get("/{roleID}/members", rh.MemberList) - r.Post("/{roleID}/member/{userID}", rh.MemberAdd) - r.Delete("/{roleID}/member/{userID}", rh.MemberRemove) - }) + r.Get("/roles/", rh.List) + r.Post("/roles/", rh.Create) + r.Put("/roles/{roleID}", rh.Update) + r.Get("/roles/{roleID}", rh.Read) + r.Delete("/roles/{roleID}", rh.Delete) + r.Post("/roles/{roleID}/archive", rh.Archive) + r.Post("/roles/{roleID}/move", rh.Move) + r.Post("/roles/{roleID}/merge", rh.Merge) + r.Get("/roles/{roleID}/members", rh.MemberList) + r.Post("/roles/{roleID}/member/{userID}", rh.MemberAdd) + r.Delete("/roles/{roleID}/member/{userID}", rh.MemberRemove) }) } diff --git a/system/rest/handlers/user.go b/system/rest/handlers/user.go index 632b3cb1e..6e3877d93 100644 --- a/system/rest/handlers/user.go +++ b/system/rest/handlers/user.go @@ -17,9 +17,10 @@ package handlers import ( "context" - "github.com/go-chi/chi" + "net/http" + "github.com/go-chi/chi" "github.com/titpetric/factory/resputil" "github.com/crusttech/crust/system/rest/request" @@ -104,14 +105,12 @@ func NewUser(uh UserAPI) *User { func (uh *User) MountRoutes(r chi.Router, middlewares ...func(http.Handler) http.Handler) { r.Group(func(r chi.Router) { r.Use(middlewares...) - r.Route("/users", func(r chi.Router) { - r.Get("/", uh.List) - r.Post("/", uh.Create) - r.Put("/{userID}", uh.Update) - r.Get("/{userID}", uh.Read) - r.Delete("/{userID}", uh.Delete) - r.Post("/{userID}/suspend", uh.Suspend) - r.Post("/{userID}/unsuspend", uh.Unsuspend) - }) + r.Get("/users/", uh.List) + r.Post("/users/", uh.Create) + r.Put("/users/{userID}", uh.Update) + r.Get("/users/{userID}", uh.Read) + r.Delete("/users/{userID}", uh.Delete) + r.Post("/users/{userID}/suspend", uh.Suspend) + r.Post("/users/{userID}/unsuspend", uh.Unsuspend) }) } diff --git a/system/rest/request/application.go b/system/rest/request/application.go index 1b650ac99..024ac8beb 100644 --- a/system/rest/request/application.go +++ b/system/rest/request/application.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/system/rest/request/auth.go b/system/rest/request/auth.go index 9ae6174bf..3266a9831 100644 --- a/system/rest/request/auth.go +++ b/system/rest/request/auth.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/system/rest/request/organisation.go b/system/rest/request/organisation.go index b1ef43a5a..c91485f45 100644 --- a/system/rest/request/organisation.go +++ b/system/rest/request/organisation.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/system/rest/request/permissions.go b/system/rest/request/permissions.go index 7016deb9a..501d72172 100644 --- a/system/rest/request/permissions.go +++ b/system/rest/request/permissions.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/system/rest/request/role.go b/system/rest/request/role.go index 737d60adc..40bebe18a 100644 --- a/system/rest/request/role.go +++ b/system/rest/request/role.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors" diff --git a/system/rest/request/user.go b/system/rest/request/user.go index 94b84177f..2d1e09d17 100644 --- a/system/rest/request/user.go +++ b/system/rest/request/user.go @@ -16,11 +16,12 @@ package request */ import ( - "encoding/json" "io" + "strings" + + "encoding/json" "mime/multipart" "net/http" - "strings" "github.com/go-chi/chi" "github.com/pkg/errors"