mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 16:29:22 +00:00
feat(storage): add team auto-archive assets policy and background job (#516)
* feat(storage): add team auto-archive assets policy and background job * fix(storage): address code review feedback on lock safety, starvation, and permissions * docs: update readme and expand archive storage documentation with auto-archive details * feat(storage): log info message on auto-archive job start and finish with archived count * style(storage): stack age threshold and grace period vertically with updated grace period description * fix(storage): only log auto-archive info messages when candidate assets are found to process
This commit is contained in:
@@ -244,7 +244,23 @@ describe('team api', () => {
|
||||
permission: Permission.Read,
|
||||
}),
|
||||
)
|
||||
expect(mockGetSettings).toHaveBeenCalledWith('t1')
|
||||
expect(mockGetSettings).toHaveBeenCalledWith('t1', { isAdmin: true })
|
||||
})
|
||||
|
||||
it('GET /teams/:teamId/settings passes isAdmin: false when user lacks admin permission', async () => {
|
||||
vi.mocked(authzService.hasPermission).mockImplementation(async (params) => {
|
||||
if (params.permission === Permission.Admin) {
|
||||
throw new Error('Forbidden')
|
||||
}
|
||||
})
|
||||
mockGetSettings.mockResolvedValue({
|
||||
archiveStorage: { enabled: true },
|
||||
})
|
||||
|
||||
const res = await app.request('/teams/t1/settings')
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
expect(mockGetSettings).toHaveBeenCalledWith('t1', { isAdmin: false })
|
||||
})
|
||||
|
||||
it('GET /teams/:teamId/settings does not return emailNotification to readers', async () => {
|
||||
@@ -381,6 +397,65 @@ describe('team api', () => {
|
||||
expect(mockUpdateSettings).toHaveBeenCalledWith('t1', 'appearance.hideAgent', true)
|
||||
})
|
||||
|
||||
it('PATCH /teams/:teamId/settings updates autoArchive settings object', async () => {
|
||||
mockUpdateSettings.mockResolvedValue({
|
||||
autoArchive: {
|
||||
enabled: true,
|
||||
method: 'not_updated',
|
||||
days: 30,
|
||||
postRestoreGraceDays: 30,
|
||||
},
|
||||
})
|
||||
|
||||
const res = await app.request('/teams/t1/settings', {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
key: 'autoArchive',
|
||||
value: {
|
||||
enabled: true,
|
||||
method: 'not_updated',
|
||||
days: 30,
|
||||
postRestoreGraceDays: 30,
|
||||
},
|
||||
}),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
const data = await res.json()
|
||||
expect(data.autoArchive.enabled).toBe(true)
|
||||
expect(data.autoArchive.days).toBe(30)
|
||||
expect(mockUpdateSettings).toHaveBeenCalledWith('t1', 'autoArchive', {
|
||||
enabled: true,
|
||||
method: 'not_updated',
|
||||
days: 30,
|
||||
postRestoreGraceDays: 30,
|
||||
})
|
||||
})
|
||||
|
||||
it('PATCH /teams/:teamId/settings updates autoArchive.enabled individual field', async () => {
|
||||
mockUpdateSettings.mockResolvedValue({
|
||||
autoArchive: {
|
||||
enabled: false,
|
||||
method: 'not_updated',
|
||||
days: 30,
|
||||
postRestoreGraceDays: 30,
|
||||
},
|
||||
})
|
||||
|
||||
const res = await app.request('/teams/t1/settings', {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
key: 'autoArchive.enabled',
|
||||
value: false,
|
||||
}),
|
||||
})
|
||||
|
||||
expect(res.status).toBe(200)
|
||||
expect(mockUpdateSettings).toHaveBeenCalledWith('t1', 'autoArchive.enabled', false)
|
||||
})
|
||||
|
||||
it('GET /teams/:teamId/user-metadata returns all metadata for the user in the team', async () => {
|
||||
mockListUserMetadata.mockResolvedValue([
|
||||
{ key: 'key1', value: 'value1' },
|
||||
|
||||
@@ -210,7 +210,17 @@ const route = new Hono<{ Variables: { user: User } }>()
|
||||
id: teamId,
|
||||
})
|
||||
|
||||
const settings = await teamService.getSettings(teamId)
|
||||
const isAdmin = await authzService
|
||||
.hasPermission({
|
||||
user,
|
||||
permission: Permission.Admin,
|
||||
type: ResourceType.Team,
|
||||
id: teamId,
|
||||
})
|
||||
.then(() => true)
|
||||
.catch(() => false)
|
||||
|
||||
const settings = await teamService.getSettings(teamId, { isAdmin })
|
||||
return c.json(settings)
|
||||
})
|
||||
.patch(
|
||||
|
||||
Reference in New Issue
Block a user