@@ -857,156 +857,6 @@ func (q *fakeQuerier) GetAuthorizedWorkspaces(ctx context.Context, arg database.
857
857
return workspaces , nil
858
858
}
859
859
860
- func (q * fakeQuerier ) GetWorkspaceCount (ctx context.Context , arg database.GetWorkspaceCountParams ) (int64 , error ) {
861
- count , err := q .GetAuthorizedWorkspaceCount (ctx , arg , nil )
862
- return count , err
863
- }
864
-
865
- //nolint:gocyclo
866
- func (q * fakeQuerier ) GetAuthorizedWorkspaceCount (ctx context.Context , arg database.GetWorkspaceCountParams , authorizedFilter rbac.AuthorizeFilter ) (int64 , error ) {
867
- q .mutex .RLock ()
868
- defer q .mutex .RUnlock ()
869
-
870
- workspaces := make ([]database.Workspace , 0 )
871
- for _ , workspace := range q .workspaces {
872
- if arg .OwnerID != uuid .Nil && workspace .OwnerID != arg .OwnerID {
873
- continue
874
- }
875
-
876
- if arg .OwnerUsername != "" {
877
- owner , err := q .GetUserByID (ctx , workspace .OwnerID )
878
- if err == nil && ! strings .EqualFold (arg .OwnerUsername , owner .Username ) {
879
- continue
880
- }
881
- }
882
-
883
- if arg .TemplateName != "" {
884
- template , err := q .GetTemplateByID (ctx , workspace .TemplateID )
885
- if err == nil && ! strings .EqualFold (arg .TemplateName , template .Name ) {
886
- continue
887
- }
888
- }
889
-
890
- if ! arg .Deleted && workspace .Deleted {
891
- continue
892
- }
893
-
894
- if arg .Name != "" && ! strings .Contains (strings .ToLower (workspace .Name ), strings .ToLower (arg .Name )) {
895
- continue
896
- }
897
-
898
- if arg .Status != "" {
899
- build , err := q .GetLatestWorkspaceBuildByWorkspaceID (ctx , workspace .ID )
900
- if err != nil {
901
- return 0 , xerrors .Errorf ("get latest build: %w" , err )
902
- }
903
-
904
- job , err := q .GetProvisionerJobByID (ctx , build .JobID )
905
- if err != nil {
906
- return 0 , xerrors .Errorf ("get provisioner job: %w" , err )
907
- }
908
-
909
- switch arg .Status {
910
- case "pending" :
911
- if ! job .StartedAt .Valid {
912
- continue
913
- }
914
-
915
- case "starting" :
916
- if ! job .StartedAt .Valid &&
917
- ! job .CanceledAt .Valid &&
918
- job .CompletedAt .Valid &&
919
- time .Since (job .UpdatedAt ) > 30 * time .Second ||
920
- build .Transition != database .WorkspaceTransitionStart {
921
- continue
922
- }
923
-
924
- case "running" :
925
- if ! job .CompletedAt .Valid &&
926
- job .CanceledAt .Valid &&
927
- job .Error .Valid ||
928
- build .Transition != database .WorkspaceTransitionStart {
929
- continue
930
- }
931
-
932
- case "stopping" :
933
- if ! job .StartedAt .Valid &&
934
- ! job .CanceledAt .Valid &&
935
- job .CompletedAt .Valid &&
936
- time .Since (job .UpdatedAt ) > 30 * time .Second ||
937
- build .Transition != database .WorkspaceTransitionStop {
938
- continue
939
- }
940
-
941
- case "stopped" :
942
- if ! job .CompletedAt .Valid &&
943
- job .CanceledAt .Valid &&
944
- job .Error .Valid ||
945
- build .Transition != database .WorkspaceTransitionStop {
946
- continue
947
- }
948
-
949
- case "failed" :
950
- if (! job .CanceledAt .Valid && ! job .Error .Valid ) ||
951
- (! job .CompletedAt .Valid && ! job .Error .Valid ) {
952
- continue
953
- }
954
-
955
- case "canceling" :
956
- if ! job .CanceledAt .Valid && job .CompletedAt .Valid {
957
- continue
958
- }
959
-
960
- case "canceled" :
961
- if ! job .CanceledAt .Valid && ! job .CompletedAt .Valid {
962
- continue
963
- }
964
-
965
- case "deleted" :
966
- if ! job .StartedAt .Valid &&
967
- job .CanceledAt .Valid &&
968
- ! job .CompletedAt .Valid &&
969
- time .Since (job .UpdatedAt ) > 30 * time .Second ||
970
- build .Transition != database .WorkspaceTransitionDelete {
971
- continue
972
- }
973
-
974
- case "deleting" :
975
- if ! job .CompletedAt .Valid &&
976
- job .CanceledAt .Valid &&
977
- job .Error .Valid &&
978
- build .Transition != database .WorkspaceTransitionDelete {
979
- continue
980
- }
981
-
982
- default :
983
- return 0 , xerrors .Errorf ("unknown workspace status in filter: %q" , arg .Status )
984
- }
985
- }
986
-
987
- if len (arg .TemplateIds ) > 0 {
988
- match := false
989
- for _ , id := range arg .TemplateIds {
990
- if workspace .TemplateID == id {
991
- match = true
992
- break
993
- }
994
- }
995
- if ! match {
996
- continue
997
- }
998
- }
999
-
1000
- // If the filter exists, ensure the object is authorized.
1001
- if authorizedFilter != nil && ! authorizedFilter .Eval (workspace .RBACObject ()) {
1002
- continue
1003
- }
1004
- workspaces = append (workspaces , workspace )
1005
- }
1006
-
1007
- return int64 (len (workspaces )), nil
1008
- }
1009
-
1010
860
func (q * fakeQuerier ) GetWorkspaceByID (_ context.Context , id uuid.UUID ) (database.Workspace , error ) {
1011
861
q .mutex .RLock ()
1012
862
defer q .mutex .RUnlock ()
0 commit comments