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

Improved: facility display logic on Admin/Super user details page(#173) #271

Merged
merged 11 commits into from
Sep 18, 2024
Merged
1 change: 1 addition & 0 deletions src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@
"The timezone you select is used to ensure automations you schedule are always accurate to the time you select.": "The timezone you select is used to ensure automations you schedule are always accurate to the time you select.",
"This is the name of the OMS you are connected to right now. Make sure that you are connected to the right instance before proceeding.": "This is the name of the OMS you are connected to right now. Make sure that you are connected to the right instance before proceeding.",
"This user was disabled due to repeated failed password attempts": "This user was disabled due to repeated failed password attempts",
"This user has 'STOREFULFILLMENT_ADMIN' permission, enabling access to all facilities.": "This user has 'STOREFULFILLMENT_ADMIN' permission, enabling access to all facilities.",
"Unblock user login": "Unblock user login",
"Unblocking a user will allow them to login to the OMS again with their credentials.": "Unblocking a user will allow them to login to the OMS again with their credentials.",
"Update product store role": "Update product store role",
Expand Down
29 changes: 29 additions & 0 deletions src/services/UserService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,34 @@ const getUserSecurityGroup = async (userLoginId: string): Promise<any> => {

return userSecurityGroup
}
const isUserFulfillmentAdmin = async (userLoginId: string): Promise<any> => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The name of the service suggest that boolean value will be returned, but you are returning data. Either return boolean or change the name of the service.

const payload = {
inputFields: {
userLoginId,
permissionId: ['STOREFULFILLMENT_ADMIN']
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why we are passing list in permissionId here?

},
entityName: "UserLoginSecurityGroupAndPermission",
filterByDate: "Y",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we will get expired permission in this case. As the UserLoginSecurityGroupAndPermission view has dates for managing UserLogin and Security Group association (fromDate, thruDate) as well as dates for managing SecurityGroup and SecurityGroupPermission associations (SGPFromDate, SGPThruDate). The filterByDate parameter in performFind service by default consider fromDate and thruDate for filtering active records.

We need checks on both the dates which is not possible in performFind. You should use the getPermission api here which is used during login to fetch the user's permission.

viewSize: 10,
};

try {
const resp: any = await api({
url: "performFind",
method: "POST",
data: payload,
});

if (!hasError(resp)) {
return resp.data.docs;
} else {
throw resp.data;
}
} catch (error) {
logger.error(error);
return [];
}
};

const removeUserSecurityGroup = async (payload: any): Promise <any> => {
return api({
Expand Down Expand Up @@ -787,6 +815,7 @@ export const UserService = {
getUserFacilities,
getUserProductStores,
getUserSecurityGroup,
isUserFulfillmentAdmin,
isUserLoginIdAlreadyExists,
isRoleTypeExists,
login,
Expand Down
10 changes: 7 additions & 3 deletions src/views/UserDetails.vue
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,11 @@
{{ translate("Show as picker") }}
</ion-toggle>
</ion-item>
<ion-item lines="none" button detail :disabled="!hasPermission(Actions.APP_UPDT_FULFILLMENT_FACILITY) || selectedUser.securityGroup.groupId === 'INTEGRATION'" @click="selectFacility()">
<ion-label>{{ getUserFacilities().length === 1 ? translate('Added to 1 facility') : translate('Added to facilities', { count: getUserFacilities().length }) }}</ion-label>
<ion-item lines="none" v-if="isUserFulfillmentAdmin.length">
<ion-label>{{ translate("This user has 'STOREFULFILLMENT_ADMIN' permission, enabling access to all facilities.") }}</ion-label>
</ion-item>
<ion-item lines="none" button detail v-else @click="selectFacility()" :disabled="selectedUser.securityGroup.groupId === 'INTEGRATION'">
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the Actions.APP_UPDT_FULFILLMENT_FACILITY permission is removed?

<ion-label>{{ getUserFacilities().length === 1 ? translate('Added to 1 facility') : translate('Added to facilities', { count: getUserFacilities().length }) }}</ion-label>
</ion-item>
</ion-list>
</ion-card>
Expand Down Expand Up @@ -520,6 +523,7 @@ export default defineComponent({
isUserFetched: false,
showPassword: false,
shopifyShopsForProductStore: [] as any,
isUserFulfillmentAdmin: []
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isUserFulfillmentAdmin should be boolean.

}
},

Expand All @@ -533,7 +537,7 @@ export default defineComponent({
if (productStoreId) {
this.getShopifyShops(productStoreId);
}

this.isUserFulfillmentAdmin = await UserService.isUserFulfillmentAdmin(this.selectedUser.userLoginId)
this.isUserFetched = true
this.username = this.selectedUser.groupName ? (this.selectedUser.groupName)?.toLowerCase() : (`${this.selectedUser.firstName}.${this.selectedUser.lastName}`?.toLowerCase())
},
Expand Down
Loading