Files
wekan/server/shareTarget.js
T
Lauri Ojansivu 52b0ea0d81 Android: share to WeKan from other apps.
The web app manifest declares a share_target, so on a phone where WeKan
is installed as an app it appears in Android's Share menu. Sharing a web
page, a note or a message opens /share-target, "Add to WeKan": pick a
board and a list, and what was shared becomes a card there - the page's
title or the text's first line as the title, the text and the address in
its description, the address once - and the card opens. Only boards the
member may add cards to are offered, and the server checks the right to
write in that list, on that board, as for any card added.

models/lib/shareTarget.js turns a share into a card and holds the
manifest's declaration; tests/shareTarget.test.cjs covers what browsers,
notes and chat apps share, an empty share, javascript: addresses, the
manifest, the route and the server's checks. Documented in
docs/Platforms/FOSS/OS/Android.md. The four new strings are English
placeholders until the next translation pass.

Thanks to memeplex and xet7 !

Fixes #1293.
2026-10-14 14:55:04 +03:00

41 lines
1.9 KiB
JavaScript

// #1293: a card from something shared to WeKan on a phone
// (models/lib/shareTarget.js). The same rights as adding a card on the board:
// a member who may write in that list.
import { Meteor } from 'meteor/meteor';
import { check, Match } from 'meteor/check';
import Boards from '/models/boards';
import Cards from '/models/cards';
import Lists from '/models/lists';
import { canWriteInList } from '/server/lib/listPermissionGate';
const { sharedCard } = require('/models/lib/shareTarget');
Meteor.methods({
async shareTargetCreateCard(input) {
check(input, { boardId: String, listId: String, title: Match.Optional(String), text: Match.Optional(String),
url: Match.Optional(String) });
if (!this.userId) throw new Meteor.Error('not-authorized');
const board = await Boards.findOneAsync(input.boardId);
const list = board && await Lists.findOneAsync({ _id: input.listId, boardId: board._id, archived: { $ne: true } });
if (!board || board.archived || !list) throw new Meteor.Error('not-found');
if (!(await canWriteInList(this.userId, board, list._id))) throw new Meteor.Error('not-authorized');
const { title, description } = sharedCard(input);
if (!title) throw new Meteor.Error('share-target-empty');
const swimlane = await board.getDefaultSwimlineAsync();
if (!swimlane) throw new Meteor.Error('not-found');
const last = await Cards.findOneAsync({ listId: list._id, archived: false }, { sort: { sort: -1 }, fields: { sort: 1 } });
const _id = await Cards.insertAsync({
title,
description,
listId: list._id,
boardId: board._id,
swimlaneId: swimlane._id,
sort: last && Number.isFinite(last.sort) ? last.sort + 1 : 0,
type: 'cardType-card',
cardNumber: await board.getNextCardNumber(),
userId: this.userId,
});
return { cardId: _id, boardId: board._id, slug: board.slug };
},
});