Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

Add visibility column to project table

天舟f51ca8fd85b9
diff --git a/api/project.go b/api/project.go
index 128dea89ab..b5d309c2f1 100644
--- a/api/project.go
+++ b/api/project.go
@@ -25,6 +25,23 @@ func (e ProjectWorkflowType) String() string {
return ""
}
+type ProjectVisibility string
+
+const (
+ PUBLIC ProjectVisibility = "PUBLIC"
+ PRIVATE ProjectVisibility = "PRIVATE"
+)
+
+func (e ProjectVisibility) String() string {
+ switch e {
+ case PUBLIC:
+ return "PUBLIC"
+ case PRIVATE:
+ return "PRIVATE"
+ }
+ return ""
+}
+
type Project struct {
ID int `jsonapi:"primary,project"`
@@ -44,6 +61,7 @@ type Project struct {
Name string `jsonapi:"attr,name"`
Key string `jsonapi:"attr,key"`
WorkflowType ProjectWorkflowType `jsonapi:"attr,workflowType"`
+ Visibility ProjectVisibility `jsonapi:"attr,visibility"`
}
type ProjectCreate struct {
diff --git a/frontend/src/store/modules/project.ts b/frontend/src/store/modules/project.ts
index 5acf20e6fa..2ef956ecd9 100644
--- a/frontend/src/store/modules/project.ts
+++ b/frontend/src/store/modules/project.ts
@@ -1,22 +1,22 @@
import axios from "axios";
import {
+ empty,
+ EMPTY_ID,
+ MemberId,
+ Principal,
PrincipalId,
- ProjectId,
Project,
ProjectCreate,
- ProjectPatch,
- ProjectState,
- ResourceObject,
- unknown,
+ ProjectId,
ProjectMember,
ProjectMemberCreate,
ProjectMemberPatch,
- MemberId,
+ ProjectPatch,
+ ProjectState,
ResourceIdentifier,
+ ResourceObject,
RowStatus,
- EMPTY_ID,
- empty,
- Principal,
+ unknown,
} from "../../types";
function convert(
@@ -38,6 +38,7 @@ function convert(
updatedTs: attrs.updatedTs,
memberList: [],
workflowType: attrs.workflowType,
+ visibility: attrs.visibility,
};
const memberList: ProjectMember[] = [];
diff --git a/frontend/src/types/common.ts b/frontend/src/types/common.ts
index ad977636a2..ab3f490da1 100644
--- a/frontend/src/types/common.ts
+++ b/frontend/src/types/common.ts
@@ -1,18 +1,18 @@
-import { CommandId, CommandRegisterId, PrincipalId } from "./id";
-import { Principal } from "./principal";
-import { Member } from "./member";
-import { Environment } from "./environment";
-import { Project, ProjectMember } from "./project";
-import { Instance } from "./instance";
+import { Activity } from "./activity";
+import { Bookmark } from "./bookmark";
import { Database } from "./database";
import { DataSource } from "./dataSource";
+import { Environment } from "./environment";
+import { CommandId, CommandRegisterId, PrincipalId } from "./id";
+import { Instance } from "./instance";
import { Issue } from "./issue";
-import { Pipeline, Stage, Task } from "./pipeline";
-import { Activity } from "./activity";
+import { Member } from "./member";
import { Message } from "./message";
-import { Bookmark } from "./bookmark";
-import { VCS } from "./vcs";
+import { Pipeline, Stage, Task } from "./pipeline";
+import { Principal } from "./principal";
+import { Project, ProjectMember } from "./project";
import { Repository } from "./repository";
+import { VCS } from "./vcs";
// System bot id
export const SYSTEM_BOT_ID = 1;
@@ -164,6 +164,7 @@ export const unknown = (
updatedTs: 0,
memberList: [],
workflowType: "UI",
+ visibility: "PUBLIC",
};
const UNKNOWN_PROJECT_MEMBER: ProjectMember = {
@@ -442,6 +443,7 @@ export const empty = (
updatedTs: 0,
memberList: [],
workflowType: "UI",
+ visibility: "PUBLIC",
};
const EMPTY_PROJECT_MEMBER: ProjectMember = {
diff --git a/frontend/src/types/project.ts b/frontend/src/types/project.ts
index e7f5747012..b8513a6386 100644
--- a/frontend/src/types/project.ts
+++ b/frontend/src/types/project.ts
@@ -9,6 +9,8 @@ export type ProjectRoleType = "OWNER" | "DEVELOPER";
export type ProjectWorkflowType = "UI" | "VCS";
+export type ProjectVisibility = "PUBLIC" | "PRIVATE";
+
// Project
export type Project = {
id: ProjectId;
@@ -27,6 +29,7 @@ export type Project = {
// to do various access check.
memberList: ProjectMember[];
workflowType: ProjectWorkflowType;
+ visibility: ProjectVisibility;
};
export type ProjectCreate = {
diff --git a/store/migration/10001__init_schema.sql b/store/migration/10001__init_schema.sql
index 45b7998d09..8fb2cb983b 100644
--- a/store/migration/10001__init_schema.sql
+++ b/store/migration/10001__init_schema.sql
@@ -171,7 +171,8 @@ CREATE TABLE project (
updated_ts BIGINT NOT NULL DEFAULT (strftime('%s', 'now')),
name TEXT NOT NULL,
`key` TEXT NOT NULL UNIQUE,
- workflow_type TEXT NOT NULL CHECK (workflow_type IN ('UI', 'VCS'))
+ workflow_type TEXT NOT NULL CHECK (workflow_type IN ('UI', 'VCS')),
+ visibility TEXT NOT NULL CHECK (visibility IN ('PUBLIC', 'PRIVATE'))
);
INSERT INTO
@@ -181,7 +182,8 @@ INSERT INTO
updater_id,
name,
`key`,
- workflow_type
+ workflow_type,
+ visibility
)
VALUES
(
@@ -190,7 +192,8 @@ VALUES
1,
'Default',
'DEFAULT',
- 'UI'
+ 'UI',
+ 'PUBLIC'
);
UPDATE
diff --git a/store/project.go b/store/project.go
index a284140ece..c594f98d3d 100644
--- a/store/project.go
+++ b/store/project.go
@@ -163,10 +163,11 @@ func createProject(ctx context.Context, tx *Tx, create *api.ProjectCreate) (*api
updater_id,
name,
key,
- workflow_type
+ workflow_type,
+ visibility
)
- VALUES (?, ?, ?, ?, 'UI')
- RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, name, `+"`key`, workflow_type"+`
+ VALUES (?, ?, ?, ?, 'UI', 'PUBLIC')
+ RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, name, `+"`key`, workflow_type, visibility"+`
`,
create.CreatorId,
create.CreatorId,
@@ -191,6 +192,7 @@ func createProject(ctx context.Context, tx *Tx, create *api.ProjectCreate) (*api
&project.Name,
&project.Key,
&project.WorkflowType,
+ &project.Visibility,
); err != nil {
return nil, FormatError(err)
}
@@ -221,7 +223,8 @@ func findProjectList(ctx context.Context, tx *Tx, find *api.ProjectFind) (_ []*a
updated_ts,
name,
key,
- workflow_type
+ workflow_type,
+ visibility
FROM project
WHERE `+strings.Join(where, " AND "),
args...,
@@ -245,6 +248,7 @@ func findProjectList(ctx context.Context, tx *Tx, find *api.ProjectFind) (_ []*a
&project.Name,
&project.Key,
&project.WorkflowType,
+ &project.Visibility,
); err != nil {
return nil, FormatError(err)
}
@@ -282,7 +286,7 @@ func patchProject(ctx context.Context, tx *sql.Tx, patch *api.ProjectPatch) (*ap
UPDATE project
SET `+strings.Join(set, ", ")+`
WHERE id = ?
- RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, name, `+"`key`, workflow_type"+`
+ RETURNING id, row_status, creator_id, created_ts, updater_id, updated_ts, name, `+"`key`, workflow_type, visibility"+`
`,
args...,
)
@@ -303,6 +307,7 @@ func patchProject(ctx context.Context, tx *sql.Tx, patch *api.ProjectPatch) (*ap
&project.Name,
&project.Key,
&project.WorkflowType,
+ &project.Visibility,
); err != nil {
return nil, FormatError(err)
}
diff --git a/store/seed/test/10030__project.sql b/store/seed/test/10030__project.sql
index f997bc57a4..094b9d564f 100644
--- a/store/seed/test/10030__project.sql
+++ b/store/seed/test/10030__project.sql
@@ -5,7 +5,8 @@ INSERT INTO
updater_id,
name,
`key`,
- workflow_type
+ workflow_type,
+ visibility
)
VALUES
(
@@ -14,7 +15,8 @@ VALUES
101,
'Test (UI)',
'TEST',
- 'UI'
+ 'UI',
+ 'PUBLIC'
);
INSERT INTO
@@ -24,7 +26,8 @@ INSERT INTO
updater_id,
name,
`key`,
- workflow_type
+ workflow_type,
+ visibility
)
VALUES
(
@@ -33,7 +36,8 @@ VALUES
101,
'Shop (Git)',
'SHP',
- 'VCS'
+ 'VCS',
+ 'PUBLIC'
);
INSERT INTO
@@ -43,7 +47,8 @@ INSERT INTO
updater_id,
name,
`key`,
- workflow_type
+ workflow_type,
+ visibility
)
VALUES
(
@@ -52,7 +57,8 @@ VALUES
101,
'Blog (Git)',
'BLG',
- 'VCS'
+ 'VCS',
+ 'PUBLIC'
);
INSERT INTO
@@ -63,7 +69,8 @@ INSERT INTO
updater_id,
name,
`key`,
- workflow_type
+ workflow_type,
+ visibility
)
VALUES
(
@@ -73,5 +80,6 @@ VALUES
101,
'Retired Project',
'RTR',
- 'UI'
+ 'UI',
+ 'PUBLIC'
);
\ No newline at end of file