@@ -1813,7 +1813,7 @@ func TestWorkspaceFilter(t *testing.T) {
1813
1813
})
1814
1814
}
1815
1815
1816
- t .Run ("SharedWithUser " ,func (t * testing.T ) {
1816
+ t .Run ("Shared " ,func (t * testing.T ) {
1817
1817
t .Parallel ()
1818
1818
1819
1819
dv := coderdtest .DeploymentValues (t )
@@ -1851,7 +1851,7 @@ func TestWorkspaceFilter(t *testing.T) {
1851
1851
require .Equal (t ,workspaces .Workspaces [0 ].ID ,sharedWorkspace .ID )
1852
1852
})
1853
1853
1854
- t .Run ("NotSharedWithUser " ,func (t * testing.T ) {
1854
+ t .Run ("NotShared " ,func (t * testing.T ) {
1855
1855
t .Parallel ()
1856
1856
1857
1857
dv := coderdtest .DeploymentValues (t )
@@ -1888,6 +1888,82 @@ func TestWorkspaceFilter(t *testing.T) {
1888
1888
require .Equal (t ,1 ,workspaces .Count ,"expected only one workspace" )
1889
1889
require .Equal (t ,workspaces .Workspaces [0 ].ID ,notSharedWorkspace .ID )
1890
1890
})
1891
+
1892
+ t .Run ("SharedWithUserByID" ,func (t * testing.T ) {
1893
+ t .Parallel ()
1894
+
1895
+ dv := coderdtest .DeploymentValues (t )
1896
+ dv .Experiments = []string {string (codersdk .ExperimentWorkspaceSharing )}
1897
+
1898
+ var (
1899
+ client ,db = coderdtest .NewWithDatabase (t ,& coderdtest.Options {
1900
+ DeploymentValues :dv ,
1901
+ })
1902
+ orgOwner = coderdtest .CreateFirstUser (t ,client )
1903
+ _ ,workspaceOwner = coderdtest .CreateAnotherUser (t ,client ,orgOwner .OrganizationID ,rbac .ScopedRoleOrgAuditor (orgOwner .OrganizationID ))
1904
+ sharedWorkspace = dbfake .WorkspaceBuild (t ,db , database.WorkspaceTable {
1905
+ OwnerID :workspaceOwner .ID ,
1906
+ OrganizationID :orgOwner .OrganizationID ,
1907
+ }).Do ().Workspace
1908
+ _ = dbfake .WorkspaceBuild (t ,db , database.WorkspaceTable {
1909
+ OwnerID :workspaceOwner .ID ,
1910
+ OrganizationID :orgOwner .OrganizationID ,
1911
+ }).Do ().Workspace
1912
+ _ ,toShareWithUser = coderdtest .CreateAnotherUser (t ,client ,orgOwner .OrganizationID )
1913
+ ctx = testutil .Context (t ,testutil .WaitMedium )
1914
+ )
1915
+
1916
+ client .UpdateWorkspaceACL (ctx ,sharedWorkspace .ID , codersdk.UpdateWorkspaceACL {
1917
+ UserRoles :map [string ]codersdk.WorkspaceRole {
1918
+ toShareWithUser .ID .String ():codersdk .WorkspaceRoleUse ,
1919
+ },
1920
+ })
1921
+
1922
+ workspaces ,err := client .Workspaces (ctx , codersdk.WorkspaceFilter {
1923
+ SharedWithUser :toShareWithUser .ID .String (),
1924
+ })
1925
+ require .NoError (t ,err ,"fetch workspaces" )
1926
+ require .Equal (t ,1 ,workspaces .Count ,"expected only one workspace" )
1927
+ require .Equal (t ,workspaces .Workspaces [0 ].ID ,sharedWorkspace .ID )
1928
+ })
1929
+
1930
+ t .Run ("SharedWithUserByUsername" ,func (t * testing.T ) {
1931
+ t .Parallel ()
1932
+
1933
+ dv := coderdtest .DeploymentValues (t )
1934
+ dv .Experiments = []string {string (codersdk .ExperimentWorkspaceSharing )}
1935
+
1936
+ var (
1937
+ client ,db = coderdtest .NewWithDatabase (t ,& coderdtest.Options {
1938
+ DeploymentValues :dv ,
1939
+ })
1940
+ orgOwner = coderdtest .CreateFirstUser (t ,client )
1941
+ _ ,workspaceOwner = coderdtest .CreateAnotherUser (t ,client ,orgOwner .OrganizationID ,rbac .ScopedRoleOrgAuditor (orgOwner .OrganizationID ))
1942
+ sharedWorkspace = dbfake .WorkspaceBuild (t ,db , database.WorkspaceTable {
1943
+ OwnerID :workspaceOwner .ID ,
1944
+ OrganizationID :orgOwner .OrganizationID ,
1945
+ }).Do ().Workspace
1946
+ _ = dbfake .WorkspaceBuild (t ,db , database.WorkspaceTable {
1947
+ OwnerID :workspaceOwner .ID ,
1948
+ OrganizationID :orgOwner .OrganizationID ,
1949
+ }).Do ().Workspace
1950
+ _ ,toShareWithUser = coderdtest .CreateAnotherUser (t ,client ,orgOwner .OrganizationID )
1951
+ ctx = testutil .Context (t ,testutil .WaitMedium )
1952
+ )
1953
+
1954
+ client .UpdateWorkspaceACL (ctx ,sharedWorkspace .ID , codersdk.UpdateWorkspaceACL {
1955
+ UserRoles :map [string ]codersdk.WorkspaceRole {
1956
+ toShareWithUser .ID .String ():codersdk .WorkspaceRoleUse ,
1957
+ },
1958
+ })
1959
+
1960
+ workspaces ,err := client .Workspaces (ctx , codersdk.WorkspaceFilter {
1961
+ SharedWithUser :toShareWithUser .Username ,
1962
+ })
1963
+ require .NoError (t ,err ,"fetch workspaces" )
1964
+ require .Equal (t ,1 ,workspaces .Count ,"expected only one workspace" )
1965
+ require .Equal (t ,workspaces .Workspaces [0 ].ID ,sharedWorkspace .ID )
1966
+ })
1891
1967
}
1892
1968
1893
1969
// TestWorkspaceFilterManual runs some specific setups with basic checks.