From 5dd318a481c2d3ec3587eaff5be5bf8ce9a060a0 Mon Sep 17 00:00:00 2001 From: Lauri Ojansivu Date: Sun, 10 Mar 2024 08:42:04 +0200 Subject: [PATCH] v7.38 --- api.py | 27 ++++++++++++++++++++++++++- models/boards.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/api.py b/api.py index 8391e91b3..c6f2064c4 100755 --- a/api.py +++ b/api.py @@ -44,6 +44,7 @@ If *nix: chmod +x api.py => ./api.py users python3 api.py addlabel BOARDID LISTID CARDID LABELID # Add label to a card python3 api.py addcardwithlabel AUTHORID BOARDID SWIMLANEID LISTID CARDTITLE CARDDESCRIPTION LABELIDS # Add a card and a label python3 api.py editboardtitle BOARDID NEWBOARDTITLE # Edit board title + python3 api.py copyboard BOARDID NEWBOARDTITLE # Copy a board python3 api.py createlabel BOARDID LABELCOLOR LABELNAME (Color available: `white`, `green`, `yellow`, `orange`, `red`, `purple`, `blue`, `sky`, `lime`, `pink`, `black`, `silver`, `peachpuff`, `crimson`, `plum`, `darkgreen`, `slateblue`, `magenta`, `gold`, `navy`, `gray`, `saddlebrown`, `paleturquoise`, `mistyrose`, `indigo`) # Create a new label python3 api.py editcardcolor BOARDID LISTID CARDID COLOR (Color available: `white`, `green`, `yellow`, `orange`, `red`, `purple`, `blue`, `sky`, `lime`, `pink`, `black`, `silver`, `peachpuff`, `crimson`, `plum`, `darkgreen`, `slateblue`, `magenta`, `gold`, `navy`, `gray`, `saddlebrown`, `paleturquoise`, `mistyrose`, `indigo`) # Edit card color python3 api.py addchecklist BOARDID CARDID TITLE ITEM1 ITEM2 ITEM3 ITEM4 (You can add multiple items or just one, or also without any item, just TITLE works as well. * If items or Title contains spaces, you should add ' between them.) # Add checklist + item on a card @@ -481,7 +482,31 @@ if arguments == 3: print(body.text) # ------- EDIT BOARD TITLE END ----------- - + + if sys.argv[1] == 'copyboard': + + # ------- COPY BOARD START ----------- + boardid = sys.argv[2] + boardtitle = sys.argv[3] + edboardcopy = wekanurl + apiboards + boardid + s + 'copy' + print(edboardcopy) + headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)} + + post_data = {'title': boardtitle} + + body = requests.post(edboardcopy, json=post_data, headers=headers) + print("=== COPY BOARD ===\n") + #body = requests.get(edboardcopy, headers=headers) + data2 = body.text.replace('}',"}\n") + print(data2) + if body.status_code == 200: + print("Succesfull!") + else: + print(f"Error: {body.status_code}") + print(body.text) + + # ------- COPY BOARD END ----------- + if sys.argv[1] == 'createlist': # ------- CREATE LIST START ----------- diff --git a/models/boards.js b/models/boards.js index 45fa9f2a6..9eb1024b0 100644 --- a/models/boards.js +++ b/models/boards.js @@ -2239,6 +2239,37 @@ if (Meteor.isServer) { } }); + /** + * @operation copy_board + * @summary Copy a board to a new one + * + * @description If your are board admin or wekan admin, this copies the + * given board to a new one. + * + * @param {string} boardId the board + * @param {string} title the title of the new board (default to old one) + * + * @return_type string + */ +JsonRoutes.add('POST', '/api/boards/:boardId/copy', function(req, res) { + const id = req.params.boardId; + const board = ReactiveCache.getBoard(id); + const adminAccess = board.members.some(e => e.userId === req.userId && e.isAdmin); + Authentication.checkAdminOrCondition(req.userId, adminAccess); + try { + board['title'] = req.body.title || Boards.uniqueTitle(board.title); + ret = board.copy(); + JsonRoutes.sendResult(res, { + code: 200, + data: ret, + }); + } catch (error) { + JsonRoutes.sendResult(res, { + data: error, + }); + } +}); + /** * @operation set_board_member_permission * @tag Users