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
3556ae4e
Unverified
Commit
3556ae4e
authored
Dec 28, 2022
by
boojack
Committed by
GitHub
Dec 28, 2022
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
fix: access control (#870)
parent
f888c628
Changes
14
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
276 additions
and
235 deletions
+276
-235
memo.go
api/memo.go
+4
-4
memo_organizer.go
api/memo_organizer.go
+5
-5
memo_resource.go
api/memo_resource.go
+1
-1
resource.go
api/resource.go
+1
-1
shortcut.go
api/shortcut.go
+1
-1
tag.go
api/tag.go
+1
-1
user_setting.go
api/user_setting.go
+1
-1
auth.go
server/auth.go
+3
-3
memo.go
server/memo.go
+170
-155
resource.go
server/resource.go
+12
-9
shortcut.go
server/shortcut.go
+40
-16
system.go
server/system.go
+19
-10
tag.go
server/tag.go
+7
-21
user.go
server/user.go
+11
-7
No files found.
api/memo.go
View file @
3556ae4e
...
@@ -46,7 +46,7 @@ type Memo struct {
...
@@ -46,7 +46,7 @@ type Memo struct {
type
MemoCreate
struct
{
type
MemoCreate
struct
{
// Standard fields
// Standard fields
CreatorID
int
CreatorID
int
`json:"-"`
// Domain specific fields
// Domain specific fields
Visibility
Visibility
`json:"visibility"`
Visibility
Visibility
`json:"visibility"`
...
@@ -73,11 +73,11 @@ type MemoPatch struct {
...
@@ -73,11 +73,11 @@ type MemoPatch struct {
}
}
type
MemoFind
struct
{
type
MemoFind
struct
{
ID
*
int
`json:"id"`
ID
*
int
// Standard fields
// Standard fields
RowStatus
*
RowStatus
`json:"rowStatus"`
RowStatus
*
RowStatus
CreatorID
*
int
`json:"creatorId"`
CreatorID
*
int
// Domain specific fields
// Domain specific fields
Pinned
*
bool
Pinned
*
bool
...
...
api/memo_organizer.go
View file @
3556ae4e
...
@@ -9,15 +9,15 @@ type MemoOrganizer struct {
...
@@ -9,15 +9,15 @@ type MemoOrganizer struct {
Pinned
bool
Pinned
bool
}
}
type
MemoOrganizerFind
struct
{
type
MemoOrganizerUpsert
struct
{
MemoID
int
MemoID
int
`json:"-"`
UserID
int
UserID
int
`json:"-"`
Pinned
bool
`json:"pinned"`
}
}
type
MemoOrganizer
Upsert
struct
{
type
MemoOrganizer
Find
struct
{
MemoID
int
MemoID
int
UserID
int
UserID
int
Pinned
bool
`json:"pinned"`
}
}
type
MemoOrganizerDelete
struct
{
type
MemoOrganizerDelete
struct
{
...
...
api/memo_resource.go
View file @
3556ae4e
...
@@ -8,7 +8,7 @@ type MemoResource struct {
...
@@ -8,7 +8,7 @@ type MemoResource struct {
}
}
type
MemoResourceUpsert
struct
{
type
MemoResourceUpsert
struct
{
MemoID
int
MemoID
int
`json:"-"`
ResourceID
int
ResourceID
int
UpdatedTs
*
int64
UpdatedTs
*
int64
}
}
...
...
api/resource.go
View file @
3556ae4e
...
@@ -20,7 +20,7 @@ type Resource struct {
...
@@ -20,7 +20,7 @@ type Resource struct {
type
ResourceCreate
struct
{
type
ResourceCreate
struct
{
// Standard fields
// Standard fields
CreatorID
int
CreatorID
int
`json:"-"`
// Domain specific fields
// Domain specific fields
Filename
string
`json:"filename"`
Filename
string
`json:"filename"`
...
...
api/shortcut.go
View file @
3556ae4e
...
@@ -16,7 +16,7 @@ type Shortcut struct {
...
@@ -16,7 +16,7 @@ type Shortcut struct {
type
ShortcutCreate
struct
{
type
ShortcutCreate
struct
{
// Standard fields
// Standard fields
CreatorID
int
CreatorID
int
`json:"-"`
// Domain specific fields
// Domain specific fields
Title
string
`json:"title"`
Title
string
`json:"title"`
...
...
api/tag.go
View file @
3556ae4e
...
@@ -7,7 +7,7 @@ type Tag struct {
...
@@ -7,7 +7,7 @@ type Tag struct {
type
TagUpsert
struct
{
type
TagUpsert
struct
{
Name
string
Name
string
CreatorID
int
CreatorID
int
`json:"-"`
}
}
type
TagFind
struct
{
type
TagFind
struct
{
...
...
api/user_setting.go
View file @
3556ae4e
...
@@ -50,7 +50,7 @@ type UserSetting struct {
...
@@ -50,7 +50,7 @@ type UserSetting struct {
}
}
type
UserSettingUpsert
struct
{
type
UserSettingUpsert
struct
{
UserID
int
UserID
int
`json:"-"`
Key
UserSettingKey
`json:"key"`
Key
UserSettingKey
`json:"key"`
Value
string
`json:"value"`
Value
string
`json:"value"`
}
}
...
...
server/auth.go
View file @
3556ae4e
...
@@ -84,7 +84,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
...
@@ -84,7 +84,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find host user"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find host user"
)
.
SetInternal
(
err
)
}
}
if
signup
.
Role
==
api
.
Host
&&
hostUser
!=
nil
{
if
signup
.
Role
==
api
.
Host
&&
hostUser
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Site Host existed, please contact the site host to signin account firstly
.
"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Site Host existed, please contact the site host to signin account firstly"
)
.
SetInternal
(
err
)
}
}
systemSettingAllowSignUpName
:=
api
.
SystemSettingAllowSignUpName
systemSettingAllowSignUpName
:=
api
.
SystemSettingAllowSignUpName
...
@@ -103,7 +103,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
...
@@ -103,7 +103,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
}
}
}
}
if
!
allowSignUpSettingValue
&&
hostUser
!=
nil
{
if
!
allowSignUpSettingValue
&&
hostUser
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Site Host existed, please contact the site host to signin account firstly
.
"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Site Host existed, please contact the site host to signin account firstly"
)
.
SetInternal
(
err
)
}
}
userCreate
:=
&
api
.
UserCreate
{
userCreate
:=
&
api
.
UserCreate
{
...
@@ -114,7 +114,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
...
@@ -114,7 +114,7 @@ func (s *Server) registerAuthRoutes(g *echo.Group) {
OpenID
:
common
.
GenUUID
(),
OpenID
:
common
.
GenUUID
(),
}
}
if
err
:=
userCreate
.
Validate
();
err
!=
nil
{
if
err
:=
userCreate
.
Validate
();
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Invalid user create format
.
"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Invalid user create format"
)
.
SetInternal
(
err
)
}
}
passwordHash
,
err
:=
bcrypt
.
GenerateFromPassword
([]
byte
(
signup
.
Password
),
bcrypt
.
DefaultCost
)
passwordHash
,
err
:=
bcrypt
.
GenerateFromPassword
([]
byte
(
signup
.
Password
),
bcrypt
.
DefaultCost
)
...
...
server/memo.go
View file @
3556ae4e
This diff is collapsed.
Click to expand it.
server/resource.go
View file @
3556ae4e
...
@@ -56,13 +56,12 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
...
@@ -56,13 +56,12 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
}
}
resourceCreate
:=
&
api
.
ResourceCreate
{
resourceCreate
:=
&
api
.
ResourceCreate
{
CreatorID
:
userID
,
Filename
:
filename
,
Filename
:
filename
,
Type
:
filetype
,
Type
:
filetype
,
Size
:
size
,
Size
:
size
,
Blob
:
fileBytes
,
Blob
:
fileBytes
,
CreatorID
:
userID
,
}
}
resource
,
err
:=
s
.
Store
.
CreateResource
(
ctx
,
resourceCreate
)
resource
,
err
:=
s
.
Store
.
CreateResource
(
ctx
,
resourceCreate
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to create resource"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to create resource"
)
.
SetInternal
(
err
)
...
@@ -158,6 +157,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
...
@@ -158,6 +157,7 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
c
.
Response
()
.
Writer
.
WriteHeader
(
http
.
StatusOK
)
c
.
Response
()
.
Writer
.
WriteHeader
(
http
.
StatusOK
)
c
.
Response
()
.
Writer
.
Header
()
.
Set
(
"Content-Type"
,
resource
.
Type
)
c
.
Response
()
.
Writer
.
Header
()
.
Set
(
"Content-Type"
,
resource
.
Type
)
c
.
Response
()
.
Writer
.
Header
()
.
Set
(
echo
.
HeaderContentSecurityPolicy
,
"default-src 'self'"
)
if
_
,
err
:=
c
.
Response
()
.
Writer
.
Write
(
resource
.
Blob
);
err
!=
nil
{
if
_
,
err
:=
c
.
Response
()
.
Writer
.
Write
(
resource
.
Blob
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to write resource blob"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to write resource blob"
)
.
SetInternal
(
err
)
}
}
...
@@ -177,23 +177,26 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
...
@@ -177,23 +177,26 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
}
}
resourceFind
:=
&
api
.
ResourceFind
{
resourceFind
:=
&
api
.
ResourceFind
{
ID
:
&
resourceID
,
ID
:
&
resourceID
,
CreatorID
:
&
userID
,
}
}
if
_
,
err
:=
s
.
Store
.
FindResource
(
ctx
,
resourceFind
);
err
!=
nil
{
resource
,
err
:=
s
.
Store
.
FindResource
(
ctx
,
resourceFind
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find resource"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find resource"
)
.
SetInternal
(
err
)
}
}
if
resource
.
CreatorID
!=
userID
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Unauthorized"
)
}
currentTs
:=
time
.
Now
()
.
Unix
()
currentTs
:=
time
.
Now
()
.
Unix
()
resourcePatch
:=
&
api
.
ResourcePatch
{
resourcePatch
:=
&
api
.
ResourcePatch
{
ID
:
resourceID
,
UpdatedTs
:
&
currentTs
,
UpdatedTs
:
&
currentTs
,
}
}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
resourcePatch
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
resourcePatch
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted patch resource request"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted patch resource request"
)
.
SetInternal
(
err
)
}
}
resource
,
err
:=
s
.
Store
.
PatchResource
(
ctx
,
resourcePatch
)
resource
.
ID
=
resourceID
resource
,
err
=
s
.
Store
.
PatchResource
(
ctx
,
resourcePatch
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to patch resource"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to patch resource"
)
.
SetInternal
(
err
)
}
}
...
@@ -224,8 +227,8 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
...
@@ -224,8 +227,8 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find resource"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find resource"
)
.
SetInternal
(
err
)
}
}
if
resource
==
nil
{
if
resource
.
CreatorID
!=
userID
{
return
echo
.
NewHTTPError
(
http
.
Status
NotFound
,
"Not find resource"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
Status
Unauthorized
,
"Unauthorized"
)
}
}
resourceDelete
:=
&
api
.
ResourceDelete
{
resourceDelete
:=
&
api
.
ResourceDelete
{
...
...
server/shortcut.go
View file @
3556ae4e
...
@@ -21,13 +21,12 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
...
@@ -21,13 +21,12 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
if
!
ok
{
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
shortcutCreate
:=
&
api
.
ShortcutCreate
{
shortcutCreate
:=
&
api
.
ShortcutCreate
{}
CreatorID
:
userID
,
}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
shortcutCreate
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
shortcutCreate
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post shortcut request"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post shortcut request"
)
.
SetInternal
(
err
)
}
}
shortcutCreate
.
CreatorID
=
userID
shortcut
,
err
:=
s
.
Store
.
CreateShortcut
(
ctx
,
shortcutCreate
)
shortcut
,
err
:=
s
.
Store
.
CreateShortcut
(
ctx
,
shortcutCreate
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to create shortcut"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to create shortcut"
)
.
SetInternal
(
err
)
...
@@ -45,21 +44,36 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
...
@@ -45,21 +44,36 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
g
.
PATCH
(
"/shortcut/:shortcutId"
,
func
(
c
echo
.
Context
)
error
{
g
.
PATCH
(
"/shortcut/:shortcutId"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
getUserIDContextKey
())
.
(
int
)
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
shortcutID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"shortcutId"
))
shortcutID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"shortcutId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"shortcutId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"shortcutId"
)))
.
SetInternal
(
err
)
}
}
shortcutFind
:=
&
api
.
ShortcutFind
{
ID
:
&
shortcutID
,
}
shortcut
,
err
:=
s
.
Store
.
FindShortcut
(
ctx
,
shortcutFind
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find shortcut"
)
.
SetInternal
(
err
)
}
if
shortcut
.
CreatorID
!=
userID
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Unauthorized"
)
}
currentTs
:=
time
.
Now
()
.
Unix
()
currentTs
:=
time
.
Now
()
.
Unix
()
shortcutPatch
:=
&
api
.
ShortcutPatch
{
shortcutPatch
:=
&
api
.
ShortcutPatch
{
ID
:
shortcutID
,
UpdatedTs
:
&
currentTs
,
UpdatedTs
:
&
currentTs
,
}
}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
shortcutPatch
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
shortcutPatch
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted patch shortcut request"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted patch shortcut request"
)
.
SetInternal
(
err
)
}
}
shortcut
,
err
:=
s
.
Store
.
PatchShortcut
(
ctx
,
shortcutPatch
)
shortcutPatch
.
ID
=
shortcutID
shortcut
,
err
=
s
.
Store
.
PatchShortcut
(
ctx
,
shortcutPatch
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to patch shortcut"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to patch shortcut"
)
.
SetInternal
(
err
)
}
}
...
@@ -73,17 +87,12 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
...
@@ -73,17 +87,12 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
g
.
GET
(
"/shortcut"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/shortcut"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
shortcutFind
:=
&
api
.
ShortcutFind
{}
userID
,
ok
:=
c
.
Get
(
getUserIDContextKey
())
.
(
int
)
if
!
ok
{
if
userID
,
err
:=
strconv
.
Atoi
(
c
.
QueryParam
(
"creatorId"
));
err
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Missing user id to find shortcut"
)
shortcutFind
.
CreatorID
=
&
userID
}
}
else
{
shortcutFind
:=
&
api
.
ShortcutFind
{
userID
,
ok
:=
c
.
Get
(
getUserIDContextKey
())
.
(
int
)
CreatorID
:
&
userID
,
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Missing user id to find shortcut"
)
}
shortcutFind
.
CreatorID
=
&
userID
}
}
list
,
err
:=
s
.
Store
.
FindShortcutList
(
ctx
,
shortcutFind
)
list
,
err
:=
s
.
Store
.
FindShortcutList
(
ctx
,
shortcutFind
)
...
@@ -122,11 +131,26 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
...
@@ -122,11 +131,26 @@ func (s *Server) registerShortcutRoutes(g *echo.Group) {
g
.
DELETE
(
"/shortcut/:shortcutId"
,
func
(
c
echo
.
Context
)
error
{
g
.
DELETE
(
"/shortcut/:shortcutId"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
getUserIDContextKey
())
.
(
int
)
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
shortcutID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"shortcutId"
))
shortcutID
,
err
:=
strconv
.
Atoi
(
c
.
Param
(
"shortcutId"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"shortcutId"
)))
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
fmt
.
Sprintf
(
"ID is not a number: %s"
,
c
.
Param
(
"shortcutId"
)))
.
SetInternal
(
err
)
}
}
shortcutFind
:=
&
api
.
ShortcutFind
{
ID
:
&
shortcutID
,
}
shortcut
,
err
:=
s
.
Store
.
FindShortcut
(
ctx
,
shortcutFind
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find shortcut"
)
.
SetInternal
(
err
)
}
if
shortcut
.
CreatorID
!=
userID
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Unauthorized"
)
}
shortcutDelete
:=
&
api
.
ShortcutDelete
{
shortcutDelete
:=
&
api
.
ShortcutDelete
{
ID
:
&
shortcutID
,
ID
:
&
shortcutID
,
}
}
...
...
server/system.go
View file @
3556ae4e
...
@@ -76,13 +76,24 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
...
@@ -76,13 +76,24 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
systemStatus
.
AdditionalScript
=
value
.
(
string
)
systemStatus
.
AdditionalScript
=
value
.
(
string
)
}
else
if
systemSetting
.
Name
==
api
.
SystemSettingCustomizedProfileName
{
}
else
if
systemSetting
.
Name
==
api
.
SystemSettingCustomizedProfileName
{
valueMap
:=
value
.
(
map
[
string
]
interface
{})
valueMap
:=
value
.
(
map
[
string
]
interface
{})
systemStatus
.
CustomizedProfile
=
api
.
CustomizedProfile
{
systemStatus
.
CustomizedProfile
=
api
.
CustomizedProfile
{}
Name
:
valueMap
[
"name"
]
.
(
string
),
if
v
:=
valueMap
[
"name"
];
v
!=
nil
{
LogoURL
:
valueMap
[
"logoUrl"
]
.
(
string
),
systemStatus
.
CustomizedProfile
.
Name
=
v
.
(
string
)
Description
:
valueMap
[
"description"
]
.
(
string
),
}
Locale
:
valueMap
[
"locale"
]
.
(
string
),
if
v
:=
valueMap
[
"logoUrl"
];
v
!=
nil
{
Appearance
:
valueMap
[
"appearance"
]
.
(
string
),
systemStatus
.
CustomizedProfile
.
LogoURL
=
v
.
(
string
)
ExternalURL
:
valueMap
[
"externalUrl"
]
.
(
string
),
}
if
v
:=
valueMap
[
"description"
];
v
!=
nil
{
systemStatus
.
CustomizedProfile
.
Description
=
v
.
(
string
)
}
if
v
:=
valueMap
[
"locale"
];
v
!=
nil
{
systemStatus
.
CustomizedProfile
.
Locale
=
v
.
(
string
)
}
if
v
:=
valueMap
[
"appearance"
];
v
!=
nil
{
systemStatus
.
CustomizedProfile
.
Appearance
=
v
.
(
string
)
}
if
v
:=
valueMap
[
"externalUrl"
];
v
!=
nil
{
systemStatus
.
CustomizedProfile
.
ExternalURL
=
v
.
(
string
)
}
}
}
}
}
}
...
@@ -125,9 +136,7 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
...
@@ -125,9 +136,7 @@ func (s *Server) registerSystemRoutes(g *echo.Group) {
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user"
)
.
SetInternal
(
err
)
}
}
if
user
==
nil
{
if
user
==
nil
||
user
.
Role
!=
api
.
Host
{
return
echo
.
NewHTTPError
(
http
.
StatusNotFound
,
"Current signin user not found"
)
}
else
if
user
.
Role
!=
api
.
Host
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Unauthorized"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Unauthorized"
)
}
}
...
...
server/tag.go
View file @
3556ae4e
...
@@ -23,9 +23,7 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
...
@@ -23,9 +23,7 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Missing user in session"
)
}
}
tagUpsert
:=
&
api
.
TagUpsert
{
tagUpsert
:=
&
api
.
TagUpsert
{}
CreatorID
:
userID
,
}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
tagUpsert
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
tagUpsert
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post tag request"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post tag request"
)
.
SetInternal
(
err
)
}
}
...
@@ -33,6 +31,7 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
...
@@ -33,6 +31,7 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Tag name shouldn't be empty"
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Tag name shouldn't be empty"
)
}
}
tagUpsert
.
CreatorID
=
userID
tag
,
err
:=
s
.
Store
.
UpsertTag
(
ctx
,
tagUpsert
)
tag
,
err
:=
s
.
Store
.
UpsertTag
(
ctx
,
tagUpsert
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to upsert tag"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to upsert tag"
)
.
SetInternal
(
err
)
...
@@ -82,31 +81,18 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
...
@@ -82,31 +81,18 @@ func (s *Server) registerTagRoutes(g *echo.Group) {
g
.
GET
(
"/tag/suggestion"
,
func
(
c
echo
.
Context
)
error
{
g
.
GET
(
"/tag/suggestion"
,
func
(
c
echo
.
Context
)
error
{
ctx
:=
c
.
Request
()
.
Context
()
ctx
:=
c
.
Request
()
.
Context
()
userID
,
ok
:=
c
.
Get
(
getUserIDContextKey
())
.
(
int
)
if
!
ok
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Missing user session"
)
}
contentSearch
:=
"#"
contentSearch
:=
"#"
normalRowStatus
:=
api
.
Normal
normalRowStatus
:=
api
.
Normal
memoFind
:=
api
.
MemoFind
{
memoFind
:=
api
.
MemoFind
{
CreatorID
:
&
userID
,
ContentSearch
:
&
contentSearch
,
ContentSearch
:
&
contentSearch
,
RowStatus
:
&
normalRowStatus
,
RowStatus
:
&
normalRowStatus
,
}
}
if
userID
,
err
:=
strconv
.
Atoi
(
c
.
QueryParam
(
"creatorId"
));
err
==
nil
{
memoFind
.
CreatorID
=
&
userID
}
currentUserID
,
ok
:=
c
.
Get
(
getUserIDContextKey
())
.
(
int
)
if
!
ok
{
if
memoFind
.
CreatorID
==
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Missing user id to find memo"
)
}
memoFind
.
VisibilityList
=
[]
api
.
Visibility
{
api
.
Public
}
}
else
{
if
memoFind
.
CreatorID
==
nil
{
memoFind
.
CreatorID
=
&
currentUserID
}
else
{
memoFind
.
VisibilityList
=
[]
api
.
Visibility
{
api
.
Public
,
api
.
Protected
}
}
}
memoList
,
err
:=
s
.
Store
.
FindMemoList
(
ctx
,
&
memoFind
)
memoList
,
err
:=
s
.
Store
.
FindMemoList
(
ctx
,
&
memoFind
)
if
err
!=
nil
{
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find memo list"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find memo list"
)
.
SetInternal
(
err
)
...
...
server/user.go
View file @
3556ae4e
...
@@ -29,18 +29,20 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
...
@@ -29,18 +29,20 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user by id"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user by id"
)
.
SetInternal
(
err
)
}
}
if
currentUser
.
Role
!=
api
.
Host
{
if
currentUser
.
Role
!=
api
.
Host
{
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Only Host user can create member
.
"
)
return
echo
.
NewHTTPError
(
http
.
StatusUnauthorized
,
"Only Host user can create member"
)
}
}
userCreate
:=
&
api
.
UserCreate
{
userCreate
:=
&
api
.
UserCreate
{}
OpenID
:
common
.
GenUUID
(),
}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
userCreate
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
userCreate
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post user request"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted post user request"
)
.
SetInternal
(
err
)
}
}
if
userCreate
.
Role
==
api
.
Host
{
return
echo
.
NewHTTPError
(
http
.
StatusForbidden
,
"Could not create host user"
)
}
userCreate
.
OpenID
=
common
.
GenUUID
()
if
err
:=
userCreate
.
Validate
();
err
!=
nil
{
if
err
:=
userCreate
.
Validate
();
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Invalid user create format
.
"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Invalid user create format"
)
.
SetInternal
(
err
)
}
}
passwordHash
,
err
:=
bcrypt
.
GenerateFromPassword
([]
byte
(
userCreate
.
Password
),
bcrypt
.
DefaultCost
)
passwordHash
,
err
:=
bcrypt
.
GenerateFromPassword
([]
byte
(
userCreate
.
Password
),
bcrypt
.
DefaultCost
)
...
@@ -74,6 +76,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
...
@@ -74,6 +76,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
for
_
,
user
:=
range
userList
{
for
_
,
user
:=
range
userList
{
// data desensitize
// data desensitize
user
.
OpenID
=
""
user
.
OpenID
=
""
user
.
Email
=
""
}
}
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
...
@@ -159,6 +162,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
...
@@ -159,6 +162,7 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
if
user
!=
nil
{
if
user
!=
nil
{
// data desensitize
// data desensitize
user
.
OpenID
=
""
user
.
OpenID
=
""
user
.
Email
=
""
}
}
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
c
.
Response
()
.
Header
()
.
Set
(
echo
.
HeaderContentType
,
echo
.
MIMEApplicationJSONCharsetUTF8
)
...
@@ -192,14 +196,14 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
...
@@ -192,14 +196,14 @@ func (s *Server) registerUserRoutes(g *echo.Group) {
currentTs
:=
time
.
Now
()
.
Unix
()
currentTs
:=
time
.
Now
()
.
Unix
()
userPatch
:=
&
api
.
UserPatch
{
userPatch
:=
&
api
.
UserPatch
{
ID
:
userID
,
UpdatedTs
:
&
currentTs
,
UpdatedTs
:
&
currentTs
,
}
}
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
userPatch
);
err
!=
nil
{
if
err
:=
json
.
NewDecoder
(
c
.
Request
()
.
Body
)
.
Decode
(
userPatch
);
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted patch user request"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Malformatted patch user request"
)
.
SetInternal
(
err
)
}
}
userPatch
.
ID
=
userID
if
err
:=
userPatch
.
Validate
();
err
!=
nil
{
if
err
:=
userPatch
.
Validate
();
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Invalid user patch format
.
"
)
.
SetInternal
(
err
)
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Invalid user patch format"
)
.
SetInternal
(
err
)
}
}
if
userPatch
.
Password
!=
nil
&&
*
userPatch
.
Password
!=
""
{
if
userPatch
.
Password
!=
nil
&&
*
userPatch
.
Password
!=
""
{
...
...
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