Skip to content

Commit 9e413b3

Browse files
authored
Merge pull request wekan#5340 from e-gaulue/ED1
2 parents 1783257 + 5dd318a commit 9e413b3

File tree

2 files changed

+57
-1
lines changed

2 files changed

+57
-1
lines changed

api.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
python3 api.py addlabel BOARDID LISTID CARDID LABELID # Add label to a card
4545
python3 api.py addcardwithlabel AUTHORID BOARDID SWIMLANEID LISTID CARDTITLE CARDDESCRIPTION LABELIDS # Add a card and a label
4646
python3 api.py editboardtitle BOARDID NEWBOARDTITLE # Edit board title
47+
python3 api.py copyboard BOARDID NEWBOARDTITLE # Copy a board
4748
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
4849
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
4950
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 @@
481482
print(body.text)
482483

483484
# ------- EDIT BOARD TITLE END -----------
484-
485+
486+
if sys.argv[1] == 'copyboard':
487+
488+
# ------- COPY BOARD START -----------
489+
boardid = sys.argv[2]
490+
boardtitle = sys.argv[3]
491+
edboardcopy = wekanurl + apiboards + boardid + s + 'copy'
492+
print(edboardcopy)
493+
headers = {'Accept': 'application/json', 'Authorization': 'Bearer {}'.format(apikey)}
494+
495+
post_data = {'title': boardtitle}
496+
497+
body = requests.post(edboardcopy, json=post_data, headers=headers)
498+
print("=== COPY BOARD ===\n")
499+
#body = requests.get(edboardcopy, headers=headers)
500+
data2 = body.text.replace('}',"}\n")
501+
print(data2)
502+
if body.status_code == 200:
503+
print("Succesfull!")
504+
else:
505+
print(f"Error: {body.status_code}")
506+
print(body.text)
507+
508+
# ------- COPY BOARD END -----------
509+
485510
if sys.argv[1] == 'createlist':
486511

487512
# ------- CREATE LIST START -----------

models/boards.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,37 @@ if (Meteor.isServer) {
22392239
}
22402240
});
22412241

2242+
/**
2243+
* @operation copy_board
2244+
* @summary Copy a board to a new one
2245+
*
2246+
* @description If your are board admin or wekan admin, this copies the
2247+
* given board to a new one.
2248+
*
2249+
* @param {string} boardId the board
2250+
* @param {string} title the title of the new board (default to old one)
2251+
*
2252+
* @return_type string
2253+
*/
2254+
JsonRoutes.add('POST', '/api/boards/:boardId/copy', function(req, res) {
2255+
const id = req.params.boardId;
2256+
const board = ReactiveCache.getBoard(id);
2257+
const adminAccess = board.members.some(e => e.userId === req.userId && e.isAdmin);
2258+
Authentication.checkAdminOrCondition(req.userId, adminAccess);
2259+
try {
2260+
board['title'] = req.body.title || Boards.uniqueTitle(board.title);
2261+
ret = board.copy();
2262+
JsonRoutes.sendResult(res, {
2263+
code: 200,
2264+
data: ret,
2265+
});
2266+
} catch (error) {
2267+
JsonRoutes.sendResult(res, {
2268+
data: error,
2269+
});
2270+
}
2271+
});
2272+
22422273
/**
22432274
* @operation set_board_member_permission
22442275
* @tag Users

0 commit comments

Comments
 (0)