|
| 1 | +# Wikis |
| 2 | + |
| 3 | +## Setup |
| 4 | + |
| 5 | +Guide for developers and contributors set and test wikis on Donut |
| 6 | + |
| 7 | +Donut has to be registered as a OAuth App on GitHub to be able to request for permissions to access repos of the orgnization on GitHub. More can be learned about the steps to register [here](https://developer.github.com/apps/building-oauth-apps/creating-an-oauth-app/). The `Authorization callback URL` URL should have link to `/wikis/oauth-callback` endpoint. |
| 8 | + |
| 9 | +Client ID and Client Secret is to be provided after registering on GitHub as environemnt variables `GITHUB_OAUTH_APP_CLIENTID` and `GITHUB_OAUTH_APP_CLIENTSECRET` respectively. Demo values for those are already given for testing purpose. |
| 10 | + |
| 11 | +## Workflow |
| 12 | + |
| 13 | +- When wikis setup not done, admin user will get option to connect to GitHub. When connecting to GitHub admin user will have to grant permission the GitHub OAuth application whose clientId and clientSecret are provided in the environemnt variables to access one organization for whom he should have the rights to create repositories. The GitHub OAuth permission requests page rediects to `Authorization callback URL` provided during the creation of the GitHub OAuth App which should point to the `/wikis/oauth-callback` endpoint. Upon succesful authorization, we get an access token which is saved in the db in the Organizations. |
| 14 | + |
| 15 | +- On first time setup a repo named `Donut-wikis-backup` public repo is created under the Organization. `Home.md` and `_Sidebar.md` files are created in the repo and two closed issues are created with the titles `Home` and `_Sidebar`. |
| 16 | + |
| 17 | +- When a page is requested for then, the `pagesIndex` which is the title of all the pages available in the GitHub repo, complete content of `_Sidebar` and complete content and history of the page currently being viewed is sent. Complete content of pages and sidebar, history and pagesIndex is cached in redis. |
| 18 | + |
| 19 | +- When editing pages, the sha and comments of the commit is commented with the corresponding GitHub issue for that page. The page contents and history for that page is updated in the cache. |
| 20 | + |
| 21 | +- When creating new pages, pagesIndex is updated in the cache and history and the content of the page created is cached. |
| 22 | + |
| 23 | +- When deleteing pages, corrent document in the Github repo is deleted, the sha and comments of the commit which deletes the page is commented on the corresponding issue, its corresponding issue is renamed to `<fileNmae>-deleted-<first 8 letters of delete commit sha>`, all corresponding keys for that page is deleted from cache. The Home page and Sidebar cannot be deleted. |
| 24 | + |
| 25 | +## Routes |
| 26 | + |
| 27 | + GET - /wikis |
| 28 | + - First route to be called by frontend, returns message if wikis setup not done else returns pagesIndex and Home page |
| 29 | + |
| 30 | + GET - /wikis/oauth-check |
| 31 | + - Route called by frontend during initial setup by admin, handles redirection to GitHub or requesting OAuth access |
| 32 | + |
| 33 | + GET - /wikis/oauth-callback |
| 34 | + - Authorization callback URL GitHub redirects to when OAuth request approved, saves the access token to DB, performs initial setup |
| 35 | + |
| 36 | + GET - /wikis/pages |
| 37 | + - expects |
| 38 | + - query parameters |
| 39 | + - title - title of the page to be retrieved |
| 40 | + - ref - SHA of commit from which the page is to be retrived, useful of retrieving previous versions of page in histories, defaults to "master" |
| 41 | + - returns pagesIndex and the complete content and history of the page to be retrieved. |
| 42 | + |
| 43 | + POST - /wikis/pages |
| 44 | + - expects |
| 45 | + - body |
| 46 | + - title - tile of the page to be created |
| 47 | + - content - content of the page to be created |
| 48 | + - comments - comments which could appear in the commmit message of the commit in which the page is created |
| 49 | + - creates a new page |
| 50 | + |
| 51 | + PUT - /wikis/pages |
| 52 | + - expects |
| 53 | + - body |
| 54 | + - title - tile of the page being edited |
| 55 | + - content - new content of the page being edited |
| 56 | + - comments - comments which could appear in the commmit message of the commit in which the page is edited |
| 57 | + - edits an existing page |
| 58 | + |
| 59 | + DELETE - /wikis/pages |
| 60 | + - expects |
| 61 | + - body |
| 62 | + - title - tile of the page being edited |
| 63 | + - deletes a page |
| 64 | + |
| 65 | +## Database |
| 66 | + |
| 67 | +accessToken - persistent - stored under wikis.accessToken in `Organization` Schema |
0 commit comments