Skip to content

Commit

Permalink
✨ Re: #165 - Implements granular user controlls
Browse files Browse the repository at this point in the history
  • Loading branch information
Lissy93 committed Aug 20, 2021
1 parent b71e154 commit 8df8425
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions src/components/LinkItems/ItemGroup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
:rows="displayData.rows"
:color="displayData.color"
:customStyles="displayData.customStyles"
v-if="isSectionVisibleToUser()"
>
<div v-if="!items || items.length < 1" class="no-items">
No Items to Show Yet
Expand Down Expand Up @@ -51,6 +52,7 @@
import Item from '@/components/LinkItems/Item.vue';
import Collapsable from '@/components/LinkItems/Collapsable.vue';
import IframeModal from '@/components/LinkItems/IframeModal.vue';
import { getCurrentUser, isLoggedInAsGuest } from '@/utils/Auth';
export default {
name: 'ItemGroup',
Expand Down Expand Up @@ -85,6 +87,9 @@ export default {
? `grid-template-rows: repeat(${this.displayData.itemCountY}, 1fr);` : '';
return styles;
},
currentUser() {
return getCurrentUser();
},
},
methods: {
/* Returns a unique lowercase string, based on name, for section ID */
Expand All @@ -95,9 +100,11 @@ export default {
triggerModal(url) {
this.$refs[`iframeModal-${this.groupId}`].show(url);
},
/* Emmit value upwards when iframe modal opened/ closed */
modalChanged(changedTo) {
this.$emit('change-modal-visibility', changedTo);
},
/* Determines if user has enabled online status checks */
shouldEnableStatusCheck(itemPreference) {
const globalPreference = this.config.appConfig.statusCheck || false;
return itemPreference !== undefined ? itemPreference : globalPreference;
Expand All @@ -109,6 +116,35 @@ export default {
if (interval < 1) interval = 0;
return interval;
},
/* Returns false if this section should not be rendered for the current user/ guest */
isSectionVisibleToUser() {
const determineVisibility = (visibilityList, currentUser) => {
let isFound = false;
visibilityList.forEach((userInList) => {
if (userInList.toLowerCase() === currentUser) isFound = true;
});
return isFound;
};
const checkVisiblity = () => {
if (!this.currentUser) return true;
const hideFor = this.displayData.hideForUsers || [];
const currentUser = this.currentUser.user.toLowerCase();
return !determineVisibility(hideFor, currentUser);
};
const checkHiddenability = () => {
if (!this.currentUser) return true;
const currentUser = this.currentUser.user.toLowerCase();
const showForUsers = this.displayData.showForUsers || [];
if (showForUsers.length < 1) return true;
return determineVisibility(showForUsers, currentUser);
};
const checkIfHideForGuest = () => {
const hideForGuest = this.displayData.hideForGuests;
const isGuest = isLoggedInAsGuest();
return !(hideForGuest && isGuest);
};
return checkVisiblity() && checkHiddenability() && checkIfHideForGuest();
},
},
};
</script>
Expand Down

0 comments on commit 8df8425

Please sign in to comment.