2020-10-16 19:20:43 +02:00
|
|
|
package sqlstore
|
2020-10-08 18:21:27 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"database/sql"
|
2020-10-15 23:56:15 +02:00
|
|
|
"encoding/json"
|
2021-08-06 14:10:24 +02:00
|
|
|
"fmt"
|
2020-10-08 18:21:27 +02:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
"github.com/mattermost/focalboard/server/services/store"
|
2021-07-09 03:09:02 +02:00
|
|
|
"github.com/mattermost/focalboard/server/utils"
|
|
|
|
|
2020-10-20 20:00:46 +02:00
|
|
|
sq "github.com/Masterminds/squirrel"
|
2021-07-09 03:09:02 +02:00
|
|
|
_ "github.com/lib/pq" // postgres driver
|
2021-01-26 23:13:46 +01:00
|
|
|
"github.com/mattermost/focalboard/server/model"
|
2021-07-09 03:09:02 +02:00
|
|
|
_ "github.com/mattn/go-sqlite3" // sqlite driver
|
2021-08-25 22:08:01 +02:00
|
|
|
|
|
|
|
"github.com/mattermost/mattermost-server/v6/shared/mlog"
|
2020-10-08 18:21:27 +02:00
|
|
|
)
|
|
|
|
|
2021-12-10 16:46:37 +01:00
|
|
|
const (
|
|
|
|
maxSearchDepth = 50
|
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
|
|
|
descClause = " DESC "
|
2021-12-10 16:46:37 +01:00
|
|
|
)
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
type BoardIDNilError struct{}
|
2021-07-09 03:09:02 +02:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func (re BoardIDNilError) Error() string {
|
|
|
|
return "boardID is nil"
|
2021-07-09 03:09:02 +02:00
|
|
|
}
|
|
|
|
|
2021-08-06 14:10:24 +02:00
|
|
|
type BlockNotFoundErr struct {
|
|
|
|
blockID string
|
|
|
|
}
|
|
|
|
|
|
|
|
func (be BlockNotFoundErr) Error() string {
|
|
|
|
return fmt.Sprintf("block not found (block id: %s", be.blockID)
|
|
|
|
}
|
|
|
|
|
2021-12-21 23:18:55 +01:00
|
|
|
func (s *SQLStore) timestampToCharField(name string, as string) string {
|
|
|
|
switch s.dbType {
|
2022-03-22 15:24:34 +01:00
|
|
|
case model.MysqlDBType:
|
2021-12-21 23:18:55 +01:00
|
|
|
return fmt.Sprintf("date_format(%s, '%%Y-%%m-%%d %%H:%%i:%%S') AS %s", name, as)
|
2022-03-22 15:24:34 +01:00
|
|
|
case model.PostgresDBType:
|
2021-12-21 23:18:55 +01:00
|
|
|
return fmt.Sprintf("to_char(%s, 'YYYY-MM-DD HH:MI:SS.MS') AS %s", name, as)
|
|
|
|
default:
|
|
|
|
return fmt.Sprintf("%s AS %s", name, as)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-22 21:57:00 +02:00
|
|
|
func (s *SQLStore) blockFields() []string {
|
|
|
|
return []string{
|
|
|
|
"id",
|
|
|
|
"parent_id",
|
|
|
|
"created_by",
|
|
|
|
"modified_by",
|
|
|
|
s.escapeField("schema"),
|
|
|
|
"type",
|
|
|
|
"title",
|
|
|
|
"COALESCE(fields, '{}')",
|
2021-12-21 23:18:55 +01:00
|
|
|
s.timestampToCharField("insert_at", "insertAt"),
|
2021-09-22 21:57:00 +02:00
|
|
|
"create_at",
|
|
|
|
"update_at",
|
|
|
|
"delete_at",
|
2022-03-22 15:24:34 +01:00
|
|
|
"COALESCE(board_id, '0')",
|
2021-09-22 21:57:00 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) getBlocksWithParentAndType(db sq.BaseRunner, boardID, parentID string, blockType string) ([]model.Block, error) {
|
2021-10-22 12:48:53 +02:00
|
|
|
query := s.getQueryBuilder(db).
|
2021-09-22 21:57:00 +02:00
|
|
|
Select(s.blockFields()...).
|
2021-04-22 22:53:01 +02:00
|
|
|
From(s.tablePrefix + "blocks").
|
2022-03-22 15:24:34 +01:00
|
|
|
Where(sq.Eq{"board_id": boardID}).
|
2020-10-20 20:00:46 +02:00
|
|
|
Where(sq.Eq{"parent_id": parentID}).
|
|
|
|
Where(sq.Eq{"type": blockType})
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2020-10-20 20:00:46 +02:00
|
|
|
rows, err := query.Query()
|
2020-10-08 18:21:27 +02:00
|
|
|
if err != nil {
|
2021-05-29 08:23:10 +02:00
|
|
|
s.logger.Error(`getBlocksWithParentAndType ERROR`, mlog.Err(err))
|
2020-10-22 13:34:42 +02:00
|
|
|
|
2020-10-16 16:21:42 +02:00
|
|
|
return nil, err
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
2021-07-06 22:44:11 +02:00
|
|
|
defer s.CloseRows(rows)
|
2020-10-08 18:21:27 +02:00
|
|
|
|
2021-05-29 08:23:10 +02:00
|
|
|
return s.blocksFromRows(rows)
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) getBlocksWithParent(db sq.BaseRunner, boardID, parentID string) ([]model.Block, error) {
|
2021-10-22 12:48:53 +02:00
|
|
|
query := s.getQueryBuilder(db).
|
2021-09-22 21:57:00 +02:00
|
|
|
Select(s.blockFields()...).
|
2021-04-22 22:53:01 +02:00
|
|
|
From(s.tablePrefix + "blocks").
|
|
|
|
Where(sq.Eq{"parent_id": parentID}).
|
2022-03-22 15:24:34 +01:00
|
|
|
Where(sq.Eq{"board_id": boardID})
|
2020-10-08 18:21:27 +02:00
|
|
|
|
2020-10-20 20:00:46 +02:00
|
|
|
rows, err := query.Query()
|
2020-10-08 18:21:27 +02:00
|
|
|
if err != nil {
|
2021-05-29 08:23:10 +02:00
|
|
|
s.logger.Error(`getBlocksWithParent ERROR`, mlog.Err(err))
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2020-10-16 16:21:42 +02:00
|
|
|
return nil, err
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
2021-07-06 22:44:11 +02:00
|
|
|
defer s.CloseRows(rows)
|
2020-10-08 18:21:27 +02:00
|
|
|
|
2021-05-29 08:23:10 +02:00
|
|
|
return s.blocksFromRows(rows)
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) getBlocksWithBoardID(db sq.BaseRunner, boardID string) ([]model.Block, error) {
|
2021-10-22 12:48:53 +02:00
|
|
|
query := s.getQueryBuilder(db).
|
2021-09-22 21:57:00 +02:00
|
|
|
Select(s.blockFields()...).
|
2021-05-13 23:04:49 +02:00
|
|
|
From(s.tablePrefix + "blocks").
|
2022-03-22 15:24:34 +01:00
|
|
|
Where(sq.Eq{"board_id": boardID})
|
2021-05-13 23:04:49 +02:00
|
|
|
|
|
|
|
rows, err := query.Query()
|
|
|
|
if err != nil {
|
2022-03-22 15:24:34 +01:00
|
|
|
s.logger.Error(`GetBlocksWithBoardID ERROR`, mlog.Err(err))
|
2021-05-13 23:04:49 +02:00
|
|
|
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-07-06 22:44:11 +02:00
|
|
|
defer s.CloseRows(rows)
|
2021-05-13 23:04:49 +02:00
|
|
|
|
2021-05-29 08:23:10 +02:00
|
|
|
return s.blocksFromRows(rows)
|
2021-05-13 23:04:49 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) getBlocksWithType(db sq.BaseRunner, boardID, blockType string) ([]model.Block, error) {
|
2021-10-22 12:48:53 +02:00
|
|
|
query := s.getQueryBuilder(db).
|
2021-09-22 21:57:00 +02:00
|
|
|
Select(s.blockFields()...).
|
2021-04-22 22:53:01 +02:00
|
|
|
From(s.tablePrefix + "blocks").
|
|
|
|
Where(sq.Eq{"type": blockType}).
|
2022-03-22 15:24:34 +01:00
|
|
|
Where(sq.Eq{"board_id": boardID})
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2020-10-20 20:00:46 +02:00
|
|
|
rows, err := query.Query()
|
2020-10-12 20:02:07 +02:00
|
|
|
if err != nil {
|
2021-05-29 08:23:10 +02:00
|
|
|
s.logger.Error(`getBlocksWithParentAndType ERROR`, mlog.Err(err))
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2020-10-16 16:21:42 +02:00
|
|
|
return nil, err
|
2020-10-12 20:02:07 +02:00
|
|
|
}
|
2021-07-06 22:44:11 +02:00
|
|
|
defer s.CloseRows(rows)
|
2020-10-12 20:02:07 +02:00
|
|
|
|
2021-05-29 08:23:10 +02:00
|
|
|
return s.blocksFromRows(rows)
|
2020-10-12 20:02:07 +02:00
|
|
|
}
|
|
|
|
|
2021-12-10 16:46:37 +01:00
|
|
|
// getSubTree2 returns blocks within 2 levels of the given blockID.
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) getSubTree2(db sq.BaseRunner, boardID string, blockID string, opts model.QuerySubtreeOptions) ([]model.Block, error) {
|
2021-10-22 12:48:53 +02:00
|
|
|
query := s.getQueryBuilder(db).
|
2021-09-22 21:57:00 +02:00
|
|
|
Select(s.blockFields()...).
|
2021-04-22 22:53:01 +02:00
|
|
|
From(s.tablePrefix + "blocks").
|
|
|
|
Where(sq.Or{sq.Eq{"id": blockID}, sq.Eq{"parent_id": blockID}}).
|
2022-03-22 15:24:34 +01:00
|
|
|
Where(sq.Eq{"board_id": boardID}).
|
|
|
|
OrderBy("insert_at, update_at")
|
2021-12-10 16:46:37 +01:00
|
|
|
|
|
|
|
if opts.BeforeUpdateAt != 0 {
|
|
|
|
query = query.Where(sq.LtOrEq{"update_at": opts.BeforeUpdateAt})
|
|
|
|
}
|
|
|
|
|
|
|
|
if opts.AfterUpdateAt != 0 {
|
|
|
|
query = query.Where(sq.GtOrEq{"update_at": opts.AfterUpdateAt})
|
|
|
|
}
|
|
|
|
|
|
|
|
if opts.Limit != 0 {
|
|
|
|
query = query.Limit(opts.Limit)
|
|
|
|
}
|
2020-10-08 18:21:27 +02:00
|
|
|
|
2020-10-20 20:00:46 +02:00
|
|
|
rows, err := query.Query()
|
2020-10-08 18:21:27 +02:00
|
|
|
if err != nil {
|
2021-05-29 08:23:10 +02:00
|
|
|
s.logger.Error(`getSubTree ERROR`, mlog.Err(err))
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2020-10-16 16:21:42 +02:00
|
|
|
return nil, err
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
2021-07-06 22:44:11 +02:00
|
|
|
defer s.CloseRows(rows)
|
2020-10-08 18:21:27 +02:00
|
|
|
|
2021-05-29 08:23:10 +02:00
|
|
|
return s.blocksFromRows(rows)
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) getBlocksForBoard(db sq.BaseRunner, boardID string) ([]model.Block, error) {
|
2021-10-22 12:48:53 +02:00
|
|
|
query := s.getQueryBuilder(db).
|
2021-09-22 21:57:00 +02:00
|
|
|
Select(s.blockFields()...).
|
2021-05-24 18:59:30 +02:00
|
|
|
From(s.tablePrefix + "blocks").
|
2022-03-22 15:24:34 +01:00
|
|
|
Where(sq.Eq{"board_id": boardID})
|
2020-10-08 18:21:27 +02:00
|
|
|
|
2020-10-20 20:00:46 +02:00
|
|
|
rows, err := query.Query()
|
2020-10-08 18:21:27 +02:00
|
|
|
if err != nil {
|
2022-03-22 15:24:34 +01:00
|
|
|
s.logger.Error(`getAllBlocksForBoard ERROR`, mlog.Err(err))
|
2020-10-16 16:21:42 +02:00
|
|
|
return nil, err
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
2021-07-06 22:44:11 +02:00
|
|
|
defer s.CloseRows(rows)
|
2020-10-08 18:21:27 +02:00
|
|
|
|
2021-05-29 08:23:10 +02:00
|
|
|
return s.blocksFromRows(rows)
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
|
|
|
|
2021-05-29 08:23:10 +02:00
|
|
|
func (s *SQLStore) blocksFromRows(rows *sql.Rows) ([]model.Block, error) {
|
2021-03-21 09:28:26 +01:00
|
|
|
results := []model.Block{}
|
2020-10-08 18:21:27 +02:00
|
|
|
|
|
|
|
for rows.Next() {
|
2020-10-16 19:12:53 +02:00
|
|
|
var block model.Block
|
2020-10-15 23:56:15 +02:00
|
|
|
var fieldsJSON string
|
2021-01-12 03:53:08 +01:00
|
|
|
var modifiedBy sql.NullString
|
2021-12-21 23:18:55 +01:00
|
|
|
var insertAt sql.NullString
|
2020-10-22 13:34:42 +02:00
|
|
|
|
2020-10-15 23:56:15 +02:00
|
|
|
err := rows.Scan(
|
|
|
|
&block.ID,
|
|
|
|
&block.ParentID,
|
2021-07-08 16:36:43 +02:00
|
|
|
&block.CreatedBy,
|
2021-01-12 03:53:08 +01:00
|
|
|
&modifiedBy,
|
2020-10-15 23:56:15 +02:00
|
|
|
&block.Schema,
|
|
|
|
&block.Type,
|
|
|
|
&block.Title,
|
|
|
|
&fieldsJSON,
|
2021-12-16 18:43:50 +01:00
|
|
|
&insertAt,
|
2020-10-15 23:56:15 +02:00
|
|
|
&block.CreateAt,
|
|
|
|
&block.UpdateAt,
|
2021-09-22 21:57:00 +02:00
|
|
|
&block.DeleteAt,
|
2022-03-22 15:24:34 +01:00
|
|
|
&block.BoardID)
|
2020-10-08 18:21:27 +02:00
|
|
|
if err != nil {
|
|
|
|
// handle this error
|
2021-05-29 08:23:10 +02:00
|
|
|
s.logger.Error(`ERROR blocksFromRows`, mlog.Err(err))
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2020-10-16 16:21:42 +02:00
|
|
|
return nil, err
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
|
|
|
|
2021-01-12 03:53:08 +01:00
|
|
|
if modifiedBy.Valid {
|
|
|
|
block.ModifiedBy = modifiedBy.String
|
|
|
|
}
|
|
|
|
|
2020-10-15 23:56:15 +02:00
|
|
|
err = json.Unmarshal([]byte(fieldsJSON), &block.Fields)
|
|
|
|
if err != nil {
|
|
|
|
// handle this error
|
2021-05-29 08:23:10 +02:00
|
|
|
s.logger.Error(`ERROR blocksFromRows fields`, mlog.Err(err))
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2020-10-16 16:21:42 +02:00
|
|
|
return nil, err
|
2020-10-15 23:56:15 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
results = append(results, block)
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
|
|
|
|
2020-10-16 16:21:42 +02:00
|
|
|
return results, nil
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) insertBlock(db sq.BaseRunner, block *model.Block, userID string) error {
|
|
|
|
if block.BoardID == "" {
|
|
|
|
return BoardIDNilError{}
|
2020-12-03 23:09:48 +01:00
|
|
|
}
|
|
|
|
|
2020-10-15 23:56:15 +02:00
|
|
|
fieldsJSON, err := json.Marshal(block.Fields)
|
|
|
|
if err != nil {
|
2020-10-16 16:21:42 +02:00
|
|
|
return err
|
2020-10-15 23:56:15 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
existingBlock, err := s.getBlock(db, block.ID)
|
2021-07-08 16:36:43 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-12-10 16:46:37 +01:00
|
|
|
block.UpdateAt = utils.GetMillis()
|
|
|
|
block.ModifiedBy = userID
|
|
|
|
|
2021-10-22 12:48:53 +02:00
|
|
|
insertQuery := s.getQueryBuilder(db).Insert("").
|
2021-01-12 03:53:08 +01:00
|
|
|
Columns(
|
2022-03-22 15:24:34 +01:00
|
|
|
"channel_id",
|
2021-01-12 03:53:08 +01:00
|
|
|
"id",
|
|
|
|
"parent_id",
|
2021-07-08 16:36:43 +02:00
|
|
|
"created_by",
|
2021-01-12 03:53:08 +01:00
|
|
|
"modified_by",
|
2021-04-22 22:53:01 +02:00
|
|
|
s.escapeField("schema"),
|
2021-01-12 03:53:08 +01:00
|
|
|
"type",
|
|
|
|
"title",
|
|
|
|
"fields",
|
|
|
|
"create_at",
|
|
|
|
"update_at",
|
|
|
|
"delete_at",
|
2022-03-22 15:24:34 +01:00
|
|
|
"board_id",
|
2021-07-08 16:36:43 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
insertQueryValues := map[string]interface{}{
|
2022-03-22 15:24:34 +01:00
|
|
|
"channel_id": "",
|
2021-07-08 16:36:43 +02:00
|
|
|
"id": block.ID,
|
|
|
|
"parent_id": block.ParentID,
|
|
|
|
s.escapeField("schema"): block.Schema,
|
|
|
|
"type": block.Type,
|
|
|
|
"title": block.Title,
|
|
|
|
"fields": fieldsJSON,
|
|
|
|
"delete_at": block.DeleteAt,
|
2022-03-22 15:24:34 +01:00
|
|
|
"created_by": userID,
|
2021-07-08 16:36:43 +02:00
|
|
|
"modified_by": block.ModifiedBy,
|
2022-03-22 15:24:34 +01:00
|
|
|
"create_at": utils.GetMillis(),
|
2021-07-08 16:36:43 +02:00
|
|
|
"update_at": block.UpdateAt,
|
2022-03-22 15:24:34 +01:00
|
|
|
"board_id": block.BoardID,
|
2021-04-22 22:53:01 +02:00
|
|
|
}
|
|
|
|
|
2021-07-08 16:36:43 +02:00
|
|
|
if existingBlock != nil {
|
|
|
|
// block with ID exists, so this is an update operation
|
2021-10-22 12:48:53 +02:00
|
|
|
query := s.getQueryBuilder(db).Update(s.tablePrefix+"blocks").
|
2021-07-08 16:36:43 +02:00
|
|
|
Where(sq.Eq{"id": block.ID}).
|
2022-03-22 15:24:34 +01:00
|
|
|
Where(sq.Eq{"board_id": block.BoardID}).
|
2021-07-08 16:36:43 +02:00
|
|
|
Set("parent_id", block.ParentID).
|
|
|
|
Set("modified_by", block.ModifiedBy).
|
|
|
|
Set(s.escapeField("schema"), block.Schema).
|
|
|
|
Set("type", block.Type).
|
|
|
|
Set("title", block.Title).
|
|
|
|
Set("fields", fieldsJSON).
|
|
|
|
Set("update_at", block.UpdateAt).
|
|
|
|
Set("delete_at", block.DeleteAt)
|
|
|
|
|
2021-10-22 12:48:53 +02:00
|
|
|
if _, err := query.Exec(); err != nil {
|
|
|
|
s.logger.Error(`InsertBlock error occurred while updating existing block`, mlog.String("blockID", block.ID), mlog.Err(err))
|
2022-03-22 15:24:34 +01:00
|
|
|
|
2021-10-22 12:48:53 +02:00
|
|
|
return err
|
2021-07-08 16:36:43 +02:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
block.CreatedBy = userID
|
2021-10-22 12:48:53 +02:00
|
|
|
query := insertQuery.SetMap(insertQueryValues).Into(s.tablePrefix + "blocks")
|
|
|
|
if _, err := query.Exec(); err != nil {
|
2021-07-08 16:36:43 +02:00
|
|
|
return err
|
|
|
|
}
|
2021-04-22 22:53:01 +02:00
|
|
|
}
|
|
|
|
|
2021-07-08 16:36:43 +02:00
|
|
|
// writing block history
|
2021-10-22 12:48:53 +02:00
|
|
|
query := insertQuery.SetMap(insertQueryValues).Into(s.tablePrefix + "blocks_history")
|
|
|
|
if _, err := query.Exec(); err != nil {
|
2020-10-16 16:21:42 +02:00
|
|
|
return err
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2020-10-16 16:21:42 +02:00
|
|
|
return nil
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) patchBlock(db sq.BaseRunner, blockID string, blockPatch *model.BlockPatch, userID string) error {
|
|
|
|
existingBlock, err := s.getBlock(db, blockID)
|
2021-08-06 14:10:24 +02:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
if existingBlock == nil {
|
|
|
|
return BlockNotFoundErr{blockID}
|
|
|
|
}
|
|
|
|
|
|
|
|
block := blockPatch.Patch(existingBlock)
|
2022-03-22 15:24:34 +01:00
|
|
|
return s.insertBlock(db, block, userID)
|
2021-08-06 14:10:24 +02:00
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) patchBlocks(db sq.BaseRunner, blockPatches *model.BlockPatchBatch, userID string) error {
|
2021-12-10 15:17:00 +01:00
|
|
|
for i, blockID := range blockPatches.BlockIDs {
|
2022-03-22 15:24:34 +01:00
|
|
|
err := s.patchBlock(db, blockID, &blockPatches.BlockPatches[i], userID)
|
2021-12-10 15:17:00 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) insertBlocks(db sq.BaseRunner, blocks []model.Block, userID string) error {
|
2022-02-22 22:30:47 +01:00
|
|
|
for _, block := range blocks {
|
2022-03-22 15:24:34 +01:00
|
|
|
if block.BoardID == "" {
|
|
|
|
return BoardIDNilError{}
|
2022-02-22 22:30:47 +01:00
|
|
|
}
|
|
|
|
}
|
2021-12-10 15:17:00 +01:00
|
|
|
for i := range blocks {
|
2022-03-22 15:24:34 +01:00
|
|
|
err := s.insertBlock(db, &blocks[i], userID)
|
2021-12-10 15:17:00 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) deleteBlock(db sq.BaseRunner, blockID string, modifiedBy string) error {
|
|
|
|
block, err := s.getBlock(db, blockID)
|
2021-12-03 18:32:57 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if block == nil {
|
2022-03-22 15:24:34 +01:00
|
|
|
s.logger.Warn("deleteBlock block not found", mlog.String("block_id", blockID))
|
2021-12-03 18:32:57 +01:00
|
|
|
return nil // deleting non-exiting block is not considered an error (for now)
|
|
|
|
}
|
|
|
|
|
|
|
|
fieldsJSON, err := json.Marshal(block.Fields)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-10-07 13:51:01 +02:00
|
|
|
now := utils.GetMillis()
|
2021-10-22 12:48:53 +02:00
|
|
|
insertQuery := s.getQueryBuilder(db).Insert(s.tablePrefix+"blocks_history").
|
2021-01-12 20:16:25 +01:00
|
|
|
Columns(
|
2022-03-22 15:24:34 +01:00
|
|
|
"board_id",
|
2021-01-12 20:16:25 +01:00
|
|
|
"id",
|
2021-12-03 18:32:57 +01:00
|
|
|
"parent_id",
|
2021-12-16 18:43:50 +01:00
|
|
|
s.escapeField("schema"),
|
2021-12-03 18:32:57 +01:00
|
|
|
"type",
|
|
|
|
"title",
|
|
|
|
"fields",
|
2021-01-12 20:16:25 +01:00
|
|
|
"modified_by",
|
2021-12-03 18:32:57 +01:00
|
|
|
"create_at",
|
2021-01-12 20:16:25 +01:00
|
|
|
"update_at",
|
|
|
|
"delete_at",
|
2021-12-03 18:32:57 +01:00
|
|
|
"created_by",
|
2021-01-12 20:16:25 +01:00
|
|
|
).
|
|
|
|
Values(
|
2022-03-22 15:24:34 +01:00
|
|
|
block.BoardID,
|
2021-12-03 18:32:57 +01:00
|
|
|
block.ID,
|
|
|
|
block.ParentID,
|
|
|
|
block.Schema,
|
|
|
|
block.Type,
|
|
|
|
block.Title,
|
|
|
|
fieldsJSON,
|
2021-01-12 20:16:25 +01:00
|
|
|
modifiedBy,
|
2021-12-03 18:32:57 +01:00
|
|
|
block.CreateAt,
|
2021-01-12 20:16:25 +01:00
|
|
|
now,
|
|
|
|
now,
|
2021-12-03 18:32:57 +01:00
|
|
|
block.CreatedBy,
|
2021-01-12 20:16:25 +01:00
|
|
|
)
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2021-10-22 12:48:53 +02:00
|
|
|
if _, err := insertQuery.Exec(); err != nil {
|
2021-04-22 22:53:01 +02:00
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2021-10-22 12:48:53 +02:00
|
|
|
deleteQuery := s.getQueryBuilder(db).
|
2021-04-26 13:43:02 +02:00
|
|
|
Delete(s.tablePrefix + "blocks").
|
2022-03-22 15:24:34 +01:00
|
|
|
Where(sq.Eq{"id": blockID})
|
2021-04-22 22:53:01 +02:00
|
|
|
|
2021-10-22 12:48:53 +02:00
|
|
|
if _, err := deleteQuery.Exec(); err != nil {
|
2020-10-16 16:21:42 +02:00
|
|
|
return err
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
2020-10-22 15:22:36 +02:00
|
|
|
|
2020-10-16 16:21:42 +02:00
|
|
|
return nil
|
2020-10-08 18:21:27 +02:00
|
|
|
}
|
2022-02-22 18:42:49 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) undeleteBlock(db sq.BaseRunner, blockID string, modifiedBy string) error {
|
|
|
|
blocks, err := s.getBlockHistory(db, blockID, model.QueryBlockHistoryOptions{Limit: 1, Descending: true})
|
2022-02-22 18:42:49 +01:00
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(blocks) == 0 {
|
2022-03-22 15:24:34 +01:00
|
|
|
s.logger.Warn("undeleteBlock block not found", mlog.String("block_id", blockID))
|
2022-02-22 18:42:49 +01:00
|
|
|
return nil // deleting non-exiting block is not considered an error (for now)
|
|
|
|
}
|
|
|
|
block := blocks[0]
|
|
|
|
|
|
|
|
if block.DeleteAt == 0 {
|
2022-03-22 15:24:34 +01:00
|
|
|
s.logger.Warn("undeleteBlock block not deleted", mlog.String("block_id", block.ID))
|
2022-02-22 18:42:49 +01:00
|
|
|
return nil // undeleting not deleted block is not considered an error (for now)
|
|
|
|
}
|
|
|
|
|
|
|
|
fieldsJSON, err := json.Marshal(block.Fields)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
now := utils.GetMillis()
|
|
|
|
columns := []string{
|
2022-03-22 15:24:34 +01:00
|
|
|
"board_id",
|
|
|
|
"channel_id",
|
2022-02-22 18:42:49 +01:00
|
|
|
"id",
|
|
|
|
"parent_id",
|
|
|
|
s.escapeField("schema"),
|
|
|
|
"type",
|
|
|
|
"title",
|
|
|
|
"fields",
|
|
|
|
"modified_by",
|
|
|
|
"create_at",
|
|
|
|
"update_at",
|
|
|
|
"delete_at",
|
|
|
|
"created_by",
|
|
|
|
}
|
|
|
|
|
|
|
|
values := []interface{}{
|
2022-03-22 15:24:34 +01:00
|
|
|
block.BoardID,
|
|
|
|
"",
|
2022-02-22 18:42:49 +01:00
|
|
|
block.ID,
|
|
|
|
block.ParentID,
|
|
|
|
block.Schema,
|
|
|
|
block.Type,
|
|
|
|
block.Title,
|
|
|
|
fieldsJSON,
|
|
|
|
modifiedBy,
|
|
|
|
block.CreateAt,
|
|
|
|
now,
|
|
|
|
0,
|
|
|
|
block.CreatedBy,
|
|
|
|
}
|
|
|
|
insertHistoryQuery := s.getQueryBuilder(db).Insert(s.tablePrefix + "blocks_history").
|
|
|
|
Columns(columns...).
|
|
|
|
Values(values...)
|
|
|
|
insertQuery := s.getQueryBuilder(db).Insert(s.tablePrefix + "blocks").
|
|
|
|
Columns(columns...).
|
|
|
|
Values(values...)
|
|
|
|
|
|
|
|
if _, err := insertHistoryQuery.Exec(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := insertQuery.Exec(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
2022-03-22 15:24:34 +01:00
|
|
|
|
2021-10-22 12:48:53 +02:00
|
|
|
func (s *SQLStore) getBlockCountsByType(db sq.BaseRunner) (map[string]int64, error) {
|
|
|
|
query := s.getQueryBuilder(db).
|
2021-06-04 16:38:49 +02:00
|
|
|
Select(
|
|
|
|
"type",
|
|
|
|
"COUNT(*) AS count",
|
|
|
|
).
|
|
|
|
From(s.tablePrefix + "blocks").
|
|
|
|
GroupBy("type")
|
|
|
|
|
|
|
|
rows, err := query.Query()
|
|
|
|
if err != nil {
|
|
|
|
s.logger.Error(`GetBlockCountsByType ERROR`, mlog.Err(err))
|
|
|
|
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-07-06 22:44:11 +02:00
|
|
|
defer s.CloseRows(rows)
|
2021-06-04 16:38:49 +02:00
|
|
|
|
|
|
|
m := make(map[string]int64)
|
|
|
|
|
|
|
|
for rows.Next() {
|
|
|
|
var blockType string
|
|
|
|
var count int64
|
|
|
|
|
|
|
|
err := rows.Scan(&blockType, &count)
|
|
|
|
if err != nil {
|
|
|
|
s.logger.Error("Failed to fetch block count", mlog.Err(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
m[blockType] = count
|
|
|
|
}
|
|
|
|
return m, nil
|
|
|
|
}
|
2021-07-08 16:36:43 +02:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) getBlock(db sq.BaseRunner, blockID string) (*model.Block, error) {
|
2021-10-22 12:48:53 +02:00
|
|
|
query := s.getQueryBuilder(db).
|
2021-09-22 21:57:00 +02:00
|
|
|
Select(s.blockFields()...).
|
2021-07-08 16:36:43 +02:00
|
|
|
From(s.tablePrefix + "blocks").
|
2022-02-04 23:12:28 +01:00
|
|
|
Where(sq.Eq{"id": blockID})
|
|
|
|
|
2021-07-08 16:36:43 +02:00
|
|
|
rows, err := query.Query()
|
|
|
|
if err != nil {
|
|
|
|
s.logger.Error(`GetBlock ERROR`, mlog.Err(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
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
|
|
|
defer s.CloseRows(rows)
|
2021-07-08 16:36:43 +02:00
|
|
|
|
|
|
|
blocks, err := s.blocksFromRows(rows)
|
2021-07-09 05:41:54 +02:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2021-07-08 16:36:43 +02:00
|
|
|
|
|
|
|
if len(blocks) == 0 {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return &blocks[0], nil
|
|
|
|
}
|
2021-11-11 17:01:43 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) getBlockHistory(db sq.BaseRunner, blockID string, opts model.QueryBlockHistoryOptions) ([]model.Block, error) {
|
2021-12-10 16:46:37 +01:00
|
|
|
var order string
|
|
|
|
if opts.Descending {
|
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
|
|
|
order = descClause
|
2021-12-10 16:46:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
query := s.getQueryBuilder(db).
|
|
|
|
Select(s.blockFields()...).
|
|
|
|
From(s.tablePrefix + "blocks_history").
|
|
|
|
Where(sq.Eq{"id": blockID}).
|
2022-03-22 15:24:34 +01:00
|
|
|
OrderBy("insert_at " + order + ", update_at" + order)
|
2021-12-10 16:46:37 +01:00
|
|
|
|
|
|
|
if opts.BeforeUpdateAt != 0 {
|
2022-01-07 16:11:36 +01:00
|
|
|
query = query.Where(sq.Lt{"update_at": opts.BeforeUpdateAt})
|
2021-12-10 16:46:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if opts.AfterUpdateAt != 0 {
|
2022-01-07 16:11:36 +01:00
|
|
|
query = query.Where(sq.Gt{"update_at": opts.AfterUpdateAt})
|
2021-12-10 16:46:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if opts.Limit != 0 {
|
|
|
|
query = query.Limit(opts.Limit)
|
|
|
|
}
|
|
|
|
|
|
|
|
rows, err := query.Query()
|
|
|
|
if err != nil {
|
|
|
|
s.logger.Error(`GetBlockHistory ERROR`, mlog.Err(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
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
|
|
|
defer s.CloseRows(rows)
|
|
|
|
|
|
|
|
return s.blocksFromRows(rows)
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SQLStore) getBlockHistoryDescendants(db sq.BaseRunner, boardID string, opts model.QueryBlockHistoryOptions) ([]model.Block, error) {
|
|
|
|
var order string
|
|
|
|
if opts.Descending {
|
|
|
|
order = descClause
|
|
|
|
}
|
|
|
|
|
|
|
|
query := s.getQueryBuilder(db).
|
|
|
|
Select(s.blockFields()...).
|
|
|
|
From(s.tablePrefix + "blocks_history").
|
|
|
|
Where(sq.Eq{"board_id": boardID}).
|
|
|
|
OrderBy("insert_at " + order + ", update_at" + order)
|
|
|
|
|
|
|
|
if opts.BeforeUpdateAt != 0 {
|
|
|
|
query = query.Where(sq.Lt{"update_at": opts.BeforeUpdateAt})
|
|
|
|
}
|
|
|
|
|
|
|
|
if opts.AfterUpdateAt != 0 {
|
|
|
|
query = query.Where(sq.Gt{"update_at": opts.AfterUpdateAt})
|
|
|
|
}
|
|
|
|
|
|
|
|
if opts.Limit != 0 {
|
|
|
|
query = query.Limit(opts.Limit)
|
|
|
|
}
|
|
|
|
|
|
|
|
rows, err := query.Query()
|
|
|
|
if err != nil {
|
|
|
|
s.logger.Error(`GetBlockHistory ERROR`, mlog.Err(err))
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
defer s.CloseRows(rows)
|
2021-12-10 16:46:37 +01:00
|
|
|
|
|
|
|
return s.blocksFromRows(rows)
|
|
|
|
}
|
|
|
|
|
|
|
|
// getBoardAndCardByID returns the first parent of type `card` and first parent of type `board` for the block specified by ID.
|
|
|
|
// `board` and/or `card` may return nil without error if the block does not belong to a board or card.
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) getBoardAndCardByID(db sq.BaseRunner, blockID string) (board *model.Board, card *model.Block, err error) {
|
2021-12-10 16:46:37 +01:00
|
|
|
// use block_history to fetch block in case it was deleted and no longer exists in blocks table.
|
|
|
|
opts := model.QueryBlockHistoryOptions{
|
|
|
|
Limit: 1,
|
|
|
|
Descending: true,
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err := s.getBlockHistory(db, blockID, opts)
|
2021-12-10 16:46:37 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
if len(blocks) == 0 {
|
|
|
|
return nil, nil, store.NewErrNotFound(blockID)
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
return s.getBoardAndCard(db, &blocks[0])
|
2021-12-10 16:46:37 +01:00
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
// getBoardAndCard returns the first parent of type `card` and and the `board` for the specified block.
|
2021-12-10 16:46:37 +01:00
|
|
|
// `board` and/or `card` may return nil without error if the block does not belong to a board or card.
|
2022-03-22 15:24:34 +01:00
|
|
|
func (s *SQLStore) getBoardAndCard(db sq.BaseRunner, block *model.Block) (board *model.Board, card *model.Block, err error) {
|
2021-12-10 16:46:37 +01:00
|
|
|
var count int // don't let invalid blocks hierarchy cause infinite loop.
|
|
|
|
iter := block
|
|
|
|
|
|
|
|
// use block_history to fetch blocks in case they were deleted and no longer exist in blocks table.
|
|
|
|
opts := model.QueryBlockHistoryOptions{
|
|
|
|
Limit: 1,
|
|
|
|
Descending: true,
|
|
|
|
}
|
|
|
|
|
|
|
|
for {
|
|
|
|
count++
|
|
|
|
if card == nil && iter.Type == model.TypeCard {
|
|
|
|
card = iter
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
if iter.ParentID == "" || card != nil || count > maxSearchDepth {
|
2021-12-10 16:46:37 +01:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
blocks, err2 := s.getBlockHistory(db, iter.ParentID, opts)
|
|
|
|
if err2 != nil {
|
|
|
|
return nil, nil, err2
|
2021-12-10 16:46:37 +01:00
|
|
|
}
|
|
|
|
if len(blocks) == 0 {
|
|
|
|
return board, card, nil
|
|
|
|
}
|
|
|
|
iter = &blocks[0]
|
|
|
|
}
|
2022-03-22 15:24:34 +01:00
|
|
|
board, err = s.getBoard(db, block.BoardID)
|
2021-11-11 17:01:43 +01:00
|
|
|
if err != nil {
|
2022-03-22 15:24:34 +01:00
|
|
|
return nil, nil, err
|
2021-11-11 17:01:43 +01:00
|
|
|
}
|
2022-03-22 15:24:34 +01:00
|
|
|
return board, card, nil
|
2021-11-11 17:01:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func (s *SQLStore) replaceBlockID(db sq.BaseRunner, currentID, newID, workspaceID string) error {
|
|
|
|
runUpdateForBlocksAndHistory := func(query sq.UpdateBuilder) error {
|
|
|
|
if _, err := query.Table(s.tablePrefix + "blocks").Exec(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
if _, err := query.Table(s.tablePrefix + "blocks_history").Exec(); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
baseQuery := s.getQueryBuilder(db).
|
|
|
|
Where(sq.Eq{"workspace_id": workspaceID})
|
|
|
|
|
|
|
|
// update ID
|
|
|
|
updateIDQ := baseQuery.Update("").
|
|
|
|
Set("id", newID).
|
|
|
|
Where(sq.Eq{"id": currentID})
|
|
|
|
|
|
|
|
if errID := runUpdateForBlocksAndHistory(updateIDQ); errID != nil {
|
|
|
|
s.logger.Error(`replaceBlockID ERROR`, mlog.Err(errID))
|
|
|
|
return errID
|
|
|
|
}
|
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
// update BoardID
|
|
|
|
updateBoardIDQ := baseQuery.Update("").
|
|
|
|
Set("board_id", newID).
|
|
|
|
Where(sq.Eq{"board_id": currentID})
|
2021-11-11 17:01:43 +01:00
|
|
|
|
2022-03-22 15:24:34 +01:00
|
|
|
if errBoardID := runUpdateForBlocksAndHistory(updateBoardIDQ); errBoardID != nil {
|
|
|
|
s.logger.Error(`replaceBlockID ERROR`, mlog.Err(errBoardID))
|
|
|
|
return errBoardID
|
2021-11-11 17:01:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// update ParentID
|
|
|
|
updateParentIDQ := baseQuery.Update("").
|
|
|
|
Set("parent_id", newID).
|
|
|
|
Where(sq.Eq{"parent_id": currentID})
|
|
|
|
|
|
|
|
if errParentID := runUpdateForBlocksAndHistory(updateParentIDQ); errParentID != nil {
|
|
|
|
s.logger.Error(`replaceBlockID ERROR`, mlog.Err(errParentID))
|
|
|
|
return errParentID
|
|
|
|
}
|
|
|
|
|
2021-12-10 15:33:41 +01:00
|
|
|
// update parent contentOrder
|
|
|
|
updateContentOrder := baseQuery.Update("")
|
2022-03-22 15:24:34 +01:00
|
|
|
if s.dbType == model.PostgresDBType {
|
2021-12-10 15:33:41 +01:00
|
|
|
updateContentOrder = updateContentOrder.
|
|
|
|
Set("fields", sq.Expr("REPLACE(fields::text, ?, ?)::json", currentID, newID)).
|
|
|
|
Where(sq.Like{"fields->>'contentOrder'": "%" + currentID + "%"}).
|
|
|
|
Where(sq.Eq{"type": model.TypeCard})
|
|
|
|
} else {
|
|
|
|
updateContentOrder = updateContentOrder.
|
|
|
|
Set("fields", sq.Expr("REPLACE(fields, ?, ?)", currentID, newID)).
|
|
|
|
Where(sq.Like{"fields": "%" + currentID + "%"}).
|
|
|
|
Where(sq.Eq{"type": model.TypeCard})
|
|
|
|
}
|
|
|
|
|
|
|
|
if errParentID := runUpdateForBlocksAndHistory(updateContentOrder); errParentID != nil {
|
|
|
|
s.logger.Error(`replaceBlockID ERROR`, mlog.Err(errParentID))
|
|
|
|
return errParentID
|
|
|
|
}
|
|
|
|
|
2021-11-11 17:01:43 +01:00
|
|
|
return nil
|
|
|
|
}
|
2022-03-22 15:24:34 +01:00
|
|
|
|
|
|
|
func (s *SQLStore) duplicateBlock(db sq.BaseRunner, boardID string, blockID string, userID string, asTemplate bool) ([]model.Block, error) {
|
2022-04-06 12:57:30 +02:00
|
|
|
blocks, err := s.getSubTree2(db, boardID, blockID, model.QuerySubtreeOptions{})
|
2022-03-22 15:24:34 +01:00
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if len(blocks) == 0 {
|
|
|
|
return nil, BlockNotFoundErr{blockID}
|
|
|
|
}
|
|
|
|
|
|
|
|
var rootBlock model.Block
|
|
|
|
allBlocks := []model.Block{}
|
|
|
|
for _, block := range blocks {
|
|
|
|
if block.ID == blockID {
|
|
|
|
if block.Fields == nil {
|
|
|
|
block.Fields = make(map[string]interface{})
|
|
|
|
}
|
|
|
|
block.Fields["isTemplate"] = asTemplate
|
|
|
|
rootBlock = block
|
|
|
|
} else {
|
|
|
|
allBlocks = append(allBlocks, block)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
allBlocks = append([]model.Block{rootBlock}, allBlocks...)
|
|
|
|
|
|
|
|
allBlocks = model.GenerateBlockIDs(allBlocks, nil)
|
|
|
|
if err := s.insertBlocks(db, allBlocks, userID); err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return allBlocks, nil
|
|
|
|
}
|