Browse Source

app now handles multi users

Skylsmoi 5 years ago
parent
commit
e6793a9cdd
4 changed files with 50 additions and 30 deletions
  1. 35 14
      src/action.async.js
  2. 12 12
      src/container/HtmlDocument.jsx
  3. 2 2
      src/container/PopupCreateHtmlDocument.jsx
  4. 1 2
      src/helper.js

+ 35 - 14
src/action.async.js View File

@@ -1,35 +1,50 @@
1 1
 import { FETCH_CONFIG } from './helper.js'
2 2
 
3
-export const getHtmlDocContent = (apiUrl, idWorkspace, idContent) =>
3
+export const getHtmlDocContent = (user, apiUrl, idWorkspace, idContent) =>
4 4
   fetch(`${apiUrl}/workspaces/${idWorkspace}/html-documents/${idContent}`, {
5
-    ...FETCH_CONFIG,
5
+    headers: {
6
+      ...FETCH_CONFIG.headers,
7
+      'Authorization': 'Basic ' + user.auth
8
+    },
6 9
     method: 'GET'
7 10
   })
8 11
 
9
-export const getHtmlDocComment = (apiUrl, idWorkspace, idContent) =>
12
+export const getHtmlDocComment = (user, apiUrl, idWorkspace, idContent) =>
10 13
   fetch(`${apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/comments`, {
11
-    ...FETCH_CONFIG,
14
+    headers: {
15
+      ...FETCH_CONFIG.headers,
16
+      'Authorization': 'Basic ' + user.auth
17
+    },
12 18
     method: 'GET'
13 19
   })
14 20
 
15
-export const getHtmlDocRevision = (apiUrl, idWorkspace, idContent) =>
21
+export const getHtmlDocRevision = (user, apiUrl, idWorkspace, idContent) =>
16 22
   fetch(`${apiUrl}/workspaces/${idWorkspace}/html-documents/${idContent}/revisions`, {
17
-    ...FETCH_CONFIG,
23
+    headers: {
24
+      ...FETCH_CONFIG.headers,
25
+      'Authorization': 'Basic ' + user.auth
26
+    },
18 27
     method: 'GET'
19 28
   })
20 29
 
21
-export const postHtmlDocNewComment = (apiUrl, idWorkspace, idContent, newComment) =>
30
+export const postHtmlDocNewComment = (user, apiUrl, idWorkspace, idContent, newComment) =>
22 31
   fetch(`${apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/comments`, {
23
-    ...FETCH_CONFIG,
32
+    headers: {
33
+      ...FETCH_CONFIG.headers,
34
+      'Authorization': 'Basic ' + user.auth
35
+    },
24 36
     method: 'POST',
25 37
     body: JSON.stringify({
26 38
       raw_content: newComment
27 39
     })
28 40
   })
29 41
 
30
-export const putHtmlDocContent = (apiUrl, idWorkspace, idContent, label, newContent) =>
42
+export const putHtmlDocContent = (user, apiUrl, idWorkspace, idContent, label, newContent) =>
31 43
   fetch(`${apiUrl}/workspaces/${idWorkspace}/html-documents/${idContent}`, {
32
-    ...FETCH_CONFIG,
44
+    headers: {
45
+      ...FETCH_CONFIG.headers,
46
+      'Authorization': 'Basic ' + user.auth
47
+    },
33 48
     method: 'PUT',
34 49
     body: JSON.stringify({
35 50
       label: label,
@@ -37,18 +52,24 @@ export const putHtmlDocContent = (apiUrl, idWorkspace, idContent, label, newCont
37 52
     })
38 53
   })
39 54
 
40
-export const putHtmlDocStatus = (apiUrl, idWorkspace, idContent, newStatus) =>
55
+export const putHtmlDocStatus = (user, apiUrl, idWorkspace, idContent, newStatus) =>
41 56
   fetch(`${apiUrl}/workspaces/${idWorkspace}/html-documents/${idContent}/status`, {
42
-    ...FETCH_CONFIG,
57
+    headers: {
58
+      ...FETCH_CONFIG.headers,
59
+      'Authorization': 'Basic ' + user.auth
60
+    },
43 61
     method: 'PUT',
44 62
     body: JSON.stringify({
45 63
       status: newStatus
46 64
     })
47 65
   })
48 66
 
49
-export const postHtmlDocContent = (apiUrl, idWorkspace, idFolder, contentType, newContentName) =>
67
+export const postHtmlDocContent = (user, apiUrl, idWorkspace, idFolder, contentType, newContentName) =>
50 68
   fetch(`${apiUrl}/workspaces/${idWorkspace}/contents`, {
51
-    ...FETCH_CONFIG,
69
+    headers: {
70
+      ...FETCH_CONFIG.headers,
71
+      'Authorization': 'Basic ' + user.auth
72
+    },
52 73
     method: 'POST',
53 74
     body: JSON.stringify({
54 75
       parent_id: idFolder,

+ 12 - 12
src/container/HtmlDocument.jsx View File

@@ -74,11 +74,11 @@ class HtmlDocument extends React.Component {
74 74
   }
75 75
 
76 76
   loadContent = async () => {
77
-    const { content, config } = this.state
77
+    const { loggedUser, content, config } = this.state
78 78
 
79
-    const fetchResultHtmlDocument = getHtmlDocContent(config.apiUrl, content.workspace_id, content.content_id)
80
-    const fetchResultComment = getHtmlDocComment(config.apiUrl, content.workspace_id, content.content_id)
81
-    const fetchResultRevision = getHtmlDocRevision(config.apiUrl, content.workspace_id, content.content_id)
79
+    const fetchResultHtmlDocument = getHtmlDocContent(loggedUser, config.apiUrl, content.workspace_id, content.content_id)
80
+    const fetchResultComment = getHtmlDocComment(loggedUser, config.apiUrl, content.workspace_id, content.content_id)
81
+    const fetchResultRevision = getHtmlDocRevision(loggedUser, config.apiUrl, content.workspace_id, content.content_id)
82 82
 
83 83
     handleFetchResult(await fetchResultHtmlDocument)
84 84
       .then(resHtmlDocument => this.setState({content: resHtmlDocument.body}))
@@ -126,9 +126,9 @@ class HtmlDocument extends React.Component {
126 126
   }
127 127
 
128 128
   handleSaveEditTitle = async newTitle => {
129
-    const { config, content } = this.state
129
+    const { loggedUser, config, content } = this.state
130 130
 
131
-    const fetchResultSaveHtmlDoc = putHtmlDocContent(config.apiUrl, content.workspace_id, content.content_id, newTitle, content.raw_content)
131
+    const fetchResultSaveHtmlDoc = putHtmlDocContent(loggedUser, config.apiUrl, content.workspace_id, content.content_id, newTitle, content.raw_content)
132 132
 
133 133
     handleFetchResult(await fetchResultSaveHtmlDoc)
134 134
       .then(resSave => {
@@ -145,9 +145,9 @@ class HtmlDocument extends React.Component {
145 145
   }
146 146
 
147 147
   handleSaveHtmlDocument = async () => {
148
-    const { content, config } = this.state
148
+    const { loggedUser, content, config } = this.state
149 149
 
150
-    const fetchResultSaveHtmlDoc = putHtmlDocContent(config.apiUrl, content.workspace_id, content.content_id, content.label, content.raw_content)
150
+    const fetchResultSaveHtmlDoc = putHtmlDocContent(loggedUser, config.apiUrl, content.workspace_id, content.content_id, content.label, content.raw_content)
151 151
 
152 152
     handleFetchResult(await fetchResultSaveHtmlDoc)
153 153
       .then(resSave => {
@@ -171,9 +171,9 @@ class HtmlDocument extends React.Component {
171 171
   }
172 172
 
173 173
   handleClickValidateNewCommentBtn = async () => {
174
-    const { config, content, newComment } = this.state
174
+    const { loggedUser, config, content, newComment } = this.state
175 175
 
176
-    const fetchResultSaveNewComment = await postHtmlDocNewComment(config.apiUrl, content.workspace_id, content.content_id, newComment)
176
+    const fetchResultSaveNewComment = await postHtmlDocNewComment(loggedUser, config.apiUrl, content.workspace_id, content.content_id, newComment)
177 177
 
178 178
     handleFetchResult(await fetchResultSaveNewComment)
179 179
       .then(resSave => {
@@ -190,9 +190,9 @@ class HtmlDocument extends React.Component {
190 190
   handleToggleWysiwyg = () => this.setState(prev => ({timelineWysiwyg: !prev.timelineWysiwyg}))
191 191
 
192 192
   handleChangeStatus = async newStatus => {
193
-    const { config, content } = this.state
193
+    const { loggedUser, config, content } = this.state
194 194
 
195
-    const fetchResultSaveEditStatus = putHtmlDocStatus(config.apiUrl, content.workspace_id, content.content_id, newStatus)
195
+    const fetchResultSaveEditStatus = putHtmlDocStatus(loggedUser, config.apiUrl, content.workspace_id, content.content_id, newStatus)
196 196
 
197 197
     handleFetchResult(await fetchResultSaveEditStatus)
198 198
       .then(resSave => {

+ 2 - 2
src/container/PopupCreateHtmlDocument.jsx View File

@@ -55,9 +55,9 @@ class PopupCreateHtmlDocument extends React.Component {
55 55
   })
56 56
 
57 57
   handleValidate = async () => {
58
-    const { config, appName, idWorkspace, idFolder, newContentName } = this.state
58
+    const { loggedUser, config, appName, idWorkspace, idFolder, newContentName } = this.state
59 59
 
60
-    const fetchSaveNewHtmlDoc = postHtmlDocContent(config.apiUrl, idWorkspace, idFolder, config.slug, newContentName)
60
+    const fetchSaveNewHtmlDoc = postHtmlDocContent(loggedUser, config.apiUrl, idWorkspace, idFolder, config.slug, newContentName)
61 61
 
62 62
     handleFetchResult(await fetchSaveNewHtmlDoc)
63 63
       .then(resSave => {

+ 1 - 2
src/helper.js View File

@@ -3,8 +3,7 @@ import { timelineDebugData } from './timelineDebugData.js'
3 3
 export const FETCH_CONFIG = {
4 4
   headers: {
5 5
     'Accept': 'application/json',
6
-    'Content-Type': 'application/json',
7
-    'Authorization': 'Basic ' + btoa(`${'admin@admin.admin'}:${'admin@admin.admin'}`)
6
+    'Content-Type': 'application/json'
8 7
   }
9 8
 }
10 9