Skip to content

Direct editing API to allow file editing using a one-time token - #17625

Merged
rullzer merged 9 commits into
masterfrom
enh/noid/direct-editing
Nov 28, 2019
Merged

Direct editing API to allow file editing using a one-time token#17625
rullzer merged 9 commits into
masterfrom
enh/noid/direct-editing

Conversation

@juliusknorr

@juliusknorrjuliusknorr commented Oct 21, 2019

Copy link
Copy Markdown
Member

Early draft PR so @tobiasKaminsky has something to play with 😉

The idea is to unify the token generation and endpoints into a server API, so mobile apps and the desktop client can just query one endpoint instead of requiring individual implementation for every app. The basic concept is that mobile apps now can request a one time url to edit a file, which can be opened in an unauthenticated webview by the apps.

Editor class

This class defines how your app is presented in the frontend (name), which filetypes it can handle as well as the endpoint that will be shown when the one-time link is opened. Inside of the open method you can then just load the onlyoffice editor with the file that is provided in the $token parameter.
https://github.com/nextcloud/text/blob/db42744a5c651666ca91d66219f77ae5775f949c/lib/DirectEditing/TextDirectEditor.php

Register the editor class in your lib/AppInfo/Application.php

/** @var IEventDispatcher $eventDispatcher */
$eventDispatcher->addListener(RegisterDirectEditorEvent::class, function (RegisterDirectEditorEvent $event) use ($container) {
$editor = $container->query(TextDirectEditor::class);
$event->register($editor);
});

Add document creators:

Creators are used to show entries in the mobile apps like "Create a new
spreadsheet" Furthermore you can also prefill the file with some content
if that is needed for the specific mimetype. Once you have added a class
it also needs to be registered in your Editor class.
https://github.com/nextcloud/text/blob/db42744a5c651666ca91d66219f77ae5775f949c/lib/DirectEditing/TextDocumentCreator.php

API endpoints

Obtain editor details

curl 'https://admin:admin@nextcloud.local/ocs/v2.php/apps/files/api/v1/directEditing?format=json' -H 'OCS-APIRequest: true'

{
"ocs": {
"meta": {
"status": "ok",
"statuscode": 200,
"message": "OK"
},
"data": {
"editors": {
"text": {
"name": "Nextcloud Text",
"mimetypes": [
"text/markdown"
],
"optionalMimetypes": [
"text/plain"
],
"secure": false
}
},
"creators": {
"textdocument": {
"id": "textdocument",
"name": "New text document",
"extension": ".md",
"templates": false
},
"textdocumenttemplate": {
"id": "textdocumenttemplate",
"name": "New text document from template",
"extension": ".md",
"templates": true
}
}
}
}
}

Get the list of templates

curl 'https://admin:admin@nextcloud.local/ocs/v2.php/apps/files/api/v1/directEditing/templates/text/textdocumenttemplate?format=json' -H 'OCS-APIRequest: true'

{
"ocs": {
"meta": {
"status": "ok",
"statuscode": 200,
"message": "OK"
},
"data": {
"1": {
"id": "1",
"extension": "md",
"name": "Weekly ToDo",
"preview": "https://cloud.bitgrid.net/apps/richdocuments/template/preview/832537"
},
"2": {
"id": "2",
"extension": "md",
"name": "Meeting notes",
"preview": "https://cloud.bitgrid.net/apps/richdocuments/template/preview/832537"
}
}
}
}

Create an empty file

curl -X POST 'https://admin:admin@nextcloud.local/ocs/v2.php/apps/files/api/v1/directEditing/create?path=/foo1.md&editorId=text&creatorId=textdocument&format=json' -H 'OCS-APIRequest: true'

{
"ocs": {
"meta": {
"status": "ok",
"statuscode": 200,
"message": "OK"
},
"data": {
"url": "https://nextcloud.local/index.php/apps/files/directEditing/DbAy3rzfdBosKJjtQyxjq5s9Wz5MAZsjf9cHRZ4LKALrjnawxRAXzncNRpbzYEbT"
}
}
}

Create a file from a template

curl -X POST 'https://admin:admin@nextcloud.local/ocs/v2.php/apps/files/api/v1/directEditing/create?path=/foo1.md&editorId=text&creatorId=textdocumenttemplate&templateId=1&format=json' -H 'OCS-APIRequest: true'

{
"ocs": {
"meta": {
"status": "ok",
"statuscode": 200,
"message": "OK"
},
"data": {
"url": "https://nextcloud.local/index.php/apps/files/directEditing/DbAy3rzfdBosKJjtQyxjq5s9Wz5MAZsjf9cHRZ4LKALrjnawxRAXzncNRpbzYEbT"
}
}
}

Open a file

curl -X POST 'https://admin:admin@nextcloud.local/ocs/v2.php/apps/files/api/v1/directEditing/open?path=/subfolder/123.txt&editorId=text&format=json' -H 'OCS-APIRequest: true'

{
"ocs": {
"meta": {
"status": "ok",
"statuscode": 200,
"message": "OK"
},
"data": {
"url": "https://nextcloud.local/index.php/apps/files/directEditing/DbAy3rzfdBosKJjtQyxjq5s9Wz5MAZsjf9cHRZ4LKALrjnawxRAXzncNRpbzYEbT"
}
}
}

Comment threadapps/files/lib/Controller/DirectEditingViewController.php Outdated
@tobiasKaminsky

Copy link
Copy Markdown
Member

❗ I also rebased

@juliusknorr
juliusknorrforce-pushed the enh/noid/direct-editing branch from 276fe7a to 799d0faCompareNovember 13, 2019 11:19
@juliusknorr
juliusknorr marked this pull request as ready for review November 13, 2019 11:21
@juliusknorr

Copy link
Copy Markdown
MemberAuthor

Ready for a first round of review, I'll look into adding some tests

@juliusknorrjuliusknorr changed the title 🚧 Direct editing API to allow file editing using a one-time tokenDirect editing API to allow file editing using a one-time tokenNov 13, 2019
@juliusknorrjuliusknorr added this to the Nextcloud 18 milestone Nov 13, 2019

@ChristophWurstChristophWurst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks nice otherwise :)

Comment threadapps/files/lib/Controller/DirectEditingController.php Outdated
Comment threadapps/files/lib/Controller/DirectEditingViewController.php Outdated
Comment threadcomposer.json Outdated
Comment threadcore/Migrations/Version18000Date20191014105105.php Outdated
Comment threadcore/Migrations/Version18000Date20191014105105.php Outdated
Comment threadlib/public/DirectEditing/ITemplate.php Outdated

@ChristophWurstChristophWurst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a few nitpicks. The rest looks great!

Comment threadlib/public/DirectEditing/ACreateFromTemplate.php Outdated
Comment threadlib/public/DirectEditing/IEditor.php Outdated
Comment threadlib/public/DirectEditing/IEditor.php Outdated
Comment threadversion.php
Comment threadapps/files/lib/Controller/DirectEditingController.php Outdated
Comment threadapps/files/lib/BackgroundJob/CleanupDirectEditingTokens.php Outdated
@juliusknorr

Copy link
Copy Markdown
MemberAuthor

After discussing with @tobiasKaminsky I moved the editor details to the files app capabilities as this will save us one additional request on the apps and will have a rather minimal performance impact on the server side, since most of the data should be static and coming from hardcoded values in php classes.

@ChristophWurstChristophWurst left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great!

@juliusknorr
juliusknorrforce-pushed the enh/noid/direct-editing branch from 3db38c1 to 75267c3CompareNovember 26, 2019 12:11
Comment threadapps/files/lib/Capabilities.php Outdated
juliusknorrand others added 4 commits November 27, 2019 14:36
mobile apps
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: tobiasKaminsky <tobias@kaminsky.me>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
Signed-off-by: Julius Härtl <jus@bitgrid.net>
@juliusknorr
juliusknorrforce-pushed the enh/noid/direct-editing branch from dac7f00 to bde624bCompareNovember 27, 2019 18:56

@rullzerrullzer left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets do this then!

@tobiasKaminsky

Copy link
Copy Markdown
Member

Is this documentation somewhere available?

@rullzer

Copy link
Copy Markdown
Member

Nope. @juliushaertl be sure to add it to the docs indeed

@marinofaggiana

marinofaggiana commented Dec 10, 2019

Copy link
Copy Markdown
Member

Please update and verify the document: "API endpoints" because it's incorrect. thanks

@marinofaggiana

Copy link
Copy Markdown
Member

@juliushaertl the "Get the list of templates" if do not exists a templates do not return nothing, but the Richdocuments API return one record with template of name "Empty", can we use the same logic ?

MorrisJobke added a commit to nextcloud/documentation that referenced this pull request Aug 10, 2020
* LoadAdditionalScripts (@rullzer) - nextcloud/server#16641
* LoadViewerEvent (@skjnldsv) - nextcloud/viewer#271
* RegisterDirectEditorEvent (@juliushaertl) - nextcloud/server#17625
* typed events for files scanner (@ChristophWurst) - nextcloud/server#18351
* typed events for group mangement (@ChristophWurst) - nextcloud/server#18350
* AddContentSecurityPolicyEvent (@rullzer) - nextcloud/server#15730
* UserLiveStatusEvent (@georgehrke) - nextcloud/server#21186
* password_policy events (@ChristophWurst) - nextcloud/server#18019
* AddFeaturePolicyEvent (@rullzer) - nextcloud/server#16613
* ShareCreatedEvent (@rullzer) - nextcloud/server#18384
* LoadSettingsScriptsEvent (@blizzz) - nextcloud/server#21475
* flow events (@rullzer) - nextcloud/server#18535
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
backportbot-nextcloudBot pushed a commit to nextcloud/documentation that referenced this pull request Aug 10, 2020
* LoadAdditionalScripts (@rullzer) - nextcloud/server#16641
* LoadViewerEvent (@skjnldsv) - nextcloud/viewer#271
* RegisterDirectEditorEvent (@juliushaertl) - nextcloud/server#17625
* typed events for files scanner (@ChristophWurst) - nextcloud/server#18351
* typed events for group mangement (@ChristophWurst) - nextcloud/server#18350
* AddContentSecurityPolicyEvent (@rullzer) - nextcloud/server#15730
* UserLiveStatusEvent (@georgehrke) - nextcloud/server#21186
* password_policy events (@ChristophWurst) - nextcloud/server#18019
* AddFeaturePolicyEvent (@rullzer) - nextcloud/server#16613
* ShareCreatedEvent (@rullzer) - nextcloud/server#18384
* LoadSettingsScriptsEvent (@blizzz) - nextcloud/server#21475
* flow events (@rullzer) - nextcloud/server#18535
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
MorrisJobke added a commit to nextcloud/documentation that referenced this pull request Aug 10, 2020
* LoadAdditionalScripts (@rullzer) - nextcloud/server#16641
* LoadViewerEvent (@skjnldsv) - nextcloud/viewer#271
* RegisterDirectEditorEvent (@juliushaertl) - nextcloud/server#17625
* typed events for files scanner (@ChristophWurst) - nextcloud/server#18351
* typed events for group mangement (@ChristophWurst) - nextcloud/server#18350
* AddContentSecurityPolicyEvent (@rullzer) - nextcloud/server#15730
* UserLiveStatusEvent (@georgehrke) - nextcloud/server#21186
* password_policy events (@ChristophWurst) - nextcloud/server#18019
* AddFeaturePolicyEvent (@rullzer) - nextcloud/server#16613
* ShareCreatedEvent (@rullzer) - nextcloud/server#18384
* LoadSettingsScriptsEvent (@blizzz) - nextcloud/server#21475
* flow events (@rullzer) - nextcloud/server#18535
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
MorrisJobke added a commit to nextcloud/documentation that referenced this pull request Aug 10, 2020
* LoadAdditionalScripts (@rullzer) - nextcloud/server#16641
* LoadViewerEvent (@skjnldsv) - nextcloud/viewer#271
* RegisterDirectEditorEvent (@juliushaertl) - nextcloud/server#17625
* typed events for files scanner (@ChristophWurst) - nextcloud/server#18351
* typed events for group mangement (@ChristophWurst) - nextcloud/server#18350
* AddContentSecurityPolicyEvent (@rullzer) - nextcloud/server#15730
* UserLiveStatusEvent (@georgehrke) - nextcloud/server#21186
* password_policy events (@ChristophWurst) - nextcloud/server#18019
* AddFeaturePolicyEvent (@rullzer) - nextcloud/server#16613
* ShareCreatedEvent (@rullzer) - nextcloud/server#18384
* LoadSettingsScriptsEvent (@blizzz) - nextcloud/server#21475
* flow events (@rullzer) - nextcloud/server#18535
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@juliusknorr@tobiasKaminsky@rullzer@marinofaggiana@ChristophWurst@kesselb