Skip to content

Commit 5df70a6

Browse files
authored
feat: add organization scope for shared ports (#18314)
1 parent eff2174 commit 5df70a6

File tree

30 files changed

+1246
-812
lines changed

30 files changed

+1246
-812
lines changed

CLAUDE.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,4 +101,7 @@ Read [cursor rules](.cursorrules).
101101

102102
## Frontend
103103

104+
The frontend is contained in the site folder.
105+
106+
For building Frontend refer to [this document](docs/contributing/frontend.md)
104107
For building Frontend refer to [this document](docs/about/contributing/frontend.md)

agent/proto/agent.pb.go

Lines changed: 722 additions & 713 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

agent/proto/agent.proto

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ message WorkspaceApp {
2424
OWNER = 1;
2525
AUTHENTICATED = 2;
2626
PUBLIC = 3;
27+
ORGANIZATION = 4;
2728
}
2829
SharingLevel sharing_level = 10;
2930

@@ -401,10 +402,11 @@ message CreateSubAgentRequest {
401402
TAB = 1;
402403
}
403404

404-
enum Share {
405+
enum SharingLevel {
405406
OWNER = 0;
406407
AUTHENTICATED = 1;
407408
PUBLIC = 2;
409+
ORGANIZATION = 3;
408410
}
409411

410412
string slug = 1;
@@ -417,7 +419,7 @@ message CreateSubAgentRequest {
417419
optional string icon = 8;
418420
optional OpenIn open_in = 9;
419421
optional int32 order = 10;
420-
optional Share share = 11;
422+
optional SharingLevel share = 11;
421423
optional bool subdomain = 12;
422424
optional string url = 13;
423425
}

coderd/agentapi/subagent.go

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"database/sql"
66
"errors"
77
"fmt"
8+
"strings"
89

910
"github.com/google/uuid"
1011
"github.com/sqlc-dev/pqtype"
@@ -140,20 +141,15 @@ func (a *SubAgentAPI) CreateSubAgent(ctx context.Context, req *agentproto.Create
140141
health = database.WorkspaceAppHealthInitializing
141142
}
142143

143-
var sharingLevel database.AppSharingLevel
144-
switch app.GetShare() {
145-
case agentproto.CreateSubAgentRequest_App_OWNER:
146-
sharingLevel = database.AppSharingLevelOwner
147-
case agentproto.CreateSubAgentRequest_App_AUTHENTICATED:
148-
sharingLevel = database.AppSharingLevelAuthenticated
149-
case agentproto.CreateSubAgentRequest_App_PUBLIC:
150-
sharingLevel = database.AppSharingLevelPublic
151-
default:
144+
share := app.GetShare()
145+
protoSharingLevel, ok := agentproto.CreateSubAgentRequest_App_SharingLevel_name[int32(share)]
146+
if !ok {
152147
return codersdk.ValidationError{
153148
Field: "share",
154-
Detail: fmt.Sprintf("%q is not a valid app sharing level", app.GetShare()),
149+
Detail: fmt.Sprintf("%q is not a valid app sharing level", share.String()),
155150
}
156151
}
152+
sharingLevel := database.AppSharingLevel(strings.ToLower(protoSharingLevel))
157153

158154
var openIn database.WorkspaceAppOpenIn
159155
switch app.GetOpenIn() {

coderd/apidoc/docs.go

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 7 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/database/dump.sql

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
-- Drop the view that depends on the templates table
3+
DROP VIEW template_with_names;
4+
5+
-- Remove 'organization' from the app_sharing_level enum
6+
CREATE TYPE new_app_sharing_level AS ENUM (
7+
'owner',
8+
'authenticated',
9+
'public'
10+
);
11+
12+
-- Update workspace_agent_port_share table to use old enum
13+
-- Convert any 'organization' values to 'authenticated' during downgrade
14+
ALTER TABLE workspace_agent_port_share
15+
ALTER COLUMN share_level TYPE new_app_sharing_level USING (
16+
CASE
17+
WHEN share_level = 'organization' THEN 'authenticated'::new_app_sharing_level
18+
ELSE share_level::text::new_app_sharing_level
19+
END
20+
);
21+
22+
-- Update workspace_apps table to use old enum
23+
-- Convert any 'organization' values to 'authenticated' during downgrade
24+
ALTER TABLE workspace_apps
25+
ALTER COLUMN sharing_level DROP DEFAULT,
26+
ALTER COLUMN sharing_level TYPE new_app_sharing_level USING (
27+
CASE
28+
WHEN sharing_level = 'organization' THEN 'authenticated'::new_app_sharing_level
29+
ELSE sharing_level::text::new_app_sharing_level
30+
END
31+
),
32+
ALTER COLUMN sharing_level SET DEFAULT 'owner'::new_app_sharing_level;
33+
34+
-- Update templates table to use old enum
35+
-- Convert any 'organization' values to 'authenticated' during downgrade
36+
ALTER TABLE templates
37+
ALTER COLUMN max_port_sharing_level DROP DEFAULT,
38+
ALTER COLUMN max_port_sharing_level TYPE new_app_sharing_level USING (
39+
CASE
40+
WHEN max_port_sharing_level = 'organization' THEN 'owner'::new_app_sharing_level
41+
ELSE max_port_sharing_level::text::new_app_sharing_level
42+
END
43+
),
44+
ALTER COLUMN max_port_sharing_level SET DEFAULT 'owner'::new_app_sharing_level;
45+
46+
-- Drop old enum and rename new one
47+
DROP TYPE app_sharing_level;
48+
ALTER TYPE new_app_sharing_level RENAME TO app_sharing_level;
49+
50+
-- Recreate the template_with_names view
51+
52+
CREATE VIEW template_with_names AS
53+
SELECT templates.id,
54+
templates.created_at,
55+
templates.updated_at,
56+
templates.organization_id,
57+
templates.deleted,
58+
templates.name,
59+
templates.provisioner,
60+
templates.active_version_id,
61+
templates.description,
62+
templates.default_ttl,
63+
templates.created_by,
64+
templates.icon,
65+
templates.user_acl,
66+
templates.group_acl,
67+
templates.display_name,
68+
templates.allow_user_cancel_workspace_jobs,
69+
templates.allow_user_autostart,
70+
templates.allow_user_autostop,
71+
templates.failure_ttl,
72+
templates.time_til_dormant,
73+
templates.time_til_dormant_autodelete,
74+
templates.autostop_requirement_days_of_week,
75+
templates.autostop_requirement_weeks,
76+
templates.autostart_block_days_of_week,
77+
templates.require_active_version,
78+
templates.deprecated,
79+
templates.activity_bump,
80+
templates.max_port_sharing_level,
81+
templates.use_classic_parameter_flow,
82+
COALESCE(visible_users.avatar_url, ''::text) AS created_by_avatar_url,
83+
COALESCE(visible_users.username, ''::text) AS created_by_username,
84+
COALESCE(visible_users.name, ''::text) AS created_by_name,
85+
COALESCE(organizations.name, ''::text) AS organization_name,
86+
COALESCE(organizations.display_name, ''::text) AS organization_display_name,
87+
COALESCE(organizations.icon, ''::text) AS organization_icon
88+
FROM ((templates
89+
LEFT JOIN visible_users ON ((templates.created_by = visible_users.id)))
90+
LEFT JOIN organizations ON ((templates.organization_id = organizations.id)));
91+
92+
COMMENT ON VIEW template_with_names IS 'Joins in the display name information such as username, avatar, and organization name.';
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
-- Drop the view that depends on the templates table
2+
DROP VIEW template_with_names;
3+
4+
-- Add 'organization' to the app_sharing_level enum
5+
CREATE TYPE new_app_sharing_level AS ENUM (
6+
'owner',
7+
'authenticated',
8+
'organization',
9+
'public'
10+
);
11+
12+
-- Update workspace_agent_port_share table to use new enum
13+
ALTER TABLE workspace_agent_port_share
14+
ALTER COLUMN share_level TYPE new_app_sharing_level USING (share_level::text::new_app_sharing_level);
15+
16+
-- Update workspace_apps table to use new enum
17+
ALTER TABLE workspace_apps
18+
ALTER COLUMN sharing_level DROP DEFAULT,
19+
ALTER COLUMN sharing_level TYPE new_app_sharing_level USING (sharing_level::text::new_app_sharing_level),
20+
ALTER COLUMN sharing_level SET DEFAULT 'owner'::new_app_sharing_level;
21+
22+
-- Update templates table to use new enum
23+
ALTER TABLE templates
24+
ALTER COLUMN max_port_sharing_level DROP DEFAULT,
25+
ALTER COLUMN max_port_sharing_level TYPE new_app_sharing_level USING (max_port_sharing_level::text::new_app_sharing_level),
26+
ALTER COLUMN max_port_sharing_level SET DEFAULT 'owner'::new_app_sharing_level;
27+
28+
-- Drop old enum and rename new one
29+
DROP TYPE app_sharing_level;
30+
ALTER TYPE new_app_sharing_level RENAME TO app_sharing_level;
31+
32+
-- Recreate the template_with_names view
33+
CREATE VIEW template_with_names AS
34+
SELECT templates.id,
35+
templates.created_at,
36+
templates.updated_at,
37+
templates.organization_id,
38+
templates.deleted,
39+
templates.name,
40+
templates.provisioner,
41+
templates.active_version_id,
42+
templates.description,
43+
templates.default_ttl,
44+
templates.created_by,
45+
templates.icon,
46+
templates.user_acl,
47+
templates.group_acl,
48+
templates.display_name,
49+
templates.allow_user_cancel_workspace_jobs,
50+
templates.allow_user_autostart,
51+
templates.allow_user_autostop,
52+
templates.failure_ttl,
53+
templates.time_til_dormant,
54+
templates.time_til_dormant_autodelete,
55+
templates.autostop_requirement_days_of_week,
56+
templates.autostop_requirement_weeks,
57+
templates.autostart_block_days_of_week,
58+
templates.require_active_version,
59+
templates.deprecated,
60+
templates.activity_bump,
61+
templates.max_port_sharing_level,
62+
templates.use_classic_parameter_flow,
63+
COALESCE(visible_users.avatar_url, ''::text) AS created_by_avatar_url,
64+
COALESCE(visible_users.username, ''::text) AS created_by_username,
65+
COALESCE(visible_users.name, ''::text) AS created_by_name,
66+
COALESCE(organizations.name, ''::text) AS organization_name,
67+
COALESCE(organizations.display_name, ''::text) AS organization_display_name,
68+
COALESCE(organizations.icon, ''::text) AS organization_icon
69+
FROM ((templates
70+
LEFT JOIN visible_users ON ((templates.created_by = visible_users.id)))
71+
LEFT JOIN organizations ON ((templates.organization_id = organizations.id)));
72+
73+
COMMENT ON VIEW template_with_names IS 'Joins in the display name information such as username, avatar, and organization name.';

coderd/database/models.go

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy