- commit
- 7f01eb3
- parent
- a827ced
- author
- Eric Bower
- date
- 2024-08-19 20:48:25 +0000 UTC
feat(pgs): block uploads for specific projects
5 files changed,
+18,
-5
M
db/db.go
+1,
-0
1@@ -59,6 +59,7 @@ type Project struct {
2 ProjectDir string `json:"project_dir"`
3 Username string `json:"username"`
4 Acl ProjectAcl `json:"acl"`
5+ Blocked string `json:"blocked"`
6 CreatedAt *time.Time `json:"created_at"`
7 UpdatedAt *time.Time `json:"updated_at"`
8 }
+9,
-4
1@@ -251,11 +251,11 @@ const (
2 sqlInsertProject = `INSERT INTO projects (user_id, name, project_dir) VALUES ($1, $2, $3) RETURNING id;`
3 sqlUpdateProject = `UPDATE projects SET updated_at = $3 WHERE user_id = $1 AND name = $2;`
4 sqlUpdateProjectAcl = `UPDATE projects SET acl = $3, updated_at = $4 WHERE user_id = $1 AND name = $2;`
5- sqlFindProjectByName = `SELECT id, user_id, name, project_dir, acl, created_at, updated_at FROM projects WHERE user_id = $1 AND name = $2;`
6+ sqlFindProjectByName = `SELECT id, user_id, name, project_dir, acl, blocked, created_at, updated_at FROM projects WHERE user_id = $1 AND name = $2;`
7 sqlSelectProjectCount = `SELECT count(id) FROM projects`
8- sqlFindProjectsByUser = `SELECT id, user_id, name, project_dir, acl, created_at, updated_at FROM projects WHERE user_id = $1 ORDER BY name ASC, updated_at DESC;`
9- sqlFindProjectsByPrefix = `SELECT id, user_id, name, project_dir, acl, created_at, updated_at FROM projects WHERE user_id = $1 AND name = project_dir AND name ILIKE $2 ORDER BY updated_at ASC, name ASC;`
10- sqlFindProjectLinks = `SELECT id, user_id, name, project_dir, acl, created_at, updated_at FROM projects WHERE user_id = $1 AND name != project_dir AND project_dir = $2 ORDER BY name ASC;`
11+ sqlFindProjectsByUser = `SELECT id, user_id, name, project_dir, acl, blocked, created_at, updated_at FROM projects WHERE user_id = $1 ORDER BY name ASC, updated_at DESC;`
12+ sqlFindProjectsByPrefix = `SELECT id, user_id, name, project_dir, acl, blocked, created_at, updated_at FROM projects WHERE user_id = $1 AND name = project_dir AND name ILIKE $2 ORDER BY updated_at ASC, name ASC;`
13+ sqlFindProjectLinks = `SELECT id, user_id, name, project_dir, acl, blocked, created_at, updated_at FROM projects WHERE user_id = $1 AND name != project_dir AND project_dir = $2 ORDER BY name ASC;`
14 sqlLinkToProject = `UPDATE projects SET project_dir = $1, updated_at = $2 WHERE id = $3;`
15 sqlRemoveProject = `DELETE FROM projects WHERE id = $1;`
16 )
17@@ -1632,6 +1632,7 @@ func (me *PsqlDB) FindProjectByName(userID, name string) (*db.Project, error) {
18 &project.Name,
19 &project.ProjectDir,
20 &project.Acl,
21+ &project.Blocked,
22 &project.CreatedAt,
23 &project.UpdatedAt,
24 )
25@@ -1656,6 +1657,7 @@ func (me *PsqlDB) FindProjectLinks(userID, name string) ([]*db.Project, error) {
26 &project.Name,
27 &project.ProjectDir,
28 &project.Acl,
29+ &project.Blocked,
30 &project.CreatedAt,
31 &project.UpdatedAt,
32 )
33@@ -1687,6 +1689,7 @@ func (me *PsqlDB) FindProjectsByPrefix(userID, prefix string) ([]*db.Project, er
34 &project.Name,
35 &project.ProjectDir,
36 &project.Acl,
37+ &project.Blocked,
38 &project.CreatedAt,
39 &project.UpdatedAt,
40 )
41@@ -1718,6 +1721,7 @@ func (me *PsqlDB) FindProjectsByUser(userID string) ([]*db.Project, error) {
42 &project.Name,
43 &project.ProjectDir,
44 &project.Acl,
45+ &project.Blocked,
46 &project.CreatedAt,
47 &project.UpdatedAt,
48 )
49@@ -1756,6 +1760,7 @@ func (me *PsqlDB) FindAllProjects(page *db.Pager, by string) (*db.Paginate[*db.P
50 &project.Name,
51 &project.ProjectDir,
52 &project.Acl,
53+ &project.Blocked,
54 &project.CreatedAt,
55 &project.UpdatedAt,
56 )
+5,
-0
1@@ -294,6 +294,11 @@ func (h *UploadAssetHandler) Write(s ssh.Session, entry *utils.FileEntry) (strin
2 setProject(s, project)
3 }
4
5+ if project.Blocked != "" {
6+ msg := "project has been blocked and cannot upload files: %s"
7+ return "", fmt.Errorf(msg, project.Blocked)
8+ }
9+
10 if entry.Mode.IsDir() {
11 _, _, err := h.Storage.PutObject(
12 bucket,
+2,
-0
1@@ -24,6 +24,7 @@ func projectTable(styles common.Styles, projects []*db.Project, width int) *tabl
2 "Links To",
3 "ACL Type",
4 "ACL",
5+ "Blocked",
6 }
7 data := [][]string{}
8 for _, project := range projects {
9@@ -40,6 +41,7 @@ func projectTable(styles common.Styles, projects []*db.Project, width int) *tabl
10 project.Acl.Type,
11 strings.Join(project.Acl.Data, " "),
12 )
13+ row = append(row, project.Blocked)
14 data = append(data, row)
15 }
16
+1,
-1
1@@ -78,7 +78,7 @@ func WishMiddleware(handler *uploadassets.UploadAssetHandler) wish.Middleware {
2 }
3
4 // default width and height when no pty
5- width := 80
6+ width := 100
7 height := 24
8 pty, _, ok := sesh.Pty()
9 if ok {