Skip to content

Commit

Permalink
Merge pull request #3583 from uselagoon/purge-group-cache-when-deleted
Browse files Browse the repository at this point in the history
fix: purge the cached id of the group when group is deleted
  • Loading branch information
tobybellwood authored Nov 2, 2023
2 parents d7d382c + bf88f3a commit f427908
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion services/api/src/clients/redisClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export const get = promisify(redisClient.get).bind(redisClient);
const hgetall = promisify(redisClient.hgetall).bind(redisClient);
const smembers = promisify(redisClient.smembers).bind(redisClient);
const sadd = promisify(redisClient.sadd).bind(redisClient);
const del = promisify(redisClient.del).bind(redisClient);
export const del = promisify(redisClient.del).bind(redisClient);

interface IUserResourceScope {
resource: string;
Expand Down
7 changes: 6 additions & 1 deletion services/api/src/models/group.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { logger } from '../loggers/logger';
// @ts-ignore
import GroupRepresentation from 'keycloak-admin/lib/defs/groupRepresentation';
import { User } from './user';
import { saveRedisKeycloakCache, get, redisClient } from '../clients/redisClient';
import { saveRedisKeycloakCache, get, del, redisClient } from '../clients/redisClient';
import { Helpers as projectHelpers } from '../resources/project/helpers';
import { sqlClientPool } from '../clients/sqlClient';
import { log } from 'winston';
Expand Down Expand Up @@ -627,6 +627,11 @@ export const Group = (clients: {

const deleteGroup = async (id: string): Promise<void> => {
try {
const keycloakGroup = await keycloakAdminClient.groups.findOne({
id,
briefRepresentation: false,
});
await del(`cache:keycloak:group-id:${keycloakGroup.name}`);
await keycloakAdminClient.groups.del({ id });
} catch (err) {
if (err.response.status && err.response.status === 404) {
Expand Down

0 comments on commit f427908

Please sign in to comment.