You've already forked joplin
mirror of
https://github.com/laurent22/joplin.git
synced 2025-11-29 22:48:10 +02:00
All: Fixed issues related to sharing notes on read-only notebooks
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import Logger from '@joplin/utils/Logger';
|
||||||
import { ModelType } from '../../BaseModel';
|
import { ModelType } from '../../BaseModel';
|
||||||
import { ErrorCode } from '../../errors';
|
import { ErrorCode } from '../../errors';
|
||||||
import JoplinError from '../../JoplinError';
|
import JoplinError from '../../JoplinError';
|
||||||
@@ -5,6 +6,8 @@ import { State as ShareState } from '../../services/share/reducer';
|
|||||||
import ItemChange from '../ItemChange';
|
import ItemChange from '../ItemChange';
|
||||||
import Setting from '../Setting';
|
import Setting from '../Setting';
|
||||||
|
|
||||||
|
const logger = Logger.create('models/utils/readOnly');
|
||||||
|
|
||||||
export interface ItemSlice {
|
export interface ItemSlice {
|
||||||
id?: string;
|
id?: string;
|
||||||
share_id: string;
|
share_id: string;
|
||||||
@@ -43,6 +46,18 @@ export const checkIfItemCanBeChanged = (itemType: ModelType, changeSource: numbe
|
|||||||
export const checkIfItemCanBeAddedToFolder = async (itemType: ModelType, Folder: any, changeSource: number, shareState: ShareState, parentId: string) => {
|
export const checkIfItemCanBeAddedToFolder = async (itemType: ModelType, Folder: any, changeSource: number, shareState: ShareState, parentId: string) => {
|
||||||
if (needsReadOnlyChecks(itemType, changeSource, shareState) && parentId) {
|
if (needsReadOnlyChecks(itemType, changeSource, shareState) && parentId) {
|
||||||
const parentFolder = await Folder.load(parentId, { fields: ['id', 'share_id'] });
|
const parentFolder = await Folder.load(parentId, { fields: ['id', 'share_id'] });
|
||||||
|
|
||||||
|
if (!parentFolder) {
|
||||||
|
// Historically it's always been possible to set the parent_id of a
|
||||||
|
// note to a folder that does not exist - this is to support
|
||||||
|
// synchronisation, where items are downloaded in random order. It
|
||||||
|
// is not ideal to skip the check here, but if for some reason the
|
||||||
|
// folder turns out to be read-only the issue will be resolved
|
||||||
|
// during sync.
|
||||||
|
logger.warn('checkIfItemCanBeAddedToFolder: Trying to add an item to a folder that does not exist - skipping check');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (itemIsReadOnlySync(itemType, changeSource, parentFolder, Setting.value('sync.userId'), shareState)) {
|
if (itemIsReadOnlySync(itemType, changeSource, parentFolder, Setting.value('sync.userId'), shareState)) {
|
||||||
throw new JoplinError('Cannot add an item as a child of a read-only item', ErrorCode.IsReadOnly);
|
throw new JoplinError('Cannot add an item as a child of a read-only item', ErrorCode.IsReadOnly);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,13 @@ const userFetcher = async () => {
|
|||||||
const fileApi = await syncTarget.fileApi();
|
const fileApi = await syncTarget.fileApi();
|
||||||
const api = fileApi.driver().api();
|
const api = fileApi.driver().api();
|
||||||
|
|
||||||
|
if (api.userId) {
|
||||||
|
// That can happen if we don't have a session yet or if it has been
|
||||||
|
// cleared
|
||||||
|
logger.info('Skipping fetching user because user ID is not available');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const owner: UserApiResponse = await api.exec('GET', `api/users/${api.userId}`);
|
const owner: UserApiResponse = await api.exec('GET', `api/users/${api.userId}`);
|
||||||
|
|
||||||
logger.info('Got user:', owner);
|
logger.info('Got user:', owner);
|
||||||
|
|||||||
Reference in New Issue
Block a user