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

Remove the User.isActive flag #14871

Merged
merged 2 commits into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
37 changes: 0 additions & 37 deletions services/app-api/handlers/users/post/activateDeactivateUser.js

This file was deleted.

1 change: 0 additions & 1 deletion services/app-api/handlers/users/post/createUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ const createUser = async (userData) => {
email: userData.email,
firstName: userData.firstName,
lastName: userData.lastName,
isActive: "true",
isSuperUser: "true",
role: userData.role,
states: [],
Expand Down
4 changes: 1 addition & 3 deletions services/app-api/handlers/users/post/updateUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,11 @@ export const main = handler(async (event, context) => {
userId: currentUser["Items"][0].userId,
},
UpdateExpression:
"SET username = :username, #r = :role, states = :states, isActive = :isActive, lastLogin = :lastLogin, usernameSub = :usernameSub",
"SET username = :username, #r = :role, states = :states, lastLogin = :lastLogin, usernameSub = :usernameSub",
ExpressionAttributeValues: {
":username": data.username,
":role": data.role,
":states": data.states ?? "",
":isActive": data.isActive ?? "inactive",
":lastLogin": new Date().toISOString(),
":usernameSub": data.usernameSub ?? null,
},
Expand All @@ -50,7 +49,6 @@ export const main = handler(async (event, context) => {
function modifyingAnythingButAnEmptyStateList(incomingUser, existingUser) {
if (incomingUser.username !== existingUser.username) return true;
if (incomingUser.role !== existingUser.role) return true;
if (incomingUser.isActive !== existingUser.isActive) return true;
if (incomingUser.usernameSub !== existingUser.usernameSub) return true;
if (existingUser.states.length > 0) return true;
return false;
Expand Down
9 changes: 0 additions & 9 deletions services/app-api/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -396,15 +396,6 @@ functions:
deleteUser:
handler: handlers/users/post/deleteUser.main
role: LambdaApiRole
activateDeactivateUser:
handler: handlers/users/post/activateDeactivateUser.main
role: LambdaApiRole
events:
- http:
path: users/activation/{username}
method: post
cors: true
authorizer: ${self:custom.authValue.${self:custom.stage}, ""}
updateUser:
handler: handlers/users/post/updateUser.main
role: LambdaApiRole
Expand Down
5 changes: 4 additions & 1 deletion services/database/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
"aws-dynamodb-local": "0.0.10",
"serverless-dynamodb": "^0.2.53"
},
"dependencies": {}
"dependencies": {
"@aws-sdk/client-dynamodb": "^3.565.0",
"@aws-sdk/lib-dynamodb": "^3.565.0"
}
}
69 changes: 69 additions & 0 deletions services/database/scripts/removeActiveFlagFromUserObject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
const { DynamoDBClient } = require("@aws-sdk/client-dynamodb");
const {
DynamoDBDocumentClient,
paginateScan,
PutCommand,
} = require("@aws-sdk/lib-dynamodb");

/*
* ENVIRONMENT VARIABLES TO SET:
* AUTH_USER_TABLE_NAME: the name of the table in Dynamo
* DYNAMODB_URL: the local URL if local; undefined otherwise
* [anything needed for AWS auth, if not local]
*/
const {
AUTH_USER_TABLE_NAME,
DYNAMODB_URL,
} = process.env;

const logger = {
debug: () => {},
info: console.info,
warn: console.warn,
error: console.error,
};

const localConfig = {
endpoint: DYNAMODB_URL,
region: "localhost",
credentials: {
accessKeyId: "LOCALFAKEKEY", // pragma: allowlist secret
secretAccessKey: "LOCALFAKESECRET", // pragma: allowlist secret
},
logger,
};

const awsConfig = {
region: "us-east-1",
logger,
};

const getConfig = () => {
return DYNAMODB_URL ? localConfig : awsConfig;
};

const client = DynamoDBDocumentClient.from(new DynamoDBClient(getConfig()));

(async function () {
let scannedCount = 0;
let updatedCount = 0;
console.log("Scanning...");
for await (let page of paginateScan({ client }, { TableName: AUTH_USER_TABLE_NAME })) {
if (!page.Items) continue;
for (let user of page.Items) {
scannedCount += 1;
if (!("isActive" in user)) continue;

delete user.isActive;
await client.send(new PutCommand({
TableName: AUTH_USER_TABLE_NAME,
Item: user,
}));

updatedCount += 1;
}
}
console.log(`Scanned ${scannedCount} total users`);
console.log(`Found ${updatedCount} users in need of update`);
console.log("All updates successful");
})();
Loading
Loading