Skip to content

Commit 556e869

Browse files
committed
Add feature that disallows reverting append-only mode
1 parent f792e65 commit 556e869

3 files changed

Lines changed: 25 additions & 5 deletions

File tree

.env.sample

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ SSH_SERVER_PORT_LAN=
3535
# Disable the DELETE feature
3636
#DISABLE_DELETE_REPO=true
3737

38+
# Do not allow to remove append-only mode, once set
39+
# DISABLE_REVERT_APPEND_ONLY=true
40+
3841
# Disable the integrations (API tokens to CRUD repositories)
3942
#DISABLE_INTEGRATIONS=true
4043

@@ -50,4 +53,4 @@ MAIL_SMTP_PWD=
5053
MAIL_REJECT_SELFSIGNED_TLS=
5154

5255
# Force app to start on IPv6
53-
#HOSTNAME=::
56+
#HOSTNAME=::

Containers/RepoManage/RepoManage.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,10 +221,18 @@ export default function RepoManage(props: RepoManageProps) {
221221
);
222222
router.replace('/');
223223
} else {
224-
const errorMessage = await response.json();
225-
toast.error(`An error has occurred : ${errorMessage.message.stderr}`, toastOptions);
226-
router.replace('/');
227-
console.log(`Fail to ${props.mode}`);
224+
if (response.status == 403) {
225+
toast.warning(
226+
'🔒 The server is currently protected against reverting append-only mode.',
227+
toastOptions
228+
);
229+
router.replace('/');
230+
} else {
231+
const errorMessage = await response.json();
232+
toast.error(`An error has occurred : ${errorMessage.message.stderr}`, toastOptions);
233+
router.replace('/');
234+
console.log(`Fail to ${props.mode}`);
235+
}
228236
}
229237
})
230238
.catch((error) => {

pages/api/v1/repositories/[slug]/index.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,15 @@ export default async function handler(
9494
'The SSH key is already used in another repository. Please use another key or delete the key from the other repository.',
9595
});
9696
}
97+
if (repo.appendOnlyMode && appendOnlyMode === false) {
98+
if (process.env.DISABLE_REVERT_APPEND_ONLY === "true") {
99+
res.status(403).json({
100+
status: 403,
101+
message: 'Reverting Append-Only mode is disabled on this server',
102+
});
103+
return;
104+
}
105+
}
97106

98107
const updatedRepo: Repository = {
99108
...repo,

0 commit comments

Comments
 (0)