mirror of
https://github.com/mattermost/focalboard.git
synced 2025-03-17 20:37:54 +02:00
Add disable_notify
flag for InsertBlocks API (#3384)
* disable_notify flag for InsertBlocks API * fix linter error
This commit is contained in:
parent
9fc232d6c2
commit
93ae3f239a
@ -70,7 +70,7 @@ type boardsProduct struct {
|
||||
}
|
||||
|
||||
//nolint:gocyclo
|
||||
func newBoardsProduct(mmServer *app.Server, services map[app.ServiceKey]interface{}) (app.Product, error) {
|
||||
func newBoardsProduct(_ *app.Server, services map[app.ServiceKey]interface{}) (app.Product, error) {
|
||||
boards := &boardsProduct{}
|
||||
|
||||
for key, service := range services {
|
||||
|
@ -27,6 +27,7 @@ const (
|
||||
HeaderRequestedWith = "X-Requested-With"
|
||||
HeaderRequestedWithXML = "XMLHttpRequest"
|
||||
UploadFormFileKey = "file"
|
||||
True = "true"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -810,6 +811,11 @@ func (a *API) handlePostBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
// description: Board ID
|
||||
// required: true
|
||||
// type: string
|
||||
// - name: disable_notify
|
||||
// in: query
|
||||
// description: Disables notifications (for bulk data inserting)
|
||||
// required: false
|
||||
// type: bool
|
||||
// - name: Body
|
||||
// in: body
|
||||
// description: array of blocks to insert or update
|
||||
@ -835,6 +841,9 @@ func (a *API) handlePostBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
boardID := mux.Vars(r)["boardID"]
|
||||
userID := getUserID(r)
|
||||
|
||||
val := r.URL.Query().Get("disable_notify")
|
||||
disableNotify := val == True
|
||||
|
||||
// in phase 1 we use "manage_board_cards", but we would have to
|
||||
// check on specific actions for phase 2
|
||||
if !a.permissions.HasPermissionToBoard(userID, boardID, model.PermissionManageBoardCards) {
|
||||
@ -887,6 +896,7 @@ func (a *API) handlePostBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
auditRec := a.makeAuditRecord(r, "postBlocks", audit.Fail)
|
||||
defer a.audit.LogRecord(audit.LevelModify, auditRec)
|
||||
auditRec.AddMeta("disable_notify", disableNotify)
|
||||
|
||||
ctx := r.Context()
|
||||
session := ctx.Value(sessionContextKey).(*model.Session)
|
||||
@ -902,7 +912,7 @@ func (a *API) handlePostBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
newBlocks, err := a.app.InsertBlocks(blocks, session.UserID, true)
|
||||
newBlocks, err := a.app.InsertBlocks(blocks, session.UserID, !disableNotify)
|
||||
if err != nil {
|
||||
if errors.Is(err, app.ErrViewsLimitReached) {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusBadRequest, err.Error(), err)
|
||||
@ -913,7 +923,10 @@ func (a *API) handlePostBlocks(w http.ResponseWriter, r *http.Request) {
|
||||
return
|
||||
}
|
||||
|
||||
a.logger.Debug("POST Blocks", mlog.Int("block_count", len(blocks)))
|
||||
a.logger.Debug("POST Blocks",
|
||||
mlog.Int("block_count", len(blocks)),
|
||||
mlog.Bool("disable_notify", disableNotify),
|
||||
)
|
||||
|
||||
json, err := json.Marshal(newBlocks)
|
||||
if err != nil {
|
||||
@ -3168,7 +3181,7 @@ func (a *API) handleDuplicateBoard(w http.ResponseWriter, r *http.Request) {
|
||||
mlog.String("boardID", boardID),
|
||||
)
|
||||
|
||||
boardsAndBlocks, _, err := a.app.DuplicateBoard(boardID, userID, toTeam, asTemplate == "true")
|
||||
boardsAndBlocks, _, err := a.app.DuplicateBoard(boardID, userID, toTeam, asTemplate == True)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, err.Error(), err)
|
||||
return
|
||||
@ -3271,7 +3284,7 @@ func (a *API) handleDuplicateBlock(w http.ResponseWriter, r *http.Request) {
|
||||
mlog.String("blockID", blockID),
|
||||
)
|
||||
|
||||
blocks, err := a.app.DuplicateBlock(boardID, blockID, userID, asTemplate == "true")
|
||||
blocks, err := a.app.DuplicateBlock(boardID, blockID, userID, asTemplate == True)
|
||||
if err != nil {
|
||||
a.errorResponse(w, r.URL.Path, http.StatusInternalServerError, err.Error(), err)
|
||||
return
|
||||
|
@ -287,6 +287,16 @@ func (c *Client) InsertBlocks(boardID string, blocks []model.Block) ([]model.Blo
|
||||
return model.BlocksFromJSON(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client) InsertBlocksDisableNotify(boardID string, blocks []model.Block) ([]model.Block, *Response) {
|
||||
r, err := c.DoAPIPost(c.GetBlocksRoute(boardID)+"?disable_notify=true", toJSON(blocks))
|
||||
if err != nil {
|
||||
return nil, BuildErrorResponse(r, err)
|
||||
}
|
||||
defer closeBody(r)
|
||||
|
||||
return model.BlocksFromJSON(r.Body), BuildResponse(r)
|
||||
}
|
||||
|
||||
func (c *Client) DeleteBlock(boardID, blockID string) (bool, *Response) {
|
||||
r, err := c.DoAPIDelete(c.GetBlockRoute(boardID, blockID), "")
|
||||
if err != nil {
|
||||
|
Loading…
x
Reference in New Issue
Block a user