Skip to content

Commit

Permalink
✨ Replace ad-hoc manage roles to match team member roles
Browse files Browse the repository at this point in the history
  • Loading branch information
foysalit committed Oct 23, 2024
1 parent 684c59c commit 3773e0e
Show file tree
Hide file tree
Showing 25 changed files with 305 additions and 194 deletions.
7 changes: 5 additions & 2 deletions lexicons/tools/ozone/setting/defs.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
"key",
"value",
"did",
"managerRole",
"scope",
"createdBy",
"lastUpdatedBy"
Expand Down Expand Up @@ -40,7 +39,11 @@
},
"managerRole": {
"type": "string",
"knownValues": ["owner", "moderator", "triage", "admin"]
"knownValues": [
"tools.ozone.team.defs#roleModerator",
"tools.ozone.team.defs#roleTriage",
"tools.ozone.team.defs#roleAdmin"
]
},
"scope": {
"type": "string",
Expand Down
8 changes: 8 additions & 0 deletions lexicons/tools/ozone/setting/listOptions.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,14 @@
"prefix": {
"type": "string",
"description": "Filter keys by prefix"
},
"keys": {
"type": "array",
"items": {
"type": "string",
"format": "nsid"
},
"description": "Filter for only the specified keys. Ignored if prefix is provided"
}
}
},
Expand Down
8 changes: 6 additions & 2 deletions lexicons/tools/ozone/setting/upsertOption.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"encoding": "application/json",
"schema": {
"type": "object",
"required": ["key", "scope", "value", "managerRole"],
"required": ["key", "scope", "value"],
"properties": {
"key": {
"type": "string",
Expand All @@ -29,7 +29,11 @@
"managerRole": {
"type": "string",
"default": "owner",
"knownValues": ["owner", "moderator", "triage", "admin"]
"knownValues": [
"tools.ozone.team.defs#roleModerator",
"tools.ozone.team.defs#roleTriage",
"tools.ozone.team.defs#roleAdmin"
]
}
}
}
Expand Down
28 changes: 14 additions & 14 deletions packages/api/src/client/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -214,8 +214,8 @@ import * as ToolsOzoneSetGetValues from './types/tools/ozone/set/getValues'
import * as ToolsOzoneSetQuerySets from './types/tools/ozone/set/querySets'
import * as ToolsOzoneSetUpsertSet from './types/tools/ozone/set/upsertSet'
import * as ToolsOzoneSettingDefs from './types/tools/ozone/setting/defs'
import * as ToolsOzoneSettingRemoveOptions from './types/tools/ozone/setting/removeOptions'
import * as ToolsOzoneSettingListOptions from './types/tools/ozone/setting/listOptions'
import * as ToolsOzoneSettingRemoveOptions from './types/tools/ozone/setting/removeOptions'
import * as ToolsOzoneSettingUpsertOption from './types/tools/ozone/setting/upsertOption'
import * as ToolsOzoneSignatureDefs from './types/tools/ozone/signature/defs'
import * as ToolsOzoneSignatureFindCorrelation from './types/tools/ozone/signature/findCorrelation'
Expand Down Expand Up @@ -437,8 +437,8 @@ export * as ToolsOzoneSetGetValues from './types/tools/ozone/set/getValues'
export * as ToolsOzoneSetQuerySets from './types/tools/ozone/set/querySets'
export * as ToolsOzoneSetUpsertSet from './types/tools/ozone/set/upsertSet'
export * as ToolsOzoneSettingDefs from './types/tools/ozone/setting/defs'
export * as ToolsOzoneSettingRemoveOptions from './types/tools/ozone/setting/removeOptions'
export * as ToolsOzoneSettingListOptions from './types/tools/ozone/setting/listOptions'
export * as ToolsOzoneSettingRemoveOptions from './types/tools/ozone/setting/removeOptions'
export * as ToolsOzoneSettingUpsertOption from './types/tools/ozone/setting/upsertOption'
export * as ToolsOzoneSignatureDefs from './types/tools/ozone/signature/defs'
export * as ToolsOzoneSignatureFindCorrelation from './types/tools/ozone/signature/findCorrelation'
Expand Down Expand Up @@ -3704,18 +3704,6 @@ export class ToolsOzoneSettingNS {
this._client = client
}

removeOptions(
data?: ToolsOzoneSettingRemoveOptions.InputSchema,
opts?: ToolsOzoneSettingRemoveOptions.CallOptions,
): Promise<ToolsOzoneSettingRemoveOptions.Response> {
return this._client.call(
'tools.ozone.setting.removeOptions',
opts?.qp,
data,
opts,
)
}

listOptions(
params?: ToolsOzoneSettingListOptions.QueryParams,
opts?: ToolsOzoneSettingListOptions.CallOptions,
Expand All @@ -3728,6 +3716,18 @@ export class ToolsOzoneSettingNS {
)
}

removeOptions(
data?: ToolsOzoneSettingRemoveOptions.InputSchema,
opts?: ToolsOzoneSettingRemoveOptions.CallOptions,
): Promise<ToolsOzoneSettingRemoveOptions.Response> {
return this._client.call(
'tools.ozone.setting.removeOptions',
opts?.qp,
data,
opts,
)
}

upsertOption(
data?: ToolsOzoneSettingUpsertOption.InputSchema,
opts?: ToolsOzoneSettingUpsertOption.CallOptions,
Expand Down
90 changes: 53 additions & 37 deletions packages/api/src/client/lexicons.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12443,7 +12443,6 @@ export const schemaDict = {
'key',
'value',
'did',
'managerRole',
'scope',
'createdBy',
'lastUpdatedBy',
Expand Down Expand Up @@ -12475,7 +12474,11 @@ export const schemaDict = {
},
managerRole: {
type: 'string',
knownValues: ['owner', 'moderator', 'triage', 'admin'],
knownValues: [
'tools.ozone.team.defs#roleModerator',
'tools.ozone.team.defs#roleTriage',
'tools.ozone.team.defs#roleAdmin',
],
},
scope: {
type: 'string',
Expand All @@ -12493,38 +12496,6 @@ export const schemaDict = {
},
},
},
ToolsOzoneSettingRemoveOptions: {
lexicon: 1,
id: 'tools.ozone.setting.removeOptions',
defs: {
main: {
type: 'procedure',
description: 'Delete settings by key',
input: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['keys', 'scope'],
properties: {
keys: {
type: 'array',
minLength: 1,
items: {
type: 'string',
format: 'nsid',
},
},
scope: {
type: 'string',
knownValues: ['instance', 'personal'],
default: 'personal',
},
},
},
},
},
},
},
ToolsOzoneSettingListOptions: {
lexicon: 1,
id: 'tools.ozone.setting.listOptions',
Expand Down Expand Up @@ -12553,6 +12524,15 @@ export const schemaDict = {
type: 'string',
description: 'Filter keys by prefix',
},
keys: {
type: 'array',
items: {
type: 'string',
format: 'nsid',
},
description:
'Filter for only the specified keys. Ignored if prefix is provided',
},
},
},
output: {
Expand All @@ -12577,6 +12557,38 @@ export const schemaDict = {
},
},
},
ToolsOzoneSettingRemoveOptions: {
lexicon: 1,
id: 'tools.ozone.setting.removeOptions',
defs: {
main: {
type: 'procedure',
description: 'Delete settings by key',
input: {
encoding: 'application/json',
schema: {
type: 'object',
required: ['keys', 'scope'],
properties: {
keys: {
type: 'array',
minLength: 1,
items: {
type: 'string',
format: 'nsid',
},
},
scope: {
type: 'string',
knownValues: ['instance', 'personal'],
default: 'personal',
},
},
},
},
},
},
},
ToolsOzoneSettingUpsertOption: {
lexicon: 1,
id: 'tools.ozone.setting.upsertOption',
Expand All @@ -12588,7 +12600,7 @@ export const schemaDict = {
encoding: 'application/json',
schema: {
type: 'object',
required: ['key', 'scope', 'value', 'managerRole'],
required: ['key', 'scope', 'value'],
properties: {
key: {
type: 'string',
Expand All @@ -12608,7 +12620,11 @@ export const schemaDict = {
managerRole: {
type: 'string',
default: 'owner',
knownValues: ['owner', 'moderator', 'triage', 'admin'],
knownValues: [
'tools.ozone.team.defs#roleModerator',
'tools.ozone.team.defs#roleTriage',
'tools.ozone.team.defs#roleAdmin',
],
},
},
},
Expand Down Expand Up @@ -13262,8 +13278,8 @@ export const ids = {
ToolsOzoneSetQuerySets: 'tools.ozone.set.querySets',
ToolsOzoneSetUpsertSet: 'tools.ozone.set.upsertSet',
ToolsOzoneSettingDefs: 'tools.ozone.setting.defs',
ToolsOzoneSettingRemoveOptions: 'tools.ozone.setting.removeOptions',
ToolsOzoneSettingListOptions: 'tools.ozone.setting.listOptions',
ToolsOzoneSettingRemoveOptions: 'tools.ozone.setting.removeOptions',
ToolsOzoneSettingUpsertOption: 'tools.ozone.setting.upsertOption',
ToolsOzoneSignatureDefs: 'tools.ozone.signature.defs',
ToolsOzoneSignatureFindCorrelation: 'tools.ozone.signature.findCorrelation',
Expand Down
6 changes: 5 additions & 1 deletion packages/api/src/client/types/tools/ozone/setting/defs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ export interface Option {
description?: string
createdAt?: string
updatedAt?: string
managerRole: 'owner' | 'moderator' | 'triage' | 'admin' | (string & {})
managerRole?:
| 'tools.ozone.team.defs#roleModerator'
| 'tools.ozone.team.defs#roleTriage'
| 'tools.ozone.team.defs#roleAdmin'
| (string & {})
scope: 'instance' | 'personal' | (string & {})
createdBy: string
lastUpdatedBy: string
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export interface QueryParams {
scope?: 'instance' | 'personal' | (string & {})
/** Filter keys by prefix */
prefix?: string
/** Filter for only the specified keys. Ignored if prefix is provided */
keys?: string[]
}

export type InputSchema = undefined
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ export interface InputSchema {
scope: 'instance' | 'personal' | (string & {})
value: {}
description?: string
managerRole: 'owner' | 'moderator' | 'triage' | 'admin' | (string & {})
managerRole?:
| 'tools.ozone.team.defs#roleModerator'
| 'tools.ozone.team.defs#roleTriage'
| 'tools.ozone.team.defs#roleAdmin'
| (string & {})
[k: string]: unknown
}

Expand Down
3 changes: 2 additions & 1 deletion packages/ozone/src/api/setting/listOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export default function (server: Server, ctx: AppContext) {
handler: async ({ params, auth }) => {
const access = auth.credentials
const db = ctx.db
const { prefix, scope, limit, cursor } = params
const { prefix, scope, keys, limit, cursor } = params
let did = ctx.cfg.service.did

if (scope === 'personal') {
Expand All @@ -26,6 +26,7 @@ export default function (server: Server, ctx: AppContext) {
const result = await settingService.query({
scope: scope === 'personal' ? 'personal' : 'instance',
did,
keys,
prefix,
limit,
cursor,
Expand Down
17 changes: 12 additions & 5 deletions packages/ozone/src/api/setting/removeOptions.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { AuthRequiredError } from '@atproto/xrpc-server'
import { Server } from '../../lexicon'
import AppContext from '../../context'
import { SettingManagerRole } from '../../db/schema/setting'
import { Member } from '../../db/schema/member'

export default function (server: Server, ctx: AppContext) {
server.tools.ozone.setting.removeOptions({
Expand All @@ -11,7 +11,7 @@ export default function (server: Server, ctx: AppContext) {
const db = ctx.db
const { keys, scope } = input.body
let did = ctx.cfg.service.did
let managerRole: SettingManagerRole[] = ['owner']
let managerRole: Member['role'][] = []

if (scope === 'personal') {
if (access.type !== 'moderator') {
Expand All @@ -28,13 +28,20 @@ export default function (server: Server, ctx: AppContext) {
// moderators can remove settings that are manageable by moderator and triage roles
// triage can remove settings that are manageable by triage role
if (scope === 'instance') {
managerRole = ['admin', 'moderator', 'triage']
managerRole = [
'tools.ozone.team.defs#roleModerator',
'tools.ozone.team.defs#roleTriage',
'tools.ozone.team.defs#roleAdmin',
]

if (access.type !== 'admin_token' && !access.isAdmin) {
if (access.isModerator) {
managerRole = ['moderator', 'triage']
managerRole = [
'tools.ozone.team.defs#roleModerator',
'tools.ozone.team.defs#roleTriage',
]
} else if (access.isTriage) {
managerRole = ['triage']
managerRole = ['tools.ozone.team.defs#roleTriage']
}
}
}
Expand Down
Loading

0 comments on commit 3773e0e

Please sign in to comment.