Browse Source

app now handles multi users

Skylsmoi 6 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
 import { FETCH_CONFIG } from './helper.js'
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
   fetch(`${apiUrl}/workspaces/${idWorkspace}/html-documents/${idContent}`, {
4
   fetch(`${apiUrl}/workspaces/${idWorkspace}/html-documents/${idContent}`, {
5
-    ...FETCH_CONFIG,
5
+    headers: {
6
+      ...FETCH_CONFIG.headers,
7
+      'Authorization': 'Basic ' + user.auth
8
+    },
6
     method: 'GET'
9
     method: 'GET'
7
   })
10
   })
8
 
11
 
9
-export const getHtmlDocComment = (apiUrl, idWorkspace, idContent) =>
12
+export const getHtmlDocComment = (user, apiUrl, idWorkspace, idContent) =>
10
   fetch(`${apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/comments`, {
13
   fetch(`${apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/comments`, {
11
-    ...FETCH_CONFIG,
14
+    headers: {
15
+      ...FETCH_CONFIG.headers,
16
+      'Authorization': 'Basic ' + user.auth
17
+    },
12
     method: 'GET'
18
     method: 'GET'
13
   })
19
   })
14
 
20
 
15
-export const getHtmlDocRevision = (apiUrl, idWorkspace, idContent) =>
21
+export const getHtmlDocRevision = (user, apiUrl, idWorkspace, idContent) =>
16
   fetch(`${apiUrl}/workspaces/${idWorkspace}/html-documents/${idContent}/revisions`, {
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
     method: 'GET'
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
   fetch(`${apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/comments`, {
31
   fetch(`${apiUrl}/workspaces/${idWorkspace}/contents/${idContent}/comments`, {
23
-    ...FETCH_CONFIG,
32
+    headers: {
33
+      ...FETCH_CONFIG.headers,
34
+      'Authorization': 'Basic ' + user.auth
35
+    },
24
     method: 'POST',
36
     method: 'POST',
25
     body: JSON.stringify({
37
     body: JSON.stringify({
26
       raw_content: newComment
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
   fetch(`${apiUrl}/workspaces/${idWorkspace}/html-documents/${idContent}`, {
43
   fetch(`${apiUrl}/workspaces/${idWorkspace}/html-documents/${idContent}`, {
32
-    ...FETCH_CONFIG,
44
+    headers: {
45
+      ...FETCH_CONFIG.headers,
46
+      'Authorization': 'Basic ' + user.auth
47
+    },
33
     method: 'PUT',
48
     method: 'PUT',
34
     body: JSON.stringify({
49
     body: JSON.stringify({
35
       label: label,
50
       label: label,
37
     })
52
     })
38
   })
53
   })
39
 
54
 
40
-export const putHtmlDocStatus = (apiUrl, idWorkspace, idContent, newStatus) =>
55
+export const putHtmlDocStatus = (user, apiUrl, idWorkspace, idContent, newStatus) =>
41
   fetch(`${apiUrl}/workspaces/${idWorkspace}/html-documents/${idContent}/status`, {
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
     method: 'PUT',
61
     method: 'PUT',
44
     body: JSON.stringify({
62
     body: JSON.stringify({
45
       status: newStatus
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
   fetch(`${apiUrl}/workspaces/${idWorkspace}/contents`, {
68
   fetch(`${apiUrl}/workspaces/${idWorkspace}/contents`, {
51
-    ...FETCH_CONFIG,
69
+    headers: {
70
+      ...FETCH_CONFIG.headers,
71
+      'Authorization': 'Basic ' + user.auth
72
+    },
52
     method: 'POST',
73
     method: 'POST',
53
     body: JSON.stringify({
74
     body: JSON.stringify({
54
       parent_id: idFolder,
75
       parent_id: idFolder,

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

74
   }
74
   }
75
 
75
 
76
   loadContent = async () => {
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
     handleFetchResult(await fetchResultHtmlDocument)
83
     handleFetchResult(await fetchResultHtmlDocument)
84
       .then(resHtmlDocument => this.setState({content: resHtmlDocument.body}))
84
       .then(resHtmlDocument => this.setState({content: resHtmlDocument.body}))
126
   }
126
   }
127
 
127
 
128
   handleSaveEditTitle = async newTitle => {
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
     handleFetchResult(await fetchResultSaveHtmlDoc)
133
     handleFetchResult(await fetchResultSaveHtmlDoc)
134
       .then(resSave => {
134
       .then(resSave => {
145
   }
145
   }
146
 
146
 
147
   handleSaveHtmlDocument = async () => {
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
     handleFetchResult(await fetchResultSaveHtmlDoc)
152
     handleFetchResult(await fetchResultSaveHtmlDoc)
153
       .then(resSave => {
153
       .then(resSave => {
171
   }
171
   }
172
 
172
 
173
   handleClickValidateNewCommentBtn = async () => {
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
     handleFetchResult(await fetchResultSaveNewComment)
178
     handleFetchResult(await fetchResultSaveNewComment)
179
       .then(resSave => {
179
       .then(resSave => {
190
   handleToggleWysiwyg = () => this.setState(prev => ({timelineWysiwyg: !prev.timelineWysiwyg}))
190
   handleToggleWysiwyg = () => this.setState(prev => ({timelineWysiwyg: !prev.timelineWysiwyg}))
191
 
191
 
192
   handleChangeStatus = async newStatus => {
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
     handleFetchResult(await fetchResultSaveEditStatus)
197
     handleFetchResult(await fetchResultSaveEditStatus)
198
       .then(resSave => {
198
       .then(resSave => {

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

55
   })
55
   })
56
 
56
 
57
   handleValidate = async () => {
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
     handleFetchResult(await fetchSaveNewHtmlDoc)
62
     handleFetchResult(await fetchSaveNewHtmlDoc)
63
       .then(resSave => {
63
       .then(resSave => {

+ 1 - 2
src/helper.js View File

3
 export const FETCH_CONFIG = {
3
 export const FETCH_CONFIG = {
4
   headers: {
4
   headers: {
5
     'Accept': 'application/json',
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