dashboard / git-pr / feat: improve documentation #18 rss

accepted · opened on 2024-08-29T14:09:39Z by in0rdr
Help
# add changes to patch request
git format-patch main --stdout | ssh pr.pico.sh pr add 18
# add review to patch request
git format-patch main --stdout | ssh pr.pico.sh pr add --review 18
# remove patchset
ssh pr.pico.sh ps rm ps-x
# checkout all patches
ssh pr.pico.sh pr print 18 | git am -3
# print a diff between the last two patches in a patch request
ssh pr.pico.sh pr diff 18
# accept PR
ssh pr.pico.sh pr accept 18
# close PR
ssh pr.pico.sh pr close 18

Logs

erock created pr with ps-34 on 2024-08-19T20:48:55Z
erock changed status on 2024-08-31T15:28:44Z {"status":"accepted"}

Patchsets

ps-34 by erock on 2024-08-19T20:48:55Z

chore(pgs): add projects.blocked col

Sometimes users have sites that violate our ToS.  We can delete the
content but if they have a script that will reupload it will
automatically recreate the site.  So we need a way to prevent uploads to
projects.
Makefile link
+2 -1
 1diff --git a/Makefile b/Makefile
 2index 050b7b6..1fdba5b 100644
 3--- a/Makefile
 4+++ b/Makefile
 5@@ -123,10 +123,11 @@ migrate:
 6 	$(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240221_add_project_acl.sql
 7 	$(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240311_add_public_key_name.sql
 8 	$(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240324_add_analytics_table.sql
 9+	$(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240819_add_projects_blocked.sql
10 .PHONY: migrate
11 
12 latest:
13-	$(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240324_add_analytics_table.sql
14+	$(DOCKER_CMD) exec -i $(DB_CONTAINER) psql -U $(PGUSER) -d $(PGDATABASE) < ./sql/migrations/20240819_add_projects_blocked.sql
15 .PHONY: latest
16 
17 psql:
sql/migrations/20240819_add_projects_blocked.sql link
+1 -0
1diff --git a/sql/migrations/20240819_add_projects_blocked.sql b/sql/migrations/20240819_add_projects_blocked.sql
2new file mode 100644
3index 0000000..f3aa794
4--- /dev/null
5+++ b/sql/migrations/20240819_add_projects_blocked.sql
6@@ -0,0 +1,1 @@
7+ALTER TABLE projects ADD COLUMN blocked varchar(256) NOT NULL DEFAULT '';

feat(pgs): block uploads for specific projects

db/db.go link
+1 -0
 1diff --git a/db/db.go b/db/db.go
 2index 2c82dc4..855f6fa 100644
 3--- a/db/db.go
 4+++ b/db/db.go
 5@@ -59,6 +59,7 @@ type Project struct {
 6 	ProjectDir string     `json:"project_dir"`
 7 	Username   string     `json:"username"`
 8 	Acl        ProjectAcl `json:"acl"`
 9+	Blocked    string     `json:"blocked"`
10 	CreatedAt  *time.Time `json:"created_at"`
11 	UpdatedAt  *time.Time `json:"updated_at"`
12 }
db/postgres/storage.go link
+9 -4
 1diff --git a/db/postgres/storage.go b/db/postgres/storage.go
 2index 1b98756..0aec6c7 100644
 3--- a/db/postgres/storage.go
 4+++ b/db/postgres/storage.go
 5@@ -251,11 +251,11 @@ const (
 6 	sqlInsertProject        = `INSERT INTO projects (user_id, name, project_dir) VALUES ($1, $2, $3) RETURNING id;`
 7 	sqlUpdateProject        = `UPDATE projects SET updated_at = $3 WHERE user_id = $1 AND name = $2;`
 8 	sqlUpdateProjectAcl     = `UPDATE projects SET acl = $3, updated_at = $4 WHERE user_id = $1 AND name = $2;`
 9-	sqlFindProjectByName    = `SELECT id, user_id, name, project_dir, acl, created_at, updated_at FROM projects WHERE user_id = $1 AND name = $2;`
10+	sqlFindProjectByName    = `SELECT id, user_id, name, project_dir, acl, blocked, created_at, updated_at FROM projects WHERE user_id = $1 AND name = $2;`
11 	sqlSelectProjectCount   = `SELECT count(id) FROM projects`
12-	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;`
13-	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;`
14-	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;`
15+	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;`
16+	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;`
17+	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;`
18 	sqlLinkToProject        = `UPDATE projects SET project_dir = $1, updated_at = $2 WHERE id = $3;`
19 	sqlRemoveProject        = `DELETE FROM projects WHERE id = $1;`
20 )
21@@ -1632,6 +1632,7 @@ func (me *PsqlDB) FindProjectByName(userID, name string) (*db.Project, error) {
22 		&project.Name,
23 		&project.ProjectDir,
24 		&project.Acl,
25+		&project.Blocked,
26 		&project.CreatedAt,
27 		&project.UpdatedAt,
28 	)
29@@ -1656,6 +1657,7 @@ func (me *PsqlDB) FindProjectLinks(userID, name string) ([]*db.Project, error) {
30 			&project.Name,
31 			&project.ProjectDir,
32 			&project.Acl,
33+			&project.Blocked,
34 			&project.CreatedAt,
35 			&project.UpdatedAt,
36 		)
37@@ -1687,6 +1689,7 @@ func (me *PsqlDB) FindProjectsByPrefix(userID, prefix string) ([]*db.Project, er
38 			&project.Name,
39 			&project.ProjectDir,
40 			&project.Acl,
41+			&project.Blocked,
42 			&project.CreatedAt,
43 			&project.UpdatedAt,
44 		)
45@@ -1718,6 +1721,7 @@ func (me *PsqlDB) FindProjectsByUser(userID string) ([]*db.Project, error) {
46 			&project.Name,
47 			&project.ProjectDir,
48 			&project.Acl,
49+			&project.Blocked,
50 			&project.CreatedAt,
51 			&project.UpdatedAt,
52 		)
53@@ -1756,6 +1760,7 @@ func (me *PsqlDB) FindAllProjects(page *db.Pager, by string) (*db.Paginate[*db.P
54 			&project.Name,
55 			&project.ProjectDir,
56 			&project.Acl,
57+			&project.Blocked,
58 			&project.CreatedAt,
59 			&project.UpdatedAt,
60 		)
filehandlers/assets/handler.go link
+5 -0
 1diff --git a/filehandlers/assets/handler.go b/filehandlers/assets/handler.go
 2index 22edce6..7332d35 100644
 3--- a/filehandlers/assets/handler.go
 4+++ b/filehandlers/assets/handler.go
 5@@ -294,6 +294,11 @@ func (h *UploadAssetHandler) Write(s ssh.Session, entry *utils.FileEntry) (strin
 6 		setProject(s, project)
 7 	}
 8 
 9+	if project.Blocked != "" {
10+		msg := "project has been blocked and cannot upload files: %s"
11+		return "", fmt.Errorf(msg, project.Blocked)
12+	}
13+
14 	if entry.Mode.IsDir() {
15 		_, _, err := h.Storage.PutObject(
16 			bucket,
pgs/cli.go link
+2 -0
 1diff --git a/pgs/cli.go b/pgs/cli.go
 2index 0af5802..faeef45 100644
 3--- a/pgs/cli.go
 4+++ b/pgs/cli.go
 5@@ -24,6 +24,7 @@ func projectTable(styles common.Styles, projects []*db.Project, width int) *tabl
 6 		"Links To",
 7 		"ACL Type",
 8 		"ACL",
 9+		"Blocked",
10 	}
11 	data := [][]string{}
12 	for _, project := range projects {
13@@ -40,6 +41,7 @@ func projectTable(styles common.Styles, projects []*db.Project, width int) *tabl
14 			project.Acl.Type,
15 			strings.Join(project.Acl.Data, " "),
16 		)
17+		row = append(row, project.Blocked)
18 		data = append(data, row)
19 	}
20 
pgs/wish.go link
+1 -1
 1diff --git a/pgs/wish.go b/pgs/wish.go
 2index cef389b..c32f6ae 100644
 3--- a/pgs/wish.go
 4+++ b/pgs/wish.go
 5@@ -78,7 +78,7 @@ func WishMiddleware(handler *uploadassets.UploadAssetHandler) wish.Middleware {
 6 			}
 7 
 8 			// default width and height when no pty
 9-			width := 80
10+			width := 100
11 			height := 24
12 			pty, _, ok := sesh.Pty()
13 			if ok {