Browse Source

feat: StreamKey revocation

develop
Dale 3 weeks ago
parent
commit
e679b8078f
Signed by: Deiru GPG Key ID: AA250C0277B927E1
5 changed files with 58 additions and 1 deletions
  1. +29
    -0
      graphql.schema.json
  2. +5
    -1
      src/graphql/index.ts
  3. +16
    -0
      src/graphql/mutations/stream-keys/index.ts
  4. +1
    -0
      src/graphql/schema/StreamKeys.graphql
  5. +7
    -0
      src/types/graphql.ts

+ 29
- 0
graphql.schema.json View File

@ -1268,6 +1268,35 @@
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "revokeStreamKey",
"description": null,
"args": [
{
"name": "input",
"description": null,
"type": {
"kind": "INPUT_OBJECT",
"name": "CreateStreamKeyInput",
"ofType": null
},
"defaultValue": null,
"isDeprecated": false,
"deprecationReason": null
}
],
"type": {
"kind": "NON_NULL",
"name": null,
"ofType": {
"kind": "SCALAR",
"name": "Boolean",
"ofType": null
}
},
"isDeprecated": false,
"deprecationReason": null
},
{
"name": "signUp",
"description": null,


+ 5
- 1
src/graphql/index.ts View File

@ -49,7 +49,10 @@ import {
streamKeysQueryResolver,
streamKeysResolver,
} from "./resolvers/stream-keys";
import { createStreamKeyMutation } from "./mutations/stream-keys";
import {
createStreamKeyMutation,
revokeStreamKeyMutation,
} from "./mutations/stream-keys";
const schemaString = glob
.sync(path.resolve(__dirname, "./**/*.graphql"))
@ -93,6 +96,7 @@ const resolvers: Resolvers<ResolverContext> = {
createActivity: createActivityMutaiton,
updateActivity: updateActivityMutation,
createStreamKey: createStreamKeyMutation,
revokeStreamKey: revokeStreamKeyMutation,
},
User: userResolver,
Channel: channelResolver,


+ 16
- 0
src/graphql/mutations/stream-keys/index.ts View File

@ -27,3 +27,19 @@ export const createStreamKeyMutation: MutationResolvers<ResolverContext>["create
}
throw new AuthorizationError();
};
export const revokeStreamKeyMutation: MutationResolvers<ResolverContext>["revokeStreamKey"] =
async (
_,
{ input: { userId, channelId } },
{ user, userRoles, db: { streamKeys } }
) => {
const isWrite = checkRight(userRoles, AccessUnit.Write, "streamKeys");
const isSelf = checkRight(userRoles, AccessUnit.Self, "streamKeys");
if (isWrite || isSelf) {
if (!isWrite && userId !== user.id) {
throw new AuthorizationError();
}
return await streamKeys.deleteStreamKeysByPair(userId, channelId);
}
};

+ 1
- 0
src/graphql/schema/StreamKeys.graphql View File

@ -16,4 +16,5 @@ input CreateStreamKeyInput {
extend type Mutation {
createStreamKey(input: CreateStreamKeyInput): StreamKey!
revokeStreamKey(input: CreateStreamKeyInput): Boolean!
}

+ 7
- 0
src/types/graphql.ts View File

@ -148,6 +148,7 @@ export type Mutation = {
updateRole: Role;
deleteRole: Scalars['Boolean'];
createStreamKey: StreamKey;
revokeStreamKey: Scalars['Boolean'];
signUp: User;
signIn?: Maybe<SessionResponse>;
};
@ -193,6 +194,11 @@ export type MutationCreateStreamKeyArgs = {
};
export type MutationRevokeStreamKeyArgs = {
input?: Maybe<CreateStreamKeyInput>;
};
export type MutationSignUpArgs = {
input: CreateUserInput;
};
@ -569,6 +575,7 @@ export type MutationResolvers<ContextType = any, ParentType extends ResolversPar
updateRole?: Resolver<ResolversTypes['Role'], ParentType, ContextType, RequireFields<MutationUpdateRoleArgs, never>>;
deleteRole?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<MutationDeleteRoleArgs, 'id'>>;
createStreamKey?: Resolver<ResolversTypes['StreamKey'], ParentType, ContextType, RequireFields<MutationCreateStreamKeyArgs, never>>;
revokeStreamKey?: Resolver<ResolversTypes['Boolean'], ParentType, ContextType, RequireFields<MutationRevokeStreamKeyArgs, never>>;
signUp?: Resolver<ResolversTypes['User'], ParentType, ContextType, RequireFields<MutationSignUpArgs, 'input'>>;
signIn?: Resolver<Maybe<ResolversTypes['SessionResponse']>, ParentType, ContextType, RequireFields<MutationSignInArgs, never>>;
};


Loading…
Cancel
Save