diff --git a/.eslintignore b/.eslintignore index 5dfcab8ab..1aa89225d 100644 --- a/.eslintignore +++ b/.eslintignore @@ -1416,6 +1416,9 @@ packages/lib/services/searchengine/queryBuilder.js.map packages/lib/services/share/ShareService.d.ts packages/lib/services/share/ShareService.js packages/lib/services/share/ShareService.js.map +packages/lib/services/share/ShareService.test.d.ts +packages/lib/services/share/ShareService.test.js +packages/lib/services/share/ShareService.test.js.map packages/lib/services/share/reducer.d.ts packages/lib/services/share/reducer.js packages/lib/services/share/reducer.js.map diff --git a/.gitignore b/.gitignore index 094694b3f..f3f6a4027 100644 --- a/.gitignore +++ b/.gitignore @@ -1401,6 +1401,9 @@ packages/lib/services/searchengine/queryBuilder.js.map packages/lib/services/share/ShareService.d.ts packages/lib/services/share/ShareService.js packages/lib/services/share/ShareService.js.map +packages/lib/services/share/ShareService.test.d.ts +packages/lib/services/share/ShareService.test.js +packages/lib/services/share/ShareService.test.js.map packages/lib/services/share/reducer.d.ts packages/lib/services/share/reducer.js packages/lib/services/share/reducer.js.map diff --git a/packages/app-desktop/gui/ClipperConfigScreen.jsx b/packages/app-desktop/gui/ClipperConfigScreen.jsx index 0b61bd573..8f5f340e0 100644 --- a/packages/app-desktop/gui/ClipperConfigScreen.jsx +++ b/packages/app-desktop/gui/ClipperConfigScreen.jsx @@ -40,6 +40,17 @@ class ClipperConfigScreenComponent extends React.Component { alert(_('Token has been copied to the clipboard!')); } + componentDidUpdate(prevProps) { + if (prevProps.needApiAuth !== this.props.needApiAuth && this.props.needApiAuth) { + // Ideally when API auth is needed, we should display the + // notification in this screen, however it's not setup for it yet. + // So instead, we just go back to the main screen where the + // notification will be displayed. + // https://discourse.joplinapp.org/t/web-clipper-2-1-3-not-working/18582/27 + this.props.dispatch({ type: 'NAV_BACK' }); + } + } + renewToken_click() { if (confirm(_('Are you sure you want to renew the authorisation token?'))) { void EncryptionService.instance() @@ -171,6 +182,7 @@ const mapStateToProps = state => { clipperServer: state.clipperServer, clipperServerAutoStart: state.settings['clipperServer.autoStart'], apiToken: state.settings['api.token'], + needApiAuth: state.needApiAuth, }; }; diff --git a/packages/app-mobile/ios/Joplin.xcodeproj/project.pbxproj b/packages/app-mobile/ios/Joplin.xcodeproj/project.pbxproj index b6132f0fb..57944e719 100644 --- a/packages/app-mobile/ios/Joplin.xcodeproj/project.pbxproj +++ b/packages/app-mobile/ios/Joplin.xcodeproj/project.pbxproj @@ -505,7 +505,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Joplin/Joplin.entitlements; - CURRENT_PROJECT_VERSION = 69; + CURRENT_PROJECT_VERSION = 70; DEVELOPMENT_TEAM = A9BXAFS6CT; ENABLE_BITCODE = NO; INFOPLIST_FILE = Joplin/Info.plist; @@ -533,7 +533,7 @@ ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon; CLANG_ENABLE_MODULES = YES; CODE_SIGN_ENTITLEMENTS = Joplin/Joplin.entitlements; - CURRENT_PROJECT_VERSION = 69; + CURRENT_PROJECT_VERSION = 70; DEVELOPMENT_TEAM = A9BXAFS6CT; INFOPLIST_FILE = Joplin/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 9.0; @@ -678,7 +678,7 @@ CLANG_WARN_UNGUARDED_AVAILABILITY = YES_AGGRESSIVE; CODE_SIGN_ENTITLEMENTS = ShareExtension/ShareExtension.entitlements; CODE_SIGN_STYLE = Automatic; - CURRENT_PROJECT_VERSION = 69; + CURRENT_PROJECT_VERSION = 70; DEBUG_INFORMATION_FORMAT = dwarf; DEVELOPMENT_TEAM = A9BXAFS6CT; GCC_C_LANGUAGE_STANDARD = gnu11; @@ -709,7 +709,7 @@ CODE_SIGN_ENTITLEMENTS = ShareExtension/ShareExtension.entitlements; CODE_SIGN_STYLE = Automatic; COPY_PHASE_STRIP = NO; - CURRENT_PROJECT_VERSION = 69; + CURRENT_PROJECT_VERSION = 70; DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; DEVELOPMENT_TEAM = A9BXAFS6CT; GCC_C_LANGUAGE_STANDARD = gnu11; diff --git a/packages/lib/services/rest/Api.ts b/packages/lib/services/rest/Api.ts index d4e2078a7..a0a310276 100644 --- a/packages/lib/services/rest/Api.ts +++ b/packages/lib/services/rest/Api.ts @@ -132,6 +132,8 @@ export default class Api { } public acceptAuthToken(accept: boolean) { + if (!this.authToken_) throw new Error('Auth token is not set'); + this.authToken_.status = accept ? AuthTokenStatus.Accepted : AuthTokenStatus.Rejected; this.dispatch_({ diff --git a/packages/lib/services/rest/routes/auth.ts b/packages/lib/services/rest/routes/auth.ts index c24205825..2508c199f 100644 --- a/packages/lib/services/rest/routes/auth.ts +++ b/packages/lib/services/rest/routes/auth.ts @@ -19,7 +19,7 @@ export default async function(request: Request, id: string = null, _link: string if (request.method === 'GET') { if (id === 'check') { if ('auth_token' in request.query) { - if (request.query.auth_token === context.authToken.value) { + if (context.authToken && request.query.auth_token === context.authToken.value) { const output: any = { status: context.authToken.status, }; diff --git a/packages/lib/services/share/ShareService.test.ts b/packages/lib/services/share/ShareService.test.ts new file mode 100644 index 000000000..1dbe79ff2 --- /dev/null +++ b/packages/lib/services/share/ShareService.test.ts @@ -0,0 +1,66 @@ +import Note from '../../models/Note'; +import { msleep, setupDatabaseAndSynchronizer, switchClient } from '../../testing/test-utils'; +import ShareService from './ShareService'; +import reducer from '../../reducer'; +import { createStore } from 'redux'; +import { NoteEntity } from '../database/types'; + +function mockApi() { + return { + exec: (method: string, path: string = '', _query: Record = null, _body: any = null, _headers: any = null, _options: any = null): Promise => { + if (method === 'GET' && path === 'api/shares') return { items: [] } as any; + return null; + }, + personalizedUserContentBaseUrl(_userId: string) { + + }, + }; +} + +function mockService() { + const service = new ShareService(); + const store = createStore(reducer as any); + service.initialize(store, mockApi() as any); + return service; +} + +describe('ShareService', function() { + + beforeEach(async (done) => { + await setupDatabaseAndSynchronizer(1); + await switchClient(1); + done(); + }); + + it('should not change the note user timestamps when sharing or unsharing', (async () => { + let note = await Note.save({}); + const service = mockService(); + await msleep(1); + await service.shareNote(note.id); + + function checkTimestamps(previousNote: NoteEntity, newNote: NoteEntity) { + // After sharing or unsharing, only the updated_time property should + // be updated, for sync purposes. All other timestamps shouldn't + // change. + expect(previousNote.user_created_time).toBe(newNote.user_created_time); + expect(previousNote.user_updated_time).toBe(newNote.user_updated_time); + expect(previousNote.updated_time < newNote.updated_time).toBe(true); + expect(previousNote.created_time).toBe(newNote.created_time); + } + + { + const noteReloaded = await Note.load(note.id); + checkTimestamps(note, noteReloaded); + note = noteReloaded; + } + + await msleep(1); + await service.unshareNote(note.id); + + { + const noteReloaded = await Note.load(note.id); + checkTimestamps(note, noteReloaded); + } + })); + +}); diff --git a/packages/lib/services/share/ShareService.ts b/packages/lib/services/share/ShareService.ts index 52357f3fc..5bdd6bcbe 100644 --- a/packages/lib/services/share/ShareService.ts +++ b/packages/lib/services/share/ShareService.ts @@ -20,8 +20,9 @@ export default class ShareService { return this.instance_; } - public initialize(store: Store) { + public initialize(store: Store, api: JoplinServerApi = null) { this.store_ = store; + this.api_ = api; } public get enabled(): boolean { @@ -120,7 +121,14 @@ export default class ShareService { const share = await this.api().exec('POST', 'api/shares', {}, { note_id: noteId }); - await Note.save({ id: note.id, is_shared: 1 }); + await Note.save({ + id: note.id, + parent_id: note.parent_id, + is_shared: 1, + updated_time: Date.now(), + }, { + autoTimestamp: false, + }); return share; } @@ -140,7 +148,14 @@ export default class ShareService { await Promise.all(promises); - await Note.save({ id: note.id, is_shared: 0 }); + await Note.save({ + id: note.id, + parent_id: note.parent_id, + is_shared: 0, + updated_time: Date.now(), + }, { + autoTimestamp: false, + }); } public shareUrl(userId: string, share: StateShare): string {