Skip to content

Commit

Permalink
Update to api function for MessageID
Browse files Browse the repository at this point in the history
Update to api function for MessageIDs - PaswordChangeRequired

This patch is just a small tweak while still assuming the current
X.Y.Z version format.
When searching for a standard Registry string from @Message.ExtendedInfo
-which is an array of Message objects-,
we should stick to the default namespace.
For example,
if someone added OpenBMC.0.5.0.PaswordChangeRequired it could be
erroneous to assume that it has the same meaning, since
semantically it is a different message.
For our use, trying to do something useful with version portion
seems problematic, so I am fine with ignoring them as already done
with code being updated here.

The search function has been made generic to allow reuse,
and some IntelliSense sugar was added.

Tested, as Paul documented:
Tested: logging in, navigating, logging out with non-expired password.
Logging in, navigating, then running `passwd -e <accountname>` via ssh
leads to functional password change page on the next request and then
navigating proceeds normally, and logging out too. If password is
expired before logging in the user gets redirected to the password
change page automatically after logging in.

Change-Id: I306ace2024efea13f25e24528a048d0955b2f95b
Signed-off-by: j-westover <[email protected]>
  • Loading branch information
j-westover committed Dec 4, 2024
1 parent b449867 commit c156729
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/store/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,28 @@ export const getResponseCount = (responses) => {
};

export const isPasswordExpired = (data) => {
return !!findMessageId(data, 'PasswordChangeRequired');
};

/**
* Returns the first ExtendedInfo.Message to start with the
* Registry Name (Default: "Base") and end with the given key
* Ignore versions (.<X>.<Y>) --or-- (.<X>.<Y>.<Z>.),
* but adhere to Registry namespace
* @param {object} data - AxiosResponse.data
* @param { {MessageKey: string}} key - key into the message registry
* @param { {MessageRegistryPrefix: string}} [registry=Base] - the name of the
* message registry, undefined param defaults to "Base"
* @returns {ExtendedInfo.Message} ExtendedInfo.Message | undefined
*/
export const findMessageId = (data, key, registry = 'Base') => {
let extInfoMsgs = data?.['@Message.ExtendedInfo'];

return (
extInfoMsgs &&
extInfoMsgs.find(
(i) => i.MessageId.split('.')[4] === 'PasswordChangeRequired',
)
extInfoMsgs.find((i) => {
const words = i.MessageId.split('.');
return words[words.length - 1] === key && words[0] === registry;
})
);
};

0 comments on commit c156729

Please sign in to comment.