Skip to content

Commit b8e14ee

Browse files
authored
improve versioning status display and delete with versions when versioning is suspended (#2689)
1 parent c700ee4 commit b8e14ee

File tree

18 files changed

+375
-61
lines changed

18 files changed

+375
-61
lines changed

integration/user_api_bucket_test.go

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2289,16 +2289,21 @@ func TestBucketVersioning(t *testing.T) {
22892289
200, getVersioningResult.StatusCode, "Status Code is incorrect")
22902290
}
22912291
bodyBytes, _ := ioutil.ReadAll(getVersioningResult.Body)
2292-
structBucketRepl := models.BucketVersioningResponse{}
2292+
structBucketRepl := models.BucketVersioningResponse{
2293+
ExcludeFolders: false,
2294+
ExcludedPrefixes: nil,
2295+
MFADelete: "",
2296+
Status: "",
2297+
}
22932298
err = json.Unmarshal(bodyBytes, &structBucketRepl)
22942299
if err != nil {
22952300
log.Println(err)
22962301
assert.Nil(err)
22972302
}
22982303
assert.Equal(
2299-
structBucketRepl.IsVersioned,
2300-
true,
2301-
structBucketRepl.IsVersioned,
2304+
structBucketRepl.Status,
2305+
"Enabled",
2306+
structBucketRepl.Status,
23022307
)
23032308

23042309
fmt.Println("Versioned bucket creation test status:", response.Status)
@@ -3045,7 +3050,7 @@ func TestSetBucketVersioning(t *testing.T) {
30453050
return
30463051
}
30473052

3048-
// 2. Set versioning as False
3053+
// 2. Set versioning as False i.e Suspend versioning
30493054
response, err := SetBucketVersioning(bucket, false, nil, nil)
30503055
assert.Nil(err)
30513056
if err != nil {
@@ -3069,13 +3074,18 @@ func TestSetBucketVersioning(t *testing.T) {
30693074
200, getVersioningResult.StatusCode, "Status Code is incorrect")
30703075
}
30713076
bodyBytes, _ := ioutil.ReadAll(getVersioningResult.Body)
3072-
result := models.BucketVersioningResponse{}
3077+
result := models.BucketVersioningResponse{
3078+
ExcludeFolders: false,
3079+
ExcludedPrefixes: nil,
3080+
MFADelete: "",
3081+
Status: "",
3082+
}
30733083
err = json.Unmarshal(bodyBytes, &result)
30743084
if err != nil {
30753085
log.Println(err)
30763086
assert.Nil(err)
30773087
}
3078-
assert.Equal(false, result.IsVersioned, result)
3088+
assert.Equal("Suspended", result.Status, result)
30793089
}
30803090

30813091
func EnableBucketEncryption(bucketName, encType, kmsKeyID string) (*http.Response, error) {

models/bucket_versioning_response.go

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

portal-ui/src/screens/Console/Buckets/BucketDetails/BrowserHandler.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ import { decodeURLString, encodeURLString } from "../../../../common/utils";
5454
import { permissionItems } from "../ListBuckets/Objects/utils";
5555
import { setErrorSnackMessage } from "../../../../systemSlice";
5656
import api from "../../../../common/api";
57-
import { BucketObjectLocking, BucketVersioning } from "../types";
57+
import { BucketObjectLocking, BucketVersioningInfo } from "../types";
5858
import { ErrorResponseHandler } from "../../../../common/types";
5959
import OBHeader from "../../ObjectBrowser/OBHeader";
6060

@@ -401,8 +401,8 @@ const BrowserHandler = () => {
401401
if (displayListObjects) {
402402
api
403403
.invoke("GET", `/api/v1/buckets/${bucketName}/versioning`)
404-
.then((res: BucketVersioning) => {
405-
dispatch(setIsVersioned(res.is_versioned));
404+
.then((res: BucketVersioningInfo) => {
405+
dispatch(setIsVersioned(res));
406406
dispatch(setLoadingVersioning(false));
407407
})
408408
.catch((err: ErrorResponseHandler) => {

portal-ui/src/screens/Console/Buckets/BucketDetails/BucketSummaryPanel.tsx

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import {
2727
BucketObjectLocking,
2828
BucketQuota,
2929
BucketReplication,
30-
BucketVersioning,
30+
BucketVersioningInfo,
3131
} from "../types";
3232
import { BucketList } from "../../Watch/types";
3333
import {
@@ -61,6 +61,7 @@ import {
6161
setBucketDetailsLoad,
6262
} from "./bucketDetailsSlice";
6363
import { useAppDispatch } from "../../../../store";
64+
import VersioningInfo from "../VersioningInfo";
6465

6566
const SetAccessPolicy = withSuspense(
6667
React.lazy(() => import("./SetAccessPolicy"))
@@ -121,7 +122,7 @@ const BucketSummary = ({ classes }: IBucketSummaryProps) => {
121122
const [loadingQuota, setLoadingQuota] = useState<boolean>(true);
122123
const [loadingReplication, setLoadingReplication] = useState<boolean>(true);
123124
const [loadingRetention, setLoadingRetention] = useState<boolean>(true);
124-
const [isVersioned, setIsVersioned] = useState<boolean>(false);
125+
const [versioningInfo, setVersioningInfo] = useState<BucketVersioningInfo>();
125126
const [quotaEnabled, setQuotaEnabled] = useState<boolean>(false);
126127
const [quota, setQuota] = useState<BucketQuota | null>(null);
127128
const [encryptionEnabled, setEncryptionEnabled] = useState<boolean>(false);
@@ -203,8 +204,8 @@ const BucketSummary = ({ classes }: IBucketSummaryProps) => {
203204
if (loadingVersioning && distributedSetup) {
204205
api
205206
.invoke("GET", `/api/v1/buckets/${bucketName}/versioning`)
206-
.then((res: BucketVersioning) => {
207-
setIsVersioned(res.is_versioned);
207+
.then((res: BucketVersioningInfo) => {
208+
setVersioningInfo(res);
208209
setLoadingVersioning(false);
209210
})
210211
.catch((err: ErrorResponseHandler) => {
@@ -370,6 +371,15 @@ const BucketSummary = ({ classes }: IBucketSummaryProps) => {
370371
loadAllBucketData();
371372
}
372373
};
374+
375+
let versioningStatus = versioningInfo?.Status;
376+
let versioningText = "Unversioned (Default)";
377+
if (versioningStatus === "Enabled") {
378+
versioningText = "Versioned";
379+
} else if (versioningStatus === "Suspended") {
380+
versioningText = "Suspended";
381+
}
382+
373383
// @ts-ignore
374384
return (
375385
<Fragment>
@@ -412,7 +422,7 @@ const BucketSummary = ({ classes }: IBucketSummaryProps) => {
412422
closeVersioningModalAndRefresh={closeEnableVersioning}
413423
modalOpen={enableVersioningOpen}
414424
selectedBucket={bucketName}
415-
versioningCurrentState={isVersioned}
425+
versioningInfo={versioningInfo}
416426
/>
417427
)}
418428

@@ -576,10 +586,27 @@ const BucketSummary = ({ classes }: IBucketSummaryProps) => {
576586
]}
577587
resourceName={bucketName}
578588
property={"Current Status:"}
579-
value={isVersioned ? "Versioned" : "Unversioned (Default)"}
589+
value={
590+
<Box
591+
sx={{
592+
display: "flex",
593+
flexDirection: "column",
594+
textDecorationStyle: "normal",
595+
placeItems: "flex-start",
596+
justifyItems: "flex-start",
597+
gap: 3,
598+
}}
599+
>
600+
<div> {versioningText}</div>
601+
</Box>
602+
}
580603
onEdit={setBucketVersioning}
581604
isLoading={loadingVersioning}
582605
/>
606+
607+
{versioningInfo?.Status === "Enabled" ? (
608+
<VersioningInfo versioningState={versioningInfo} />
609+
) : null}
583610
</Box>
584611
</Box>
585612
</Grid>

portal-ui/src/screens/Console/Buckets/BucketDetails/EnableVersioningModal.tsx

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,24 @@ import { ConfirmModalIcon } from "mds";
2424

2525
import { setErrorSnackMessage } from "../../../../systemSlice";
2626
import { useAppDispatch } from "../../../../store";
27+
import { BucketVersioningInfo } from "../types";
28+
import VersioningInfo from "../VersioningInfo";
2729

2830
interface IVersioningEventProps {
2931
closeVersioningModalAndRefresh: (refresh: boolean) => void;
3032
modalOpen: boolean;
3133
selectedBucket: string;
32-
versioningCurrentState: boolean;
34+
versioningInfo: BucketVersioningInfo | undefined;
3335
}
3436

3537
const EnableVersioningModal = ({
3638
closeVersioningModalAndRefresh,
3739
modalOpen,
3840
selectedBucket,
39-
versioningCurrentState,
41+
versioningInfo = {},
4042
}: IVersioningEventProps) => {
43+
const isVersioningEnabled = versioningInfo.Status === "Enabled";
44+
4145
const dispatch = useAppDispatch();
4246
const [versioningLoading, setVersioningLoading] = useState<boolean>(false);
4347

@@ -49,7 +53,7 @@ const EnableVersioningModal = ({
4953

5054
api
5155
.invoke("PUT", `/api/v1/buckets/${selectedBucket}/versioning`, {
52-
versioning: !versioningCurrentState,
56+
versioning: !isVersioningEnabled,
5357
})
5458
.then(() => {
5559
setVersioningLoading(false);
@@ -64,7 +68,7 @@ const EnableVersioningModal = ({
6468
return (
6569
<ConfirmDialog
6670
title={`Versioning on Bucket`}
67-
confirmText={versioningCurrentState ? "Disable" : "Enable"}
71+
confirmText={isVersioningEnabled ? "Suspend" : "Enable"}
6872
isOpen={modalOpen}
6973
isLoading={versioningLoading}
7074
titleIcon={<ConfirmModalIcon />}
@@ -78,15 +82,24 @@ const EnableVersioningModal = ({
7882
confirmationContent={
7983
<DialogContentText id="alert-dialog-description">
8084
Are you sure you want to{" "}
81-
<strong>{versioningCurrentState ? "disable" : "enable"}</strong>{" "}
85+
<strong>{isVersioningEnabled ? "suspend" : "enable"}</strong>{" "}
8286
versioning for this bucket?
83-
{versioningCurrentState && (
87+
{isVersioningEnabled && (
8488
<Fragment>
8589
<br />
8690
<br />
8791
<strong>File versions won't be automatically deleted.</strong>
8892
</Fragment>
8993
)}
94+
<div
95+
style={{
96+
paddingTop: "20px",
97+
}}
98+
>
99+
{isVersioningEnabled ? (
100+
<VersioningInfo versioningState={versioningInfo} />
101+
) : null}
102+
</div>
90103
</DialogContentText>
91104
}
92105
/>

0 commit comments

Comments
 (0)