Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 5afa629

Browse files
thxCodegitlawr
authored andcommitted
fix: delete project by viewer
Signed-off-by: thxCode <thxcode0824@gmail.com>
1 parent d15478a commit 5afa629

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

pkg/apis/project/basic.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package project
22

33
import (
4+
"net/http"
5+
46
"github.com/seal-io/walrus/pkg/auths/session"
57
"github.com/seal-io/walrus/pkg/dao"
68
"github.com/seal-io/walrus/pkg/dao/model"
79
"github.com/seal-io/walrus/pkg/dao/model/project"
810
"github.com/seal-io/walrus/pkg/dao/types"
911
"github.com/seal-io/walrus/pkg/dao/types/object"
12+
"github.com/seal-io/walrus/utils/errorx"
1013
)
1114

1215
func (h Handler) Create(req CreateRequest) (CreateResponse, error) {
@@ -119,6 +122,16 @@ func (h Handler) CollectionGet(req CollectionGetRequest) (CollectionGetResponse,
119122
func (h Handler) CollectionDelete(req CollectionDeleteRequest) error {
120123
ids := req.IDs()
121124

125+
// Validate whether the subject has permission to delete the projects.
126+
sj := session.MustGetSubject(req.Context)
127+
if !sj.IsAdmin() {
128+
for i := range ids {
129+
if !sj.Enforce(string(ids[i]), http.MethodDelete, "projects", string(ids[i]), req.Context.FullPath()) {
130+
return errorx.NewHttpError(http.StatusForbidden, "")
131+
}
132+
}
133+
}
134+
122135
return h.modelClient.WithTx(req.Context, func(tx *model.Tx) error {
123136
_, err := tx.Projects().Delete().
124137
Where(project.IDIn(ids...)).

0 commit comments

Comments
 (0)