2020-11-09 14:19:03 +02:00
|
|
|
package client
|
|
|
|
|
|
|
|
import (
|
2021-08-10 04:57:45 +02:00
|
|
|
"bytes"
|
2020-11-09 14:19:03 +02:00
|
|
|
"encoding/json"
|
|
|
|
"fmt"
|
|
|
|
"io"
|
2021-08-10 04:57:45 +02:00
|
|
|
"mime/multipart"
|
2020-11-09 14:19:03 +02:00
|
|
|
"net/http"
|
|
|
|
"strings"
|
|
|
|
|
2021-08-10 04:57:45 +02:00
|
|
|
"github.com/mattermost/focalboard/server/api"
|
2021-01-27 00:13:46 +02:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
2022-12-24 06:31:39 +02:00
|
|
|
|
2022-11-24 13:46:59 +02:00
|
|
|
mmModel "github.com/mattermost/mattermost-server/v6/model"
|
2020-11-09 14:19:03 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2022-04-13 22:24:32 +02:00
|
|
|
APIURLSuffix = "/api/v2"
|
2020-11-09 14:19:03 +02:00
|
|
|
)
|
|
|
|
|
2021-07-09 03:09:02 +02:00
|
|
|
type RequestReaderError struct {
|
|
|
|
buf []byte
|
|
|
|
}
|
|
|
|
|
|
|
|
func (rre RequestReaderError) Error() string {
|
|
|
|
return "payload: " + string(rre.buf)
|
|
|
|
}
|
|
|
|
|
2020-11-09 14:19:03 +02:00
|
|
|
type Response struct {
|
|
|
|
StatusCode int
|
|
|
|
Error error
|
|
|
|
Header http.Header
|
|
|
|
}
|
|
|
|
|
|
|
|
func BuildResponse(r *http.Response) *Response {
|
|
|
|
return &Response{
|
|
|
|
StatusCode: r.StatusCode,
|
|
|
|
Header: r.Header,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func BuildErrorResponse(r *http.Response, err error) *Response {
|
|
|
|
statusCode := 0
|
|
|
|
header := make(http.Header)
|
|
|
|
if r != nil {
|
|
|
|
statusCode = r.StatusCode
|
|
|
|
header = r.Header
|
|
|
|
}
|
|
|
|
|
|
|
|
return &Response{
|
|
|
|
StatusCode: statusCode,
|
|
|
|
Error: err,
|
|
|
|
Header: header,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func closeBody(r *http.Response) {
|
|
|
|
if r.Body != nil {
|
2022-10-25 22:28:00 +02:00
|
|
|
_, _ = io.Copy(io.Discard, r.Body)
|
2020-11-09 14:19:03 +02:00
|
|
|
_ = r.Body.Close()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func toJSON(v interface{}) string {
|
|
|
|
b, _ := json.Marshal(v)
|
|
|
|
return string(b)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Client struct {
|
2021-06-21 11:21:42 +02:00
|
|
|
URL string
|
|
|
|
APIURL string
|
|
|
|
HTTPClient *http.Client
|
|
|
|
HTTPHeader map[string]string
|
2021-08-10 04:57:45 +02:00
|
|
|
// Token if token is empty indicate client is not login yet
|
|
|
|
Token string
|
2020-11-09 14:19:03 +02:00
|
|
|
}
|
|
|
|
|
2021-03-21 10:28:26 +02:00
|
|
|
func NewClient(url, sessionToken string) *Client {
|
2020-11-09 14:19:03 +02:00
|
|
|
url = strings.TrimRight(url, "/")
|
2021-08-10 04:57:45 +02:00
|
|
|
|
2021-02-03 20:42:06 +02:00
|
|
|
headers := map[string]string{
|
|
|
|
"X-Requested-With": "XMLHttpRequest",
|
|
|
|
}
|
2021-08-10 04:57:45 +02:00
|
|
|
|
|
|
|
return &Client{url, url + APIURLSuffix, &http.Client{}, headers, sessionToken}
|
2020-11-09 14:19:03 +02:00
|
|
|
}
|
|
|
|
|
2021-06-21 11:21:42 +02:00
|
|
|
func (c *Client) DoAPIGet(url, etag string) (*http.Response, error) {
|
|
|
|
return c.DoAPIRequest(http.MethodGet, c.APIURL+url, "", etag)
|
2020-11-09 14:19:03 +02:00
|
|
|
}
|
|
|
|
|
2021-06-21 11:21:42 +02:00
|
|
|
func (c *Client) DoAPIPost(url, data string) (*http.Response, error) {
|
|
|
|
return c.DoAPIRequest(http.MethodPost, c.APIURL+url, data, "")
|
2020-11-09 14:19:03 +02:00
|
|
|
}
|
|
|
|
|
2021-08-06 14:10:24 +02:00
|
|
|
func (c *Client) DoAPIPatch(url, data string) (*http.Response, error) {
|
|
|
|
return c.DoAPIRequest(http.MethodPatch, c.APIURL+url, data, "")
|
|
|
|
}
|
|
|
|
|
2021-06-21 11:21:42 +02:00
|
|
|
func (c *Client) DoAPIPut(url, data string) (*http.Response, error) {
|
|
|
|
return c.DoAPIRequest(http.MethodPut, c.APIURL+url, data, "")
|
2020-11-09 14:19:03 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) DoAPIDelete(url string, data string) (*http.Response, error) {
|
|
|
|
return c.DoAPIRequest(http.MethodDelete, c.APIURL+url, data, "")
|
2020-11-09 14:19:03 +02:00
|
|
|
}
|
|
|
|
|
2021-06-21 11:21:42 +02:00
|
|
|
func (c *Client) DoAPIRequest(method, url, data, etag string) (*http.Response, error) {
|
|
|
|
return c.doAPIRequestReader(method, url, strings.NewReader(data), etag)
|
2020-11-09 14:19:03 +02:00
|
|
|
}
|
|
|
|
|
2021-08-10 04:57:45 +02:00
|
|
|
type requestOption func(r *http.Request)
|
|
|
|
|
|
|
|
func (c *Client) doAPIRequestReader(method, url string, data io.Reader, _ /* etag */ string, opts ...requestOption) (*http.Response, error) {
|
2020-11-09 14:19:03 +02:00
|
|
|
rq, err := http.NewRequest(method, url, data)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-08-10 04:57:45 +02:00
|
|
|
for _, opt := range opts {
|
|
|
|
opt(rq)
|
|
|
|
}
|
|
|
|
|
2021-06-21 11:21:42 +02:00
|
|
|
if c.HTTPHeader != nil && len(c.HTTPHeader) > 0 {
|
|
|
|
for k, v := range c.HTTPHeader {
|
2020-11-09 14:19:03 +02:00
|
|
|
rq.Header.Set(k, v)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-10 04:57:45 +02:00
|
|
|
if c.Token != "" {
|
|
|
|
rq.Header.Set("Authorization", "Bearer "+c.Token)
|
|
|
|
}
|
|
|
|
|
2021-06-21 11:21:42 +02:00
|
|
|
rp, err := c.HTTPClient.Do(rq)
|
2020-11-09 14:19:03 +02:00
|
|
|
if err != nil || rp == nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2021-06-21 11:21:42 +02:00
|
|
|
if rp.StatusCode == http.StatusNotModified {
|
2020-11-09 14:19:03 +02:00
|
|
|
return rp, nil
|
|
|
|
}
|
|
|
|
|
2021-06-21 11:21:42 +02:00
|
|
|
if rp.StatusCode >= http.StatusMultipleChoices {
|
2020-11-09 14:19:03 +02:00
|
|
|
defer closeBody(rp)
|
2022-09-13 12:18:40 +02:00
|
|
|
b, err := io.ReadAll(rp.Body)
|
2020-11-09 14:19:03 +02:00
|
|
|
if err != nil {
|
|
|
|
return rp, fmt.Errorf("error when parsing response with code %d: %w", rp.StatusCode, err)
|
|
|
|
}
|
2021-07-09 03:09:02 +02:00
|
|
|
return rp, RequestReaderError{b}
|
2020-11-09 14:19:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return rp, nil
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) GetTeamRoute(teamID string) string {
|
|
|
|
return fmt.Sprintf("%s/%s", c.GetTeamsRoute(), teamID)
|
2020-11-09 14:19:03 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) GetTeamsRoute() string {
|
|
|
|
return "/teams"
|
2020-11-09 14:19:03 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) GetBlockRoute(boardID, blockID string) string {
|
|
|
|
return fmt.Sprintf("%s/%s", c.GetBlocksRoute(boardID), blockID)
|
2020-11-09 14:19:03 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) GetBoardsRoute() string {
|
|
|
|
return "/boards"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) GetBoardRoute(boardID string) string {
|
|
|
|
return fmt.Sprintf("%s/%s", c.GetBoardsRoute(), boardID)
|
|
|
|
}
|
|
|
|
|
GetBoardMetadata API (#2569)
* wip
* Added data migration for populating categories
* wip
* Added data migration for populating categories
* Store WIP
* migration WIP
* category CRUD APIs complete
* category block API WIP
* block category update API done
* Fetcehed data into store
* Started displayting sidebar data
* sidebar WIP
* Dashboard - basic changes
* Sidebar dashboard btn and board switcher UI only
* Sidebar dashboard btn and board switcher UI only
* create category dialog WIP
* Create category webapp side done
* Integrated move card to other category
* board to block
* Disabled dashboard route for now as we'll implement it in phase 2
* WIP
* Added logic to open last board/view on per team level
* Add workspace to teams and boards migrations (#1986)
* Add workspace to teams and boards migrations
* Update json annotations on board models
* boards search dialog WIP
* Seach dialog WIP
* Implemented opening boiard from search results
* Boards switcher styliung
* Handled update category WS event
* Template support
* personal server support and styling fixes
* test fix WIP
* Fixed a bug causing boards to not be moved correctly beteen categories
* Fixed webapp tests
* fix
* Store changes (#2011)
* Permissions phase 1 - Websocket updates (#2014)
* Store changes
* Websockets changes
* Permissions phase 1 - Permissions service (#2015)
* Store changes
* Websockets changes
* Permissions service
* Api and app updates (#2016)
* Store changes
* Websockets changes
* Permissions service
* New API and App changes
* Delete and Patch boards and blocks endpoints
* Used correct variable
* Webapp changes WIP
* Open correct team URL
* Fixed get block API
* Used React context for workspace users
* WIP
* On load navigation sorted out
* WIP
* Nav fix
* categories WS broadcast
* Used real search API
* Fixed unfurl ppreview
* set active team in sidebar
* IMplemented navigation on changing team in sidebar
* Misc fixes
* close rows inside transaction (#2045)
* update syntax for mysql (#2044)
* Upadted mutator for new patchBlock API
* Updated patchBlock API to use new URL
* Listeining to correct event in plugin mode
* Implemented WS messages for category operations:
* Fix duplicated build tags on Makefile
* Sidebar enhancements
* Add missing prefix to SQLite migration and fix flaky tests
* Sidebar boards menu enhancement
* Fix board page interactions (#2144)
* Fix patch board card properties error
* Fix board interactions
* Fix insert blocks interactions
* Fix app tests (#2104)
* Add json1 tag to vscode launch (#2157)
* Fix add, delete and update boards and add board patch generation (#2146)
* Fix update boards and add board patch generation
* Make add board and add template work, as well as deleting a board
* Update the state on board deletion
* Delete unused variable
* Fix bad parenthesis
* Fix board creation inside plugin, options were coming null due websocket message serialization
* update property type mutators to use boards API (#2168)
* Add permissions modal (#2196)
* Initial integration
* Permissions modal, websocket updates and API tests implemented
* Avoid updating/removing user if there is only one admin left
* Fix duplicates on board search
* Adds integration test
* Addressing PR review comments
Co-authored-by: Jesús Espino <jespinog@gmail.com>
* Merge
* I'm able to compile now
* Some fixes around tests execution
* Fixing migrations
* Fixing migrations order
* WIP
* Fixing some other compilation problems on tests
* Some typescript tests fixed
* Fixing javascript tests
* Fixing compilation
* Fixing some problems to create boards
* Load the templates on initial load
* Improvements over initial team templates import
* Adding new fields in the database
* Working on adding duplicate board api
* Removing RootID concept entirely
* Improving a bit the subscriptions
* Fixing store tests for notificationHints
* Fixing more tests
* fixing tests
* Fixing tests
* Fixing tests
* Fixing some small bugs related to templates
* Fixing registration link generation/regeneration
* Fixing cypress tests
* Adding store tests for duplicateBoard and duplicateBlock
* Addressing some TODO comments
* Making the export api simpler
* Add redirect component for old workspace urls
* Removing Dashboard code
* Delete only the built-in templates on update
* fixing tests
* Adding users autocompletion
* Updating snapshots
* Fixing bad merge
* fix panic when creating new card in notifysubscriptions (#2352)
* fix lint errors (#2353)
* fix lint errors
* fix panic when creating new card in notifysubscriptions (#2352)
* fix lint errors
* fix unit test
* Revert "fix unit test"
This reverts commit 0ad78aed65745521c0bb45790c9ea91b6c316c44.
Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
* fix sql syntax error for SearchUsersByTeam (#2357)
* Fix mentions delivery (#2358)
* fix sql syntax error for SearchUsersByTeam
* fix mentions delivery
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* update api for octoClient calls, pass correct variables to mutator (#2359)
* Fixing tests after merge
* Fix sidebar context menu UI issue (#2399)
* Fix notification diff for text blocks (#2386)
* fix notification diff for text blocks; fix various linter errors.
* fix URLs to cards
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Permissions branch: Fix card links (#2391)
* fix notification diff for text blocks; fix various linter errors.
* fix URLs to cards
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Fixing sqlite tests
* Fixing server tests
* Update migrations to create global templates. (#2397)
* fix duplicate templates
* revert migrate.go
* update UI for empty templates
* implement updating built-in templates as global (teamId = 0)
* handle error if board not found
* update unit test
* fix more tests
* Update blocks_test.go
Fix merge issue
* fix migration sql error (#2414)
* Fixing frontend tests
* Set target team ID when using a global template (#2419)
* Fix some server tests
* Fixing onboarding creation
* Permissions branch: Fix unit tests and CI errors (part 1) (#2425)
* Fixing some small memory leaks (#2400)
* Fixing some small memory leaks
* fixing tests
* passing the tags to all test targets
* Increasing the timeout of the tests
* Fix some type checkings
* Permissions branch: Fixes all the linter errors (#2429)
* fix linter errors
* Reestructuring the router and splitting in more subcomponents (#2403)
* Reestructuring the router and splitting in more subcomponents
* Removing console.log calls
* Removing unneeded selector
* Addressing PR comment
* Fix redirection to one team when you load directly the boards home path
* Using properly the lastTeamID to redirect the user if needed
* don't allow last admin change/deleted (#2416)
* don't allow last admin change/deleted
* update for i18-extract
* fixed en.json
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Harshil Sharma <harshilsharma63@gmail.com>
* Splitting BoardPage component into simpler/smaller components (#2435)
* Splitting BoardPage component into simpler/smaller components
* Removing unneeded import
* Replace go migrate with morph permissions (#2424)
* merge origin/replace-go-migrate-with-morph
* run go mod tidy on mattermost-plugin and increase test timeout
* fix merge issue temprorarily
* remove some debug changes
* fixing the linter
* Allow always team 0 (global) templates fetch (#2472)
* Fix problem with viewId 0 in the URL (#2473)
* Migrate from binddata to goembed (#2471)
* Adding join logic to the board switcher (#2434)
* Adding join logic to the board switcher
* Using already existing client function and removing the joinBoard one
* Adding support for autojoin based on url
* Fixing frontend tests
* fix webapp compile error, missing enableSharedBoards (#2501)
* Fixing duplication on postgres
* Adding back views to the sidebar (#2494)
* Fix #2507. Update Swagger comments (#2508)
* Fix the flash of the template selector on board/team switch (#2490)
* Fix the flash of the template selector on board/team switch
* More fixes specially around error handling
* Fixing the bot badge (#2487)
* simplifying a bit the team store sync between channels and focalboard (#2481)
* Fix menu tests (#2528)
* fix failing menu tests
* fix lint error
* Added keyboard shortcut for boards switcher (#2407)
* Added keyboard shortcut for boards switcher
* Fixed a type error
* Added some inline comments
* Fixed lint
* Fixed bug with scroll jumping when the card is opened: (#2477)
- avoid remounting of `ScrollingComponent` for each render of `Kanban` component
- property `autoFocus` set to false for `CalculationOptions` because it triggers `blur` even for the button in Jest tests and closes the menu
- snapshots for tests with `CalculationOptions` updated
* Adding the frontend support for permissions and applying it to a big part of the interface. (#2536)
* Initial work on permissions gates
* Applying permissions gates in more places
* Adding more checks to the interface
* Adding more permissions gates and keeping the store up to date
* fixing some tests
* Fixing some more tests
* Fixing another test
* Fixing all tests and adding some more
* Adding no-permission snapshot tests
* Addressing PR review comments
* Fixing invert behavior
* Permissions branch: No sqlstore calls after app shutdown (#2530)
* fix webapp compile error, missing enableSharedBoards
* refactor app init wip
* - ensure all block change notifications are finished before shutting down app
- fix unit tests for mysql (insert_at only has 1 second resolution!)
* adjust logging
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Fixed migrations to allow upgrading from previous version (#2535)
* Added mechanism to check if schema migration is needed
* WIP
* WIP
* WIP
* WIP
* Fixed migration
* Fixed for SQLite
* minor cleaniup
* Deleted old schema migration table after running migrations
* Removed a debug log
* Fixed a bug where the code always tried to delete a table which may or may not exist
* Show properly the user avatar in the ShareBoard component (#2542)
* Fixing the last CI problems from the permissions-branch (#2541)
* Fix history ordering
* Giving some times to avoid possible race conditions
* Empty
* Reverting accidental change in the config.json
* Optimizing table view (#2540)
* Optimizing table view
* Reducing the amount of rendering for tables
* Some other performance improvements
* Improve the activeView updates
* Some extra simplifications
* Another small improvement
* Fixing tests
* Fixing linter errors
* Reducing a bit the amount of dependency with big objects in the store
* Small simplification
* Removing Commenter role from the user role selector (#2561)
* Shareboard cleanup (#2550)
* Initial work on permissions gates
* Applying permissions gates in more places
* Adding more checks to the interface
* Adding more permissions gates and keeping the store up to date
* fixing some tests
* Fixing some more tests
* Fixing another test
* Fixing all tests and adding some more
* Adding no-permission snapshot tests
* Addressing PR review comments
* cleanup some shareboard settings
* remove unused property, fix for user items being displayed for non admin
* revert change, allow users to show
Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* GetBoardMetadata API
* Integration tests. WIP
* getBoardHistory
* Working integration test
* Fix ordering, add store tests
* Fix: Update board_history update_at on patch
* sqltests
* Fix unmarshall delete boards_history
* testGetBlockMetadata with delete and undelete
* Handle board not found
* Fixing comments and cards with the new optimizations in the store (#2560)
* Fixing property creation (#2563)
* Cleanup
* Fix user selection in table view (#2565)
* Fixing focus new row in table view (#2567)
* Permissions branch: Fix sqlite table lock (CI) (#2568)
* fix sqlite table lock
* remove test db on teardown
* revert .gitignore
* fix goimport on migration code
* fix typo
* more linter fixes
* clean up tmp db for sqlstore tests
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Fixing snapshots
* Remove debug log
* Return metadata for deleted boards
* Migrating center panel to functional component (#2562)
* Migrating center panel to functional component
* Fixing some tests
* Fixing another test
* Fixing linter errors
* Fixing types errors
* Fixing linter error
* Fixing cypress tests
* Fixing the last cypress test
* Simpliying a bit the code
* Making property insertion more robust
* Updating checkbox test
* License check
* Cleanup and update Swagger docs
* Merge from main
* Fix bad merge
* Fix Linux-app build break
* do mod tidy
* Fix server lint
* Require credentials (not only read token)
* Add missing defer CloseRows
* do mod tidy
Co-authored-by: Harshil Sharma <harshilsharma63@gmail.com>
Co-authored-by: Miguel de la Cruz <miguel@mcrx.me>
Co-authored-by: Scott Bishel <scott.bishel@mattermost.com>
Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Harshil Sharma <18575143+harshilsharma63@users.noreply.github.com>
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Co-authored-by: kamre <eremchenko@gmail.com>
2022-03-29 23:47:49 +02:00
|
|
|
func (c *Client) GetBoardMetadataRoute(boardID string) string {
|
|
|
|
return fmt.Sprintf("%s/%s/metadata", c.GetBoardsRoute(), boardID)
|
|
|
|
}
|
|
|
|
|
2022-03-29 10:14:33 +02:00
|
|
|
func (c *Client) GetJoinBoardRoute(boardID string) string {
|
|
|
|
return fmt.Sprintf("%s/%s/join", c.GetBoardsRoute(), boardID)
|
|
|
|
}
|
|
|
|
|
2022-04-05 17:00:04 +02:00
|
|
|
func (c *Client) GetLeaveBoardRoute(boardID string) string {
|
|
|
|
return fmt.Sprintf("%s/%s/join", c.GetBoardsRoute(), boardID)
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) GetBlocksRoute(boardID string) string {
|
|
|
|
return fmt.Sprintf("%s/blocks", c.GetBoardRoute(boardID))
|
|
|
|
}
|
|
|
|
|
2022-03-30 00:55:39 +02:00
|
|
|
func (c *Client) GetAllBlocksRoute(boardID string) string {
|
|
|
|
return fmt.Sprintf("%s/blocks?all=true", c.GetBoardRoute(boardID))
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) GetBoardsAndBlocksRoute() string {
|
|
|
|
return "/boards-and-blocks"
|
|
|
|
}
|
|
|
|
|
2022-09-08 13:01:33 +02:00
|
|
|
func (c *Client) GetCardsRoute() string {
|
|
|
|
return "/cards"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) GetCardRoute(cardID string) string {
|
|
|
|
return fmt.Sprintf("%s/%s", c.GetCardsRoute(), cardID)
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) GetTeam(teamID string) (*model.Team, *Response) {
|
|
|
|
r, err := c.DoAPIGet(c.GetTeamRoute(teamID), "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.TeamFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
[MM-43781] Feature: boards insights (#3005)
* Add boilerplate functions and handlers for boards insights
* Fix function signatures to add 'duration' parameter, fix where clauses in db queries
* Fix where clause to include boards of which userId in parameter is a member
* Modify queries to work with sqlite, postgres, mysql
* Integration tests, and results of make generate
* Lint Fixes
* Add icons to board insights
* Lint fixes
* Format insights queries without squirrel to fix parameterization issues
* Add tests for sqlstore utility functions
* Improve team insights tests by creating 2 boards
* Refactor endpoints/app to adhere to developments in 7.0 release
* Refactor queries to use squirrel
* Lint fixes
* Fix client, integration tests
* Remove old integration tests
* Add storetests, refactor functions to handle authorized board_ids
* Make queries compatible with mysql, sqlite
* Add app tests
* Fix lint errors
* Revert makefile changes, fix docstring in api
* Lint fixes and doc correction suggested by @wiggin77
* Fix mock store call count error
* adding client code
* Make the following changes
- use serviceAPI to get user.Timezone
- rename licenseAndGuestUserCheck to insightPermissionGate, and handle returned error better
- validate page, perPage parameters aren't < 0
* Lint fix
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Benjamin Cooke <benjamincooke@Benjamins-MacBook-Pro.local>
2022-08-08 08:12:02 +02:00
|
|
|
func (c *Client) GetTeamBoardsInsights(teamID string, userID string, timeRange string, page int, perPage int) (*model.BoardInsightsList, *Response) {
|
|
|
|
query := fmt.Sprintf("?time_range=%v&page=%v&per_page=%v", timeRange, page, perPage)
|
|
|
|
r, err := c.DoAPIGet(c.GetTeamRoute(teamID)+"/boards/insights"+query, "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
var boardInsightsList *model.BoardInsightsList
|
|
|
|
if jsonErr := json.NewDecoder(r.Body).Decode(&boardInsightsList); jsonErr != nil {
|
|
|
|
return nil, BuildErrorResponse(r, jsonErr)
|
|
|
|
}
|
|
|
|
return boardInsightsList, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) GetUserBoardsInsights(teamID string, userID string, timeRange string, page int, perPage int) (*model.BoardInsightsList, *Response) {
|
|
|
|
query := fmt.Sprintf("?time_range=%v&page=%v&per_page=%v&team_id=%v", timeRange, page, perPage, teamID)
|
|
|
|
r, err := c.DoAPIGet(c.GetMeRoute()+"/boards/insights"+query, "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
var boardInsightsList *model.BoardInsightsList
|
|
|
|
if jsonErr := json.NewDecoder(r.Body).Decode(&boardInsightsList); jsonErr != nil {
|
|
|
|
return nil, BuildErrorResponse(r, jsonErr)
|
|
|
|
}
|
|
|
|
return boardInsightsList, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-10-25 22:46:43 +02:00
|
|
|
func (c *Client) GetBlocksForBoard(boardID string) ([]*model.Block, *Response) {
|
2022-03-22 16:24:34 +02:00
|
|
|
r, err := c.DoAPIGet(c.GetBlocksRoute(boardID), "")
|
2020-11-09 14:19:03 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BlocksFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-10-25 22:46:43 +02:00
|
|
|
func (c *Client) GetAllBlocksForBoard(boardID string) ([]*model.Block, *Response) {
|
2022-03-30 00:55:39 +02:00
|
|
|
r, err := c.DoAPIGet(c.GetAllBlocksRoute(boardID), "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BlocksFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-08-23 17:37:49 +02:00
|
|
|
const disableNotifyQueryParam = "disable_notify=true"
|
|
|
|
|
|
|
|
func (c *Client) PatchBlock(boardID, blockID string, blockPatch *model.BlockPatch, disableNotify bool) (bool, *Response) {
|
|
|
|
var queryParams string
|
|
|
|
if disableNotify {
|
|
|
|
queryParams = "?" + disableNotifyQueryParam
|
|
|
|
}
|
|
|
|
r, err := c.DoAPIPatch(c.GetBlockRoute(boardID, blockID)+queryParams, toJSON(blockPatch))
|
2021-08-06 14:10:24 +02:00
|
|
|
if err != nil {
|
|
|
|
return false, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return true, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-03-30 00:55:39 +02:00
|
|
|
func (c *Client) DuplicateBoard(boardID string, asTemplate bool, teamID string) (*model.BoardsAndBlocks, *Response) {
|
2022-03-22 16:24:34 +02:00
|
|
|
queryParams := "?asTemplate=false&"
|
|
|
|
if asTemplate {
|
|
|
|
queryParams = "?asTemplate=true"
|
|
|
|
}
|
2022-03-30 00:55:39 +02:00
|
|
|
if len(teamID) > 0 {
|
|
|
|
queryParams = queryParams + "&toTeam=" + teamID
|
|
|
|
}
|
2022-03-22 16:24:34 +02:00
|
|
|
r, err := c.DoAPIPost(c.GetBoardRoute(boardID)+"/duplicate"+queryParams, "")
|
2020-11-09 14:19:03 +02:00
|
|
|
if err != nil {
|
2022-03-30 00:55:39 +02:00
|
|
|
return nil, BuildErrorResponse(r, err)
|
2020-11-09 14:19:03 +02:00
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
2022-03-30 00:55:39 +02:00
|
|
|
return model.BoardsAndBlocksFromJSON(r.Body), BuildResponse(r)
|
2020-11-09 14:19:03 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) DuplicateBlock(boardID, blockID string, asTemplate bool) (bool, *Response) {
|
|
|
|
queryParams := "?asTemplate=false"
|
|
|
|
if asTemplate {
|
|
|
|
queryParams = "?asTemplate=true"
|
|
|
|
}
|
|
|
|
r, err := c.DoAPIPost(c.GetBlockRoute(boardID, blockID)+"/duplicate"+queryParams, "")
|
2020-11-09 14:19:03 +02:00
|
|
|
if err != nil {
|
|
|
|
return false, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return true, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) UndeleteBlock(boardID, blockID string) (bool, *Response) {
|
|
|
|
r, err := c.DoAPIPost(c.GetBlockRoute(boardID, blockID)+"/undelete", "")
|
|
|
|
if err != nil {
|
|
|
|
return false, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return true, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-10-25 22:46:43 +02:00
|
|
|
func (c *Client) InsertBlocks(boardID string, blocks []*model.Block, disableNotify bool) ([]*model.Block, *Response) {
|
2022-08-23 17:37:49 +02:00
|
|
|
var queryParams string
|
|
|
|
if disableNotify {
|
|
|
|
queryParams = "?" + disableNotifyQueryParam
|
2022-03-22 16:24:34 +02:00
|
|
|
}
|
2022-08-23 17:37:49 +02:00
|
|
|
r, err := c.DoAPIPost(c.GetBlocksRoute(boardID)+queryParams, toJSON(blocks))
|
2022-07-19 17:26:01 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BlocksFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-08-23 17:37:49 +02:00
|
|
|
func (c *Client) DeleteBlock(boardID, blockID string, disableNotify bool) (bool, *Response) {
|
|
|
|
var queryParams string
|
|
|
|
if disableNotify {
|
|
|
|
queryParams = "?" + disableNotifyQueryParam
|
|
|
|
}
|
|
|
|
r, err := c.DoAPIDelete(c.GetBlockRoute(boardID, blockID)+queryParams, "")
|
2022-02-22 19:42:49 +02:00
|
|
|
if err != nil {
|
|
|
|
return false, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return true, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-09-08 13:01:33 +02:00
|
|
|
//
|
|
|
|
// Cards
|
|
|
|
//
|
|
|
|
|
|
|
|
func (c *Client) CreateCard(boardID string, card *model.Card, disableNotify bool) (*model.Card, *Response) {
|
|
|
|
var queryParams string
|
|
|
|
if disableNotify {
|
|
|
|
queryParams = "?" + disableNotifyQueryParam
|
|
|
|
}
|
|
|
|
r, err := c.DoAPIPost(c.GetBoardRoute(boardID)+"/cards"+queryParams, toJSON(card))
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
var cardNew *model.Card
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&cardNew); err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cardNew, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) GetCards(boardID string, page int, perPage int) ([]*model.Card, *Response) {
|
|
|
|
url := fmt.Sprintf("%s/cards?page=%d&per_page=%d", c.GetBoardRoute(boardID), page, perPage)
|
|
|
|
r, err := c.DoAPIGet(url, "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var cards []*model.Card
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&cards); err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cards, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) PatchCard(cardID string, cardPatch *model.CardPatch, disableNotify bool) (*model.Card, *Response) {
|
|
|
|
var queryParams string
|
|
|
|
if disableNotify {
|
|
|
|
queryParams = "?" + disableNotifyQueryParam
|
|
|
|
}
|
|
|
|
r, err := c.DoAPIPatch(c.GetCardRoute(cardID)+queryParams, toJSON(cardPatch))
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var cardNew *model.Card
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&cardNew); err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return cardNew, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) GetCard(cardID string) (*model.Card, *Response) {
|
|
|
|
r, err := c.DoAPIGet(c.GetCardRoute(cardID), "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
var card *model.Card
|
|
|
|
if err := json.NewDecoder(r.Body).Decode(&card); err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return card, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
//
|
2022-03-22 16:24:34 +02:00
|
|
|
// Boards and blocks.
|
2022-09-08 13:01:33 +02:00
|
|
|
//
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) CreateBoardsAndBlocks(bab *model.BoardsAndBlocks) (*model.BoardsAndBlocks, *Response) {
|
|
|
|
r, err := c.DoAPIPost(c.GetBoardsAndBlocksRoute(), toJSON(bab))
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BoardsAndBlocksFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-08-10 13:01:34 +02:00
|
|
|
func (c *Client) CreateCategory(category model.Category) (*model.Category, *Response) {
|
|
|
|
r, err := c.DoAPIPost(c.GetTeamRoute(category.TeamID)+"/categories", toJSON(category))
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.CategoryFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-11-24 12:01:32 +02:00
|
|
|
func (c *Client) DeleteCategory(teamID, categoryID string) *Response {
|
|
|
|
r, err := c.DoAPIDelete(c.GetTeamRoute(teamID)+"/categories/"+categoryID, "")
|
|
|
|
if err != nil {
|
|
|
|
return BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-08-10 13:01:34 +02:00
|
|
|
func (c *Client) UpdateCategoryBoard(teamID, categoryID, boardID string) *Response {
|
|
|
|
r, err := c.DoAPIPost(fmt.Sprintf("%s/categories/%s/boards/%s", c.GetTeamRoute(teamID), categoryID, boardID), "")
|
|
|
|
if err != nil {
|
|
|
|
return BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) GetUserCategoryBoards(teamID string) ([]model.CategoryBoards, *Response) {
|
|
|
|
r, err := c.DoAPIGet(c.GetTeamRoute(teamID)+"/categories", "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
var categoryBoards []model.CategoryBoards
|
|
|
|
_ = json.NewDecoder(r.Body).Decode(&categoryBoards)
|
|
|
|
return categoryBoards, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-11-24 12:01:32 +02:00
|
|
|
func (c *Client) ReorderCategories(teamID string, newOrder []string) ([]string, *Response) {
|
|
|
|
r, err := c.DoAPIPut(c.GetTeamRoute(teamID)+"/categories/reorder", toJSON(newOrder))
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
var updatedCategoryOrder []string
|
|
|
|
_ = json.NewDecoder(r.Body).Decode(&updatedCategoryOrder)
|
|
|
|
return updatedCategoryOrder, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ReorderCategoryBoards(teamID, categoryID string, newOrder []string) ([]string, *Response) {
|
|
|
|
r, err := c.DoAPIPut(c.GetTeamRoute(teamID)+"/categories/"+categoryID+"/reorder", toJSON(newOrder))
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
var updatedBoardsOrder []string
|
|
|
|
_ = json.NewDecoder(r.Body).Decode(&updatedBoardsOrder)
|
|
|
|
return updatedBoardsOrder, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) PatchBoardsAndBlocks(pbab *model.PatchBoardsAndBlocks) (*model.BoardsAndBlocks, *Response) {
|
|
|
|
r, err := c.DoAPIPatch(c.GetBoardsAndBlocksRoute(), toJSON(pbab))
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BoardsAndBlocksFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) DeleteBoardsAndBlocks(dbab *model.DeleteBoardsAndBlocks) (bool, *Response) {
|
|
|
|
r, err := c.DoAPIDelete(c.GetBoardsAndBlocksRoute(), toJSON(dbab))
|
|
|
|
if err != nil {
|
|
|
|
return false, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return true, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2021-01-13 02:44:50 +02:00
|
|
|
// Sharing
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) GetSharingRoute(boardID string) string {
|
|
|
|
return fmt.Sprintf("%s/sharing", c.GetBoardRoute(boardID))
|
2021-01-13 02:44:50 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) GetSharing(boardID string) (*model.Sharing, *Response) {
|
|
|
|
r, err := c.DoAPIGet(c.GetSharingRoute(boardID), "")
|
2021-01-13 02:44:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
sharing := model.SharingFromJSON(r.Body)
|
|
|
|
return &sharing, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) PostSharing(sharing *model.Sharing) (bool, *Response) {
|
2021-06-21 11:21:42 +02:00
|
|
|
r, err := c.DoAPIPost(c.GetSharingRoute(sharing.ID), toJSON(sharing))
|
2021-01-13 02:44:50 +02:00
|
|
|
if err != nil {
|
|
|
|
return false, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return true, BuildResponse(r)
|
|
|
|
}
|
2021-08-10 04:57:45 +02:00
|
|
|
|
|
|
|
func (c *Client) GetRegisterRoute() string {
|
|
|
|
return "/register"
|
|
|
|
}
|
|
|
|
|
2022-08-10 14:20:42 +02:00
|
|
|
func (c *Client) Register(request *model.RegisterRequest) (bool, *Response) {
|
2021-08-10 04:57:45 +02:00
|
|
|
r, err := c.DoAPIPost(c.GetRegisterRoute(), toJSON(&request))
|
|
|
|
if err != nil {
|
|
|
|
return false, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return true, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) GetLoginRoute() string {
|
|
|
|
return "/login"
|
|
|
|
}
|
|
|
|
|
2022-08-10 14:20:42 +02:00
|
|
|
func (c *Client) Login(request *model.LoginRequest) (*model.LoginResponse, *Response) {
|
2021-08-10 04:57:45 +02:00
|
|
|
r, err := c.DoAPIPost(c.GetLoginRoute(), toJSON(&request))
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
2022-08-10 14:20:42 +02:00
|
|
|
data, err := model.LoginResponseFromJSON(r.Body)
|
2021-08-10 04:57:45 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
if data.Token != "" {
|
|
|
|
c.Token = data.Token
|
|
|
|
}
|
|
|
|
|
|
|
|
return data, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) GetMeRoute() string {
|
|
|
|
return "/users/me"
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) GetMe() (*model.User, *Response) {
|
|
|
|
r, err := c.DoAPIGet(c.GetMeRoute(), "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
me, err := model.UserFromJSON(r.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
return me, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-04-19 19:00:52 +02:00
|
|
|
func (c *Client) GetUserID() string {
|
|
|
|
me, _ := c.GetMe()
|
|
|
|
if me == nil {
|
|
|
|
return ""
|
|
|
|
}
|
|
|
|
return me.ID
|
|
|
|
}
|
|
|
|
|
2021-08-10 04:57:45 +02:00
|
|
|
func (c *Client) GetUserRoute(id string) string {
|
|
|
|
return fmt.Sprintf("/users/%s", id)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) GetUser(id string) (*model.User, *Response) {
|
|
|
|
r, err := c.DoAPIGet(c.GetUserRoute(id), "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
user, err := model.UserFromJSON(r.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
return user, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) GetUserChangePasswordRoute(id string) string {
|
|
|
|
return fmt.Sprintf("/users/%s/changepassword", id)
|
|
|
|
}
|
|
|
|
|
2022-08-10 14:20:42 +02:00
|
|
|
func (c *Client) UserChangePassword(id string, data *model.ChangePasswordRequest) (bool, *Response) {
|
2021-08-10 04:57:45 +02:00
|
|
|
r, err := c.DoAPIPost(c.GetUserChangePasswordRoute(id), toJSON(&data))
|
|
|
|
if err != nil {
|
|
|
|
return false, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return true, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) CreateBoard(board *model.Board) (*model.Board, *Response) {
|
|
|
|
r, err := c.DoAPIPost(c.GetBoardsRoute(), toJSON(board))
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BoardFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) PatchBoard(boardID string, patch *model.BoardPatch) (*model.Board, *Response) {
|
|
|
|
r, err := c.DoAPIPatch(c.GetBoardRoute(boardID), toJSON(patch))
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BoardFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) DeleteBoard(boardID string) (bool, *Response) {
|
|
|
|
r, err := c.DoAPIDelete(c.GetBoardRoute(boardID), "")
|
|
|
|
if err != nil {
|
|
|
|
return false, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return true, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-04-08 19:31:28 +02:00
|
|
|
func (c *Client) UndeleteBoard(boardID string) (bool, *Response) {
|
|
|
|
r, err := c.DoAPIPost(c.GetBoardRoute(boardID)+"/undelete", "")
|
|
|
|
if err != nil {
|
|
|
|
return false, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return true, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) GetBoard(boardID, readToken string) (*model.Board, *Response) {
|
|
|
|
url := c.GetBoardRoute(boardID)
|
|
|
|
if readToken != "" {
|
|
|
|
url += fmt.Sprintf("?read_token=%s", readToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
r, err := c.DoAPIGet(url, "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BoardFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
GetBoardMetadata API (#2569)
* wip
* Added data migration for populating categories
* wip
* Added data migration for populating categories
* Store WIP
* migration WIP
* category CRUD APIs complete
* category block API WIP
* block category update API done
* Fetcehed data into store
* Started displayting sidebar data
* sidebar WIP
* Dashboard - basic changes
* Sidebar dashboard btn and board switcher UI only
* Sidebar dashboard btn and board switcher UI only
* create category dialog WIP
* Create category webapp side done
* Integrated move card to other category
* board to block
* Disabled dashboard route for now as we'll implement it in phase 2
* WIP
* Added logic to open last board/view on per team level
* Add workspace to teams and boards migrations (#1986)
* Add workspace to teams and boards migrations
* Update json annotations on board models
* boards search dialog WIP
* Seach dialog WIP
* Implemented opening boiard from search results
* Boards switcher styliung
* Handled update category WS event
* Template support
* personal server support and styling fixes
* test fix WIP
* Fixed a bug causing boards to not be moved correctly beteen categories
* Fixed webapp tests
* fix
* Store changes (#2011)
* Permissions phase 1 - Websocket updates (#2014)
* Store changes
* Websockets changes
* Permissions phase 1 - Permissions service (#2015)
* Store changes
* Websockets changes
* Permissions service
* Api and app updates (#2016)
* Store changes
* Websockets changes
* Permissions service
* New API and App changes
* Delete and Patch boards and blocks endpoints
* Used correct variable
* Webapp changes WIP
* Open correct team URL
* Fixed get block API
* Used React context for workspace users
* WIP
* On load navigation sorted out
* WIP
* Nav fix
* categories WS broadcast
* Used real search API
* Fixed unfurl ppreview
* set active team in sidebar
* IMplemented navigation on changing team in sidebar
* Misc fixes
* close rows inside transaction (#2045)
* update syntax for mysql (#2044)
* Upadted mutator for new patchBlock API
* Updated patchBlock API to use new URL
* Listeining to correct event in plugin mode
* Implemented WS messages for category operations:
* Fix duplicated build tags on Makefile
* Sidebar enhancements
* Add missing prefix to SQLite migration and fix flaky tests
* Sidebar boards menu enhancement
* Fix board page interactions (#2144)
* Fix patch board card properties error
* Fix board interactions
* Fix insert blocks interactions
* Fix app tests (#2104)
* Add json1 tag to vscode launch (#2157)
* Fix add, delete and update boards and add board patch generation (#2146)
* Fix update boards and add board patch generation
* Make add board and add template work, as well as deleting a board
* Update the state on board deletion
* Delete unused variable
* Fix bad parenthesis
* Fix board creation inside plugin, options were coming null due websocket message serialization
* update property type mutators to use boards API (#2168)
* Add permissions modal (#2196)
* Initial integration
* Permissions modal, websocket updates and API tests implemented
* Avoid updating/removing user if there is only one admin left
* Fix duplicates on board search
* Adds integration test
* Addressing PR review comments
Co-authored-by: Jesús Espino <jespinog@gmail.com>
* Merge
* I'm able to compile now
* Some fixes around tests execution
* Fixing migrations
* Fixing migrations order
* WIP
* Fixing some other compilation problems on tests
* Some typescript tests fixed
* Fixing javascript tests
* Fixing compilation
* Fixing some problems to create boards
* Load the templates on initial load
* Improvements over initial team templates import
* Adding new fields in the database
* Working on adding duplicate board api
* Removing RootID concept entirely
* Improving a bit the subscriptions
* Fixing store tests for notificationHints
* Fixing more tests
* fixing tests
* Fixing tests
* Fixing tests
* Fixing some small bugs related to templates
* Fixing registration link generation/regeneration
* Fixing cypress tests
* Adding store tests for duplicateBoard and duplicateBlock
* Addressing some TODO comments
* Making the export api simpler
* Add redirect component for old workspace urls
* Removing Dashboard code
* Delete only the built-in templates on update
* fixing tests
* Adding users autocompletion
* Updating snapshots
* Fixing bad merge
* fix panic when creating new card in notifysubscriptions (#2352)
* fix lint errors (#2353)
* fix lint errors
* fix panic when creating new card in notifysubscriptions (#2352)
* fix lint errors
* fix unit test
* Revert "fix unit test"
This reverts commit 0ad78aed65745521c0bb45790c9ea91b6c316c44.
Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
* fix sql syntax error for SearchUsersByTeam (#2357)
* Fix mentions delivery (#2358)
* fix sql syntax error for SearchUsersByTeam
* fix mentions delivery
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* update api for octoClient calls, pass correct variables to mutator (#2359)
* Fixing tests after merge
* Fix sidebar context menu UI issue (#2399)
* Fix notification diff for text blocks (#2386)
* fix notification diff for text blocks; fix various linter errors.
* fix URLs to cards
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Permissions branch: Fix card links (#2391)
* fix notification diff for text blocks; fix various linter errors.
* fix URLs to cards
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Fixing sqlite tests
* Fixing server tests
* Update migrations to create global templates. (#2397)
* fix duplicate templates
* revert migrate.go
* update UI for empty templates
* implement updating built-in templates as global (teamId = 0)
* handle error if board not found
* update unit test
* fix more tests
* Update blocks_test.go
Fix merge issue
* fix migration sql error (#2414)
* Fixing frontend tests
* Set target team ID when using a global template (#2419)
* Fix some server tests
* Fixing onboarding creation
* Permissions branch: Fix unit tests and CI errors (part 1) (#2425)
* Fixing some small memory leaks (#2400)
* Fixing some small memory leaks
* fixing tests
* passing the tags to all test targets
* Increasing the timeout of the tests
* Fix some type checkings
* Permissions branch: Fixes all the linter errors (#2429)
* fix linter errors
* Reestructuring the router and splitting in more subcomponents (#2403)
* Reestructuring the router and splitting in more subcomponents
* Removing console.log calls
* Removing unneeded selector
* Addressing PR comment
* Fix redirection to one team when you load directly the boards home path
* Using properly the lastTeamID to redirect the user if needed
* don't allow last admin change/deleted (#2416)
* don't allow last admin change/deleted
* update for i18-extract
* fixed en.json
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Harshil Sharma <harshilsharma63@gmail.com>
* Splitting BoardPage component into simpler/smaller components (#2435)
* Splitting BoardPage component into simpler/smaller components
* Removing unneeded import
* Replace go migrate with morph permissions (#2424)
* merge origin/replace-go-migrate-with-morph
* run go mod tidy on mattermost-plugin and increase test timeout
* fix merge issue temprorarily
* remove some debug changes
* fixing the linter
* Allow always team 0 (global) templates fetch (#2472)
* Fix problem with viewId 0 in the URL (#2473)
* Migrate from binddata to goembed (#2471)
* Adding join logic to the board switcher (#2434)
* Adding join logic to the board switcher
* Using already existing client function and removing the joinBoard one
* Adding support for autojoin based on url
* Fixing frontend tests
* fix webapp compile error, missing enableSharedBoards (#2501)
* Fixing duplication on postgres
* Adding back views to the sidebar (#2494)
* Fix #2507. Update Swagger comments (#2508)
* Fix the flash of the template selector on board/team switch (#2490)
* Fix the flash of the template selector on board/team switch
* More fixes specially around error handling
* Fixing the bot badge (#2487)
* simplifying a bit the team store sync between channels and focalboard (#2481)
* Fix menu tests (#2528)
* fix failing menu tests
* fix lint error
* Added keyboard shortcut for boards switcher (#2407)
* Added keyboard shortcut for boards switcher
* Fixed a type error
* Added some inline comments
* Fixed lint
* Fixed bug with scroll jumping when the card is opened: (#2477)
- avoid remounting of `ScrollingComponent` for each render of `Kanban` component
- property `autoFocus` set to false for `CalculationOptions` because it triggers `blur` even for the button in Jest tests and closes the menu
- snapshots for tests with `CalculationOptions` updated
* Adding the frontend support for permissions and applying it to a big part of the interface. (#2536)
* Initial work on permissions gates
* Applying permissions gates in more places
* Adding more checks to the interface
* Adding more permissions gates and keeping the store up to date
* fixing some tests
* Fixing some more tests
* Fixing another test
* Fixing all tests and adding some more
* Adding no-permission snapshot tests
* Addressing PR review comments
* Fixing invert behavior
* Permissions branch: No sqlstore calls after app shutdown (#2530)
* fix webapp compile error, missing enableSharedBoards
* refactor app init wip
* - ensure all block change notifications are finished before shutting down app
- fix unit tests for mysql (insert_at only has 1 second resolution!)
* adjust logging
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Fixed migrations to allow upgrading from previous version (#2535)
* Added mechanism to check if schema migration is needed
* WIP
* WIP
* WIP
* WIP
* Fixed migration
* Fixed for SQLite
* minor cleaniup
* Deleted old schema migration table after running migrations
* Removed a debug log
* Fixed a bug where the code always tried to delete a table which may or may not exist
* Show properly the user avatar in the ShareBoard component (#2542)
* Fixing the last CI problems from the permissions-branch (#2541)
* Fix history ordering
* Giving some times to avoid possible race conditions
* Empty
* Reverting accidental change in the config.json
* Optimizing table view (#2540)
* Optimizing table view
* Reducing the amount of rendering for tables
* Some other performance improvements
* Improve the activeView updates
* Some extra simplifications
* Another small improvement
* Fixing tests
* Fixing linter errors
* Reducing a bit the amount of dependency with big objects in the store
* Small simplification
* Removing Commenter role from the user role selector (#2561)
* Shareboard cleanup (#2550)
* Initial work on permissions gates
* Applying permissions gates in more places
* Adding more checks to the interface
* Adding more permissions gates and keeping the store up to date
* fixing some tests
* Fixing some more tests
* Fixing another test
* Fixing all tests and adding some more
* Adding no-permission snapshot tests
* Addressing PR review comments
* cleanup some shareboard settings
* remove unused property, fix for user items being displayed for non admin
* revert change, allow users to show
Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* GetBoardMetadata API
* Integration tests. WIP
* getBoardHistory
* Working integration test
* Fix ordering, add store tests
* Fix: Update board_history update_at on patch
* sqltests
* Fix unmarshall delete boards_history
* testGetBlockMetadata with delete and undelete
* Handle board not found
* Fixing comments and cards with the new optimizations in the store (#2560)
* Fixing property creation (#2563)
* Cleanup
* Fix user selection in table view (#2565)
* Fixing focus new row in table view (#2567)
* Permissions branch: Fix sqlite table lock (CI) (#2568)
* fix sqlite table lock
* remove test db on teardown
* revert .gitignore
* fix goimport on migration code
* fix typo
* more linter fixes
* clean up tmp db for sqlstore tests
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
* Fixing snapshots
* Remove debug log
* Return metadata for deleted boards
* Migrating center panel to functional component (#2562)
* Migrating center panel to functional component
* Fixing some tests
* Fixing another test
* Fixing linter errors
* Fixing types errors
* Fixing linter error
* Fixing cypress tests
* Fixing the last cypress test
* Simpliying a bit the code
* Making property insertion more robust
* Updating checkbox test
* License check
* Cleanup and update Swagger docs
* Merge from main
* Fix bad merge
* Fix Linux-app build break
* do mod tidy
* Fix server lint
* Require credentials (not only read token)
* Add missing defer CloseRows
* do mod tidy
Co-authored-by: Harshil Sharma <harshilsharma63@gmail.com>
Co-authored-by: Miguel de la Cruz <miguel@mcrx.me>
Co-authored-by: Scott Bishel <scott.bishel@mattermost.com>
Co-authored-by: Jesús Espino <jespinog@gmail.com>
Co-authored-by: Doug Lauder <wiggin77@warpmail.net>
Co-authored-by: Mattermod <mattermod@users.noreply.github.com>
Co-authored-by: Harshil Sharma <18575143+harshilsharma63@users.noreply.github.com>
Co-authored-by: Ibrahim Serdar Acikgoz <serdaracikgoz86@gmail.com>
Co-authored-by: kamre <eremchenko@gmail.com>
2022-03-29 23:47:49 +02:00
|
|
|
func (c *Client) GetBoardMetadata(boardID, readToken string) (*model.BoardMetadata, *Response) {
|
|
|
|
url := c.GetBoardMetadataRoute(boardID)
|
|
|
|
if readToken != "" {
|
|
|
|
url += fmt.Sprintf("?read_token=%s", readToken)
|
|
|
|
}
|
|
|
|
|
|
|
|
r, err := c.DoAPIGet(url, "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BoardMetadataFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) GetBoardsForTeam(teamID string) ([]*model.Board, *Response) {
|
|
|
|
r, err := c.DoAPIGet(c.GetTeamRoute(teamID)+"/boards", "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BoardsFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-12-16 18:46:00 +02:00
|
|
|
func (c *Client) SearchBoardsForUser(teamID, term string, field model.BoardSearchField) ([]*model.Board, *Response) {
|
|
|
|
query := fmt.Sprintf("q=%s&field=%s", term, field)
|
|
|
|
r, err := c.DoAPIGet(c.GetTeamRoute(teamID)+"/boards/search?"+query, "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BoardsFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) SearchBoardsForTeam(teamID, term string) ([]*model.Board, *Response) {
|
|
|
|
r, err := c.DoAPIGet(c.GetTeamRoute(teamID)+"/boards/search?q="+term, "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BoardsFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) GetMembersForBoard(boardID string) ([]*model.BoardMember, *Response) {
|
|
|
|
r, err := c.DoAPIGet(c.GetBoardRoute(boardID)+"/members", "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BoardMembersFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) AddMemberToBoard(member *model.BoardMember) (*model.BoardMember, *Response) {
|
|
|
|
r, err := c.DoAPIPost(c.GetBoardRoute(member.BoardID)+"/members", toJSON(member))
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BoardMemberFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-03-29 10:14:33 +02:00
|
|
|
func (c *Client) JoinBoard(boardID string) (*model.BoardMember, *Response) {
|
|
|
|
r, err := c.DoAPIPost(c.GetJoinBoardRoute(boardID), "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BoardMemberFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-04-05 17:00:04 +02:00
|
|
|
func (c *Client) LeaveBoard(boardID string) (*model.BoardMember, *Response) {
|
|
|
|
r, err := c.DoAPIPost(c.GetLeaveBoardRoute(boardID), "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BoardMemberFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) UpdateBoardMember(member *model.BoardMember) (*model.BoardMember, *Response) {
|
|
|
|
r, err := c.DoAPIPut(c.GetBoardRoute(member.BoardID)+"/members/"+member.UserID, toJSON(member))
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BoardMemberFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) DeleteBoardMember(member *model.BoardMember) (bool, *Response) {
|
|
|
|
r, err := c.DoAPIDelete(c.GetBoardRoute(member.BoardID)+"/members/"+member.UserID, "")
|
|
|
|
if err != nil {
|
|
|
|
return false, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return true, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) GetTeamUploadFileRoute(teamID, boardID string) string {
|
|
|
|
return fmt.Sprintf("%s/%s/files", c.GetTeamRoute(teamID), boardID)
|
2021-08-10 04:57:45 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) TeamUploadFile(teamID, boardID string, data io.Reader) (*api.FileUploadResponse, *Response) {
|
2021-08-10 04:57:45 +02:00
|
|
|
body := &bytes.Buffer{}
|
|
|
|
writer := multipart.NewWriter(body)
|
|
|
|
part, err := writer.CreateFormFile(api.UploadFormFileKey, "file")
|
|
|
|
if err != nil {
|
|
|
|
return nil, &Response{Error: err}
|
|
|
|
}
|
|
|
|
if _, err = io.Copy(part, data); err != nil {
|
|
|
|
return nil, &Response{Error: err}
|
|
|
|
}
|
|
|
|
writer.Close()
|
|
|
|
|
|
|
|
opt := func(r *http.Request) {
|
|
|
|
r.Header.Add("Content-Type", writer.FormDataContentType())
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
r, err := c.doAPIRequestReader(http.MethodPost, c.APIURL+c.GetTeamUploadFileRoute(teamID, boardID), body, "", opt)
|
2021-08-10 04:57:45 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
fileUploadResponse, err := api.FileUploadResponseFromJSON(r.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return fileUploadResponse, BuildResponse(r)
|
|
|
|
}
|
2021-12-10 17:46:37 +02:00
|
|
|
|
2022-11-24 13:46:59 +02:00
|
|
|
func (c *Client) TeamUploadFileInfo(teamID, boardID string, fileName string) (*mmModel.FileInfo, *Response) {
|
|
|
|
r, err := c.DoAPIGet(fmt.Sprintf("/files/teams/%s/%s/%s/info", teamID, boardID, fileName), "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
fileInfoResponse, error := api.FileInfoResponseFromJSON(r.Body)
|
|
|
|
if error != nil {
|
|
|
|
return nil, BuildErrorResponse(r, error)
|
|
|
|
}
|
|
|
|
return fileInfoResponse, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) GetSubscriptionsRoute() string {
|
|
|
|
return "/subscriptions"
|
2021-12-10 17:46:37 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) CreateSubscription(sub *model.Subscription) (*model.Subscription, *Response) {
|
|
|
|
r, err := c.DoAPIPost(c.GetSubscriptionsRoute(), toJSON(&sub))
|
2021-12-10 17:46:37 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
subNew, err := model.SubscriptionFromJSON(r.Body)
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
return subNew, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) DeleteSubscription(blockID string, subscriberID string) *Response {
|
|
|
|
url := fmt.Sprintf("%s/%s/%s", c.GetSubscriptionsRoute(), blockID, subscriberID)
|
2021-12-10 17:46:37 +02:00
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
r, err := c.DoAPIDelete(url, "")
|
2021-12-10 17:46:37 +02:00
|
|
|
if err != nil {
|
|
|
|
return BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-03-22 16:24:34 +02:00
|
|
|
func (c *Client) GetSubscriptions(subscriberID string) ([]*model.Subscription, *Response) {
|
|
|
|
url := fmt.Sprintf("%s/%s", c.GetSubscriptionsRoute(), subscriberID)
|
2021-12-10 17:46:37 +02:00
|
|
|
|
|
|
|
r, err := c.DoAPIGet(url, "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
var subs []*model.Subscription
|
|
|
|
err = json.NewDecoder(r.Body).Decode(&subs)
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return subs, BuildResponse(r)
|
|
|
|
}
|
2022-03-30 00:55:39 +02:00
|
|
|
|
|
|
|
func (c *Client) GetTemplatesForTeam(teamID string) ([]*model.Board, *Response) {
|
|
|
|
r, err := c.DoAPIGet(c.GetTeamRoute(teamID)+"/templates", "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return model.BoardsFromJSON(r.Body), BuildResponse(r)
|
|
|
|
}
|
2022-04-13 05:41:32 +02:00
|
|
|
|
|
|
|
func (c *Client) ExportBoardArchive(boardID string) ([]byte, *Response) {
|
|
|
|
r, err := c.DoAPIGet(c.GetBoardRoute(boardID)+"/archive/export", "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
2022-09-13 12:18:40 +02:00
|
|
|
buf, err := io.ReadAll(r.Body)
|
2022-04-13 05:41:32 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
return buf, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) ImportArchive(teamID string, data io.Reader) *Response {
|
|
|
|
body := &bytes.Buffer{}
|
|
|
|
writer := multipart.NewWriter(body)
|
|
|
|
part, err := writer.CreateFormFile(api.UploadFormFileKey, "file")
|
|
|
|
if err != nil {
|
|
|
|
return &Response{Error: err}
|
|
|
|
}
|
|
|
|
if _, err = io.Copy(part, data); err != nil {
|
|
|
|
return &Response{Error: err}
|
|
|
|
}
|
|
|
|
writer.Close()
|
|
|
|
|
|
|
|
opt := func(r *http.Request) {
|
|
|
|
r.Header.Add("Content-Type", writer.FormDataContentType())
|
|
|
|
}
|
|
|
|
|
|
|
|
r, err := c.doAPIRequestReader(http.MethodPost, c.APIURL+c.GetTeamRoute(teamID)+"/archive/import", body, "", opt)
|
|
|
|
if err != nil {
|
|
|
|
return BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return BuildResponse(r)
|
|
|
|
}
|
2022-06-15 12:17:44 +02:00
|
|
|
|
|
|
|
func (c *Client) GetLimits() (*model.BoardsCloudLimits, *Response) {
|
|
|
|
r, err := c.DoAPIGet("/limits", "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
var limits *model.BoardsCloudLimits
|
|
|
|
err = json.NewDecoder(r.Body).Decode(&limits)
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return limits, BuildResponse(r)
|
|
|
|
}
|
2022-10-25 22:28:00 +02:00
|
|
|
|
2022-11-15 17:59:07 +02:00
|
|
|
func (c *Client) MoveContentBlock(srcBlockID string, dstBlockID string, where string, userID string) (bool, *Response) {
|
|
|
|
r, err := c.DoAPIPost("/content-blocks/"+srcBlockID+"/moveto/"+where+"/"+dstBlockID, "")
|
|
|
|
if err != nil {
|
|
|
|
return false, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
return true, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-10-25 22:28:00 +02:00
|
|
|
func (c *Client) GetStatistics() (*model.BoardsStatistics, *Response) {
|
|
|
|
r, err := c.DoAPIGet("/statistics", "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
|
|
|
var stats *model.BoardsStatistics
|
|
|
|
err = json.NewDecoder(r.Body).Decode(&stats)
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return stats, BuildResponse(r)
|
|
|
|
}
|
2022-12-06 01:03:19 +02:00
|
|
|
|
2022-12-24 06:31:39 +02:00
|
|
|
func (c *Client) GetBoardsForCompliance(teamID string, page, perPage int) (*model.BoardsComplianceResponse, *Response) {
|
2022-12-06 01:03:19 +02:00
|
|
|
query := fmt.Sprintf("?team_id=%s&page=%d&per_page=%d", teamID, page, perPage)
|
|
|
|
r, err := c.DoAPIGet("/admin/boards"+query, "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
2022-12-24 06:31:39 +02:00
|
|
|
var res *model.BoardsComplianceResponse
|
2022-12-06 01:03:19 +02:00
|
|
|
err = json.NewDecoder(r.Body).Decode(&res)
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-12-24 06:31:39 +02:00
|
|
|
func (c *Client) GetBoardsComplianceHistory(
|
2022-12-31 23:33:05 +02:00
|
|
|
modifiedSince int64, includeDeleted bool, teamID string, page, perPage int) (*model.BoardsComplianceHistoryResponse, *Response) {
|
2022-12-24 06:31:39 +02:00
|
|
|
query := fmt.Sprintf("?modified_since=%d&include_deleted=%t&team_id=%s&page=%d&per_page=%d",
|
|
|
|
modifiedSince, includeDeleted, teamID, page, perPage)
|
2022-12-06 01:03:19 +02:00
|
|
|
r, err := c.DoAPIGet("/admin/boards_history"+query, "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
2022-12-24 06:31:39 +02:00
|
|
|
var res *model.BoardsComplianceHistoryResponse
|
2022-12-06 01:03:19 +02:00
|
|
|
err = json.NewDecoder(r.Body).Decode(&res)
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
2022-12-24 06:31:39 +02:00
|
|
|
func (c *Client) GetBlocksComplianceHistory(
|
2022-12-31 23:33:05 +02:00
|
|
|
modifiedSince int64, includeDeleted bool, teamID, boardID string, page, perPage int) (*model.BlocksComplianceHistoryResponse, *Response) {
|
2022-12-24 06:31:39 +02:00
|
|
|
query := fmt.Sprintf("?modified_since=%d&include_deleted=%t&team_id=%s&board_id=%s&page=%d&per_page=%d",
|
|
|
|
modifiedSince, includeDeleted, teamID, boardID, page, perPage)
|
2022-12-06 01:03:19 +02:00
|
|
|
r, err := c.DoAPIGet("/admin/blocks_history"+query, "")
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
defer closeBody(r)
|
|
|
|
|
2022-12-24 06:31:39 +02:00
|
|
|
var res *model.BlocksComplianceHistoryResponse
|
2022-12-06 01:03:19 +02:00
|
|
|
err = json.NewDecoder(r.Body).Decode(&res)
|
|
|
|
if err != nil {
|
|
|
|
return nil, BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return res, BuildResponse(r)
|
|
|
|
}
|
2023-01-24 23:25:23 +02:00
|
|
|
|
2023-01-24 12:11:54 +02:00
|
|
|
func (c *Client) HideBoard(teamID, categoryID, boardID string) *Response {
|
|
|
|
r, err := c.DoAPIPut(c.GetTeamRoute(teamID)+"/categories/"+categoryID+"/boards/"+boardID+"/hide", "")
|
|
|
|
if err != nil {
|
|
|
|
return BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return BuildResponse(r)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) UnhideBoard(teamID, categoryID, boardID string) *Response {
|
|
|
|
r, err := c.DoAPIPut(c.GetTeamRoute(teamID)+"/categories/"+categoryID+"/boards/"+boardID+"/unhide", "")
|
|
|
|
if err != nil {
|
|
|
|
return BuildErrorResponse(r, err)
|
|
|
|
}
|
|
|
|
|
|
|
|
return BuildResponse(r)
|
|
|
|
}
|