Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add a policy property to takedown events #3271

Merged
merged 5 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
✨ Add policy list setting validation
  • Loading branch information
foysalit committed Dec 20, 2024
commit a78184177a08c19d527e978a05a63911a9f14291
1 change: 1 addition & 0 deletions packages/ozone/src/setting/constants.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export const ProtectedTagSettingKey = 'tools.ozone.setting.protectedTags'
export const PolicyListSettingKey = 'tools.ozone.setting.policyList'
29 changes: 28 additions & 1 deletion packages/ozone/src/setting/validators.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Selectable } from 'kysely'
import { Setting } from '../db/schema/setting'
import { ProtectedTagSettingKey } from './constants'
import { PolicyListSettingKey, ProtectedTagSettingKey } from './constants'
import { InvalidRequestError } from '@atproto/xrpc-server'

export const settingValidators = new Map<
Expand Down Expand Up @@ -58,4 +58,31 @@ export const settingValidators = new Map<
}
},
],
[
PolicyListSettingKey,
async (setting: Partial<Selectable<Setting>>) => {
if (setting.managerRole !== 'tools.ozone.team.defs#roleAdmin') {
throw new InvalidRequestError(
'Only admins should be able to manage policy list',
)
}

if (typeof setting.value !== 'object') {
throw new InvalidRequestError('Invalid value')
}
for (const [key, val] of Object.entries(setting.value)) {
if (!val || typeof val !== 'object') {
throw new InvalidRequestError(
`Invalid configuration for policy ${key}`,
)
}

if (!val['name'] || !val['description']) {
throw new InvalidRequestError(
`Must define a name and description for policy ${key}`,
)
}
}
},
],
])
Loading