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
41c50e75
Unverified
Commit
41c50e75
authored
Apr 02, 2023
by
boojack
Committed by
GitHub
Apr 02, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
chore: revert resource visibility changes (#1444)
parent
d71bfce1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
22 additions
and
76 deletions
+22
-76
resource.go
api/resource.go
+13
-16
resource.go
server/resource.go
+0
-43
LATEST__SCHEMA.sql
store/db/migration/dev/LATEST__SCHEMA.sql
+1
-2
resource.go
store/resource.go
+8
-15
No files found.
api/resource.go
View file @
41c50e75
...
...
@@ -15,7 +15,6 @@ type Resource struct {
ExternalLink
string
`json:"externalLink"`
Type
string
`json:"type"`
Size
int64
`json:"size"`
Visibility
Visibility
`json:"visibility"`
// Related fields
LinkedMemoAmount
int
`json:"linkedMemoAmount"`
...
...
@@ -32,7 +31,6 @@ type ResourceCreate struct {
ExternalLink
string
`json:"externalLink"`
Type
string
`json:"type"`
Size
int64
`json:"-"`
Visibility
Visibility
`json:"visibility"`
}
type
ResourceFind
struct
{
...
...
@@ -59,7 +57,6 @@ type ResourcePatch struct {
// Domain specific fields
Filename
*
string
`json:"filename"`
Visibility
*
Visibility
`json:"visibility"`
}
type
ResourceDelete
struct
{
...
...
server/resource.go
View file @
41c50e75
...
...
@@ -47,27 +47,6 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
if
resourceCreate
.
ExternalLink
!=
""
&&
!
strings
.
HasPrefix
(
resourceCreate
.
ExternalLink
,
"http"
)
{
return
echo
.
NewHTTPError
(
http
.
StatusBadRequest
,
"Invalid external link"
)
}
if
resourceCreate
.
Visibility
==
""
{
userResourceVisibilitySetting
,
err
:=
s
.
Store
.
FindUserSetting
(
ctx
,
&
api
.
UserSettingFind
{
UserID
:
userID
,
Key
:
api
.
UserSettingResourceVisibilityKey
,
})
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user setting"
)
.
SetInternal
(
err
)
}
if
userResourceVisibilitySetting
!=
nil
{
resourceVisibility
:=
api
.
Private
err
:=
json
.
Unmarshal
([]
byte
(
userResourceVisibilitySetting
.
Value
),
&
resourceVisibility
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to unmarshal user setting value"
)
.
SetInternal
(
err
)
}
resourceCreate
.
Visibility
=
resourceVisibility
}
else
{
// Private is the default resource visibility.
resourceCreate
.
Visibility
=
api
.
Private
}
}
resource
,
err
:=
s
.
Store
.
CreateResource
(
ctx
,
resourceCreate
)
if
err
!=
nil
{
...
...
@@ -215,28 +194,6 @@ func (s *Server) registerResourceRoutes(g *echo.Group) {
}
}
if
resourceCreate
.
Visibility
==
""
{
userResourceVisibilitySetting
,
err
:=
s
.
Store
.
FindUserSetting
(
ctx
,
&
api
.
UserSettingFind
{
UserID
:
userID
,
Key
:
api
.
UserSettingResourceVisibilityKey
,
})
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to find user setting"
)
.
SetInternal
(
err
)
}
if
userResourceVisibilitySetting
!=
nil
{
resourceVisibility
:=
api
.
Private
err
:=
json
.
Unmarshal
([]
byte
(
userResourceVisibilitySetting
.
Value
),
&
resourceVisibility
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to unmarshal user setting value"
)
.
SetInternal
(
err
)
}
resourceCreate
.
Visibility
=
resourceVisibility
}
else
{
// Private is the default resource visibility.
resourceCreate
.
Visibility
=
api
.
Private
}
}
resource
,
err
:=
s
.
Store
.
CreateResource
(
ctx
,
resourceCreate
)
if
err
!=
nil
{
return
echo
.
NewHTTPError
(
http
.
StatusInternalServerError
,
"Failed to create resource"
)
.
SetInternal
(
err
)
...
...
store/db/migration/dev/LATEST__SCHEMA.sql
View file @
41c50e75
...
...
@@ -77,8 +77,7 @@ CREATE TABLE resource (
internal_path
TEXT
NOT
NULL
DEFAULT
''
,
external_link
TEXT
NOT
NULL
DEFAULT
''
,
type
TEXT
NOT
NULL
DEFAULT
''
,
size
INTEGER
NOT
NULL
DEFAULT
0
,
visibility
TEXT
NOT
NULL
CHECK
(
visibility
IN
(
'PUBLIC'
,
'PROTECTED'
,
'PRIVATE'
))
DEFAULT
'PRIVATE'
size
INTEGER
NOT
NULL
DEFAULT
0
);
-- memo_resource
...
...
store/resource.go
View file @
41c50e75
...
...
@@ -28,7 +28,6 @@ type resourceRaw struct {
ExternalLink
string
Type
string
Size
int64
Visibility
api
.
Visibility
LinkedMemoAmount
int
}
...
...
@@ -48,7 +47,6 @@ func (raw *resourceRaw) toResource() *api.Resource {
ExternalLink
:
raw
.
ExternalLink
,
Type
:
raw
.
Type
,
Size
:
raw
.
Size
,
Visibility
:
raw
.
Visibility
,
LinkedMemoAmount
:
raw
.
LinkedMemoAmount
,
}
}
...
...
@@ -197,9 +195,9 @@ func (s *Store) createResourceImpl(ctx context.Context, tx *sql.Tx, create *api.
values
:=
[]
any
{
create
.
Filename
,
create
.
Blob
,
create
.
ExternalLink
,
create
.
Type
,
create
.
Size
,
create
.
CreatorID
}
placeholders
:=
[]
string
{
"?"
,
"?"
,
"?"
,
"?"
,
"?"
,
"?"
}
if
s
.
profile
.
IsDev
()
{
fields
=
append
(
fields
,
"
visibility"
,
"
internal_path"
)
values
=
append
(
values
,
create
.
Visibility
,
create
.
InternalPath
)
placeholders
=
append
(
placeholders
,
"?"
,
"?"
)
fields
=
append
(
fields
,
"internal_path"
)
values
=
append
(
values
,
create
.
InternalPath
)
placeholders
=
append
(
placeholders
,
"?"
)
}
query
:=
`
...
...
@@ -220,7 +218,7 @@ func (s *Store) createResourceImpl(ctx context.Context, tx *sql.Tx, create *api.
&
resourceRaw
.
CreatorID
,
}
if
s
.
profile
.
IsDev
()
{
dests
=
append
(
dests
,
&
resourceRaw
.
Visibility
,
&
resourceRaw
.
InternalPath
)
dests
=
append
(
dests
,
&
resourceRaw
.
InternalPath
)
}
dests
=
append
(
dests
,
[]
any
{
&
resourceRaw
.
CreatedTs
,
&
resourceRaw
.
UpdatedTs
}
...
)
if
err
:=
tx
.
QueryRowContext
(
ctx
,
query
,
values
...
)
.
Scan
(
dests
...
);
err
!=
nil
{
...
...
@@ -239,17 +237,12 @@ func (s *Store) patchResourceImpl(ctx context.Context, tx *sql.Tx, patch *api.Re
if
v
:=
patch
.
Filename
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"filename = ?"
),
append
(
args
,
*
v
)
}
if
s
.
profile
.
IsDev
()
{
if
v
:=
patch
.
Visibility
;
v
!=
nil
{
set
,
args
=
append
(
set
,
"visibility = ?"
),
append
(
args
,
*
v
)
}
}
args
=
append
(
args
,
patch
.
ID
)
fields
:=
[]
string
{
"id"
,
"filename"
,
"external_link"
,
"type"
,
"size"
,
"creator_id"
,
"created_ts"
,
"updated_ts"
}
if
s
.
profile
.
IsDev
()
{
fields
=
append
(
fields
,
"
visibility"
,
"
internal_path"
)
fields
=
append
(
fields
,
"internal_path"
)
}
query
:=
`
...
...
@@ -269,7 +262,7 @@ func (s *Store) patchResourceImpl(ctx context.Context, tx *sql.Tx, patch *api.Re
&
resourceRaw
.
UpdatedTs
,
}
if
s
.
profile
.
IsDev
()
{
dests
=
append
(
dests
,
&
resourceRaw
.
Visibility
,
&
resourceRaw
.
InternalPath
)
dests
=
append
(
dests
,
&
resourceRaw
.
InternalPath
)
}
if
err
:=
tx
.
QueryRowContext
(
ctx
,
query
,
args
...
)
.
Scan
(
dests
...
);
err
!=
nil
{
return
nil
,
FormatError
(
err
)
...
...
@@ -299,7 +292,7 @@ func (s *Store) findResourceListImpl(ctx context.Context, tx *sql.Tx, find *api.
fields
=
append
(
fields
,
"resource.blob"
)
}
if
s
.
profile
.
IsDev
()
{
fields
=
append
(
fields
,
"
visibility"
,
"
internal_path"
)
fields
=
append
(
fields
,
"internal_path"
)
}
query
:=
fmt
.
Sprintf
(
`
...
...
@@ -343,7 +336,7 @@ func (s *Store) findResourceListImpl(ctx context.Context, tx *sql.Tx, find *api.
dests
=
append
(
dests
,
&
resourceRaw
.
Blob
)
}
if
s
.
profile
.
IsDev
()
{
dests
=
append
(
dests
,
&
resourceRaw
.
Visibility
,
&
resourceRaw
.
InternalPath
)
dests
=
append
(
dests
,
&
resourceRaw
.
InternalPath
)
}
if
err
:=
rows
.
Scan
(
dests
...
);
err
!=
nil
{
return
nil
,
FormatError
(
err
)
...
...
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