Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
canifa_note
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Vũ Hoàng Anh
canifa_note
Commits
63468dba
Commit
63468dba
authored
Sep 21, 2022
by
Steven
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: update memo detail access handler
parent
2acd5d4a
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
47 additions
and
36 deletions
+47
-36
acl.go
server/acl.go
+1
-1
memo.go
server/memo.go
+33
-24
MemoCardDialog.tsx
web/src/components/MemoCardDialog.tsx
+0
-5
Toast.tsx
web/src/components/Toast.tsx
+1
-1
MemoDetail.tsx
web/src/pages/MemoDetail.tsx
+12
-5
No files found.
server/acl.go
View file @
63468dba
...
@@ -104,7 +104,7 @@ func aclMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {
...
@@ -104,7 +104,7 @@ func aclMiddleware(s *Server, next echo.HandlerFunc) echo.HandlerFunc {
}
}
}
}
if
common
.
HasPrefixes
(
path
,
"/api/memo/all"
)
&&
c
.
Request
()
.
Method
==
http
.
MethodGet
{
if
common
.
HasPrefixes
(
path
,
"/api/memo/all"
,
"/api/memo/:memoId"
)
&&
c
.
Request
()
.
Method
==
http
.
MethodGet
{
return
next
(
c
)
return
next
(
c
)
}
}
...
...
server/memo.go
View file @
63468dba
...
@@ -203,33 +203,17 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
...
@@ -203,33 +203,17 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
return
nil
return
nil
})
})
g
.
POST
(
"/memo/:memoId/organizer
"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/memo/:memoId
"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
memoID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
memoID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
}
}
userID
,
ok
:=
c
.
Get
(
getUserIDContextKey
())
.
(
int
)
memoFind
:=
&
api
.
MemoFind
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
memoOrganizerUpsert
:=
&
api
.
MemoOrganizerUpsert
{
MemoID
:
memoID
,
UserID
:
userID
,
}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
memoOrganizerUpsert
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post memo organizer request"
)
.
SetInternal
(
err
)
}
err
=
s
.
Store
.
UpsertMemoOrganizer
(
ctx
,
memoOrganizerUpsert
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to upsert memo organizer"
)
.
SetInternal
(
err
)
}
memo
,
err
:=
s
.
Store
.
FindMemo
(
ctx
,
&
api
.
MemoFind
{
ID
:
&
memoID
,
ID
:
&
memoID
,
})
}
memo
,
err
:=
s
.
Store
.
FindMemo
(
ctx
,
memoFind
)
if
err
!=
nil
{
if
err
!=
nil
{
if
common
.
ErrorCode
(
err
)
==
common
.
NotFound
{
if
common
.
ErrorCode
(
err
)
==
common
.
NotFound
{
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"Memo ID not found: %d"
,
memoID
))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"Memo ID not found: %d"
,
memoID
))
.
SetInternal
(
err
)
...
@@ -238,6 +222,15 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
...
@@ -238,6 +222,15 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to find memo by ID: %v"
,
memoID
))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
fmt
.
Sprintf
(
"Failed to find memo by ID: %v"
,
memoID
))
.
SetInternal
(
err
)
}
}
if
memo
.
Visibility
==
api
.
Privite
{
return
echo
.
NewHTTPError
(
http
.
StatusForbidden
,
"this memo is private only"
)
}
else
if
memo
.
Visibility
==
api
.
Protected
{
_
,
ok
:=
c
.
Get
(
getUserIDContextKey
())
.
(
int
)
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusForbidden
,
"this memo is protected, missing user in session"
)
}
}
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
memo
));
err
!=
nil
{
if
err
:=
json
.
NewEncoder
(
c
.
Response
()
.
Writer
)
.
Encode
(
composeResponse
(
memo
));
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to encode memo response"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to encode memo response"
)
.
SetInternal
(
err
)
...
@@ -245,17 +238,33 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
...
@@ -245,17 +238,33 @@ func (s *Server) registerMemoRoutes(g *echo.Group) {
return
nil
return
nil
})
})
g
.
GET
(
"/memo/:memoId
"
,
func
(
c
echo
.
Context
)
error
{
g
.
POST
(
"/memo/:memoId/organizer
"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
memoID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
memoID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"memoId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"memoId"
)))
.
SetInternal
(
err
)
}
}
memoFind
:=
&
api
.
MemoFind
{
userID
,
ok
:=
c
.
Get
(
getUserIDContextKey
())
.
(
int
)
ID
:
&
memoID
,
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
memo
,
err
:=
s
.
Store
.
FindMemo
(
ctx
,
memoFind
)
memoOrganizerUpsert
:=
&
api
.
MemoOrganizerUpsert
{
MemoID
:
memoID
,
UserID
:
userID
,
}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
memoOrganizerUpsert
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post memo organizer request"
)
.
SetInternal
(
err
)
}
err
=
s
.
Store
.
UpsertMemoOrganizer
(
ctx
,
memoOrganizerUpsert
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to upsert memo organizer"
)
.
SetInternal
(
err
)
}
memo
,
err
:=
s
.
Store
.
FindMemo
(
ctx
,
&
api
.
MemoFind
{
ID
:
&
memoID
,
})
if
err
!=
nil
{
if
err
!=
nil
{
if
common
.
ErrorCode
(
err
)
==
common
.
NotFound
{
if
common
.
ErrorCode
(
err
)
==
common
.
NotFound
{
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"Memo ID not found: %d"
,
memoID
))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
fmt
.
Sprintf
(
"Memo ID not found: %d"
,
memoID
))
.
SetInternal
(
err
)
...
...
web/src/components/MemoCardDialog.tsx
View file @
63468dba
...
@@ -115,11 +115,6 @@ const MemoCardDialog: React.FC<Props> = (props: Props) => {
...
@@ -115,11 +115,6 @@ const MemoCardDialog: React.FC<Props> = (props: Props) => {
},
[]);
},
[]);
const
handleGotoMemoLinkBtnClick
=
()
=>
{
const
handleGotoMemoLinkBtnClick
=
()
=>
{
if
(
memo
.
visibility
===
"PRIVATE"
)
{
toastHelper
.
error
(
t
(
"message.private-only"
));
return
;
}
window
.
open
(
`/m/
${
memo
.
id
}
`
);
window
.
open
(
`/m/
${
memo
.
id
}
`
);
};
};
...
...
web/src/components/Toast.tsx
View file @
63468dba
...
@@ -94,7 +94,7 @@ const initialToastHelper = () => {
...
@@ -94,7 +94,7 @@ const initialToastHelper = () => {
return
showToast
({
type
:
"success"
,
content
,
duration
});
return
showToast
({
type
:
"success"
,
content
,
duration
});
};
};
const
error
=
(
content
:
string
,
duration
=
3000
)
=>
{
const
error
=
(
content
:
string
,
duration
=
-
1
)
=>
{
return
showToast
({
type
:
"error"
,
content
,
duration
});
return
showToast
({
type
:
"error"
,
content
,
duration
});
};
};
...
...
web/src/pages/MemoDetail.tsx
View file @
63468dba
...
@@ -7,6 +7,7 @@ import { UNKNOWN_ID } from "../helpers/consts";
...
@@ -7,6 +7,7 @@ import { UNKNOWN_ID } from "../helpers/consts";
import
{
isNullorUndefined
}
from
"../helpers/utils"
;
import
{
isNullorUndefined
}
from
"../helpers/utils"
;
import
{
useAppSelector
}
from
"../store"
;
import
{
useAppSelector
}
from
"../store"
;
import
useLoading
from
"../hooks/useLoading"
;
import
useLoading
from
"../hooks/useLoading"
;
import
toastHelper
from
"../components/Toast"
;
import
MemoContent
from
"../components/MemoContent"
;
import
MemoContent
from
"../components/MemoContent"
;
import
MemoResources
from
"../components/MemoResources"
;
import
MemoResources
from
"../components/MemoResources"
;
import
"../less/explore.less"
;
import
"../less/explore.less"
;
...
@@ -37,12 +38,18 @@ const MemoDetail = () => {
...
@@ -37,12 +38,18 @@ const MemoDetail = () => {
const
memoId
=
Number
(
params
.
memoId
);
const
memoId
=
Number
(
params
.
memoId
);
if
(
memoId
&&
!
isNaN
(
memoId
))
{
if
(
memoId
&&
!
isNaN
(
memoId
))
{
memoService
.
fetchMemoById
(
memoId
).
then
((
memo
)
=>
{
memoService
setState
({
.
fetchMemoById
(
memoId
)
memo
,
.
then
((
memo
)
=>
{
setState
({
memo
,
});
loadingState
.
setFinish
();
})
.
catch
((
error
)
=>
{
console
.
error
(
error
);
toastHelper
.
error
(
error
.
response
.
data
.
message
);
});
});
loadingState
.
setFinish
();
});
}
}
},
[
location
]);
},
[
location
]);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment