2021-06-30 15:32:10 +02:00
|
|
|
import { User, UserRole } from '../models/user';
|
|
|
|
|
|
|
|
export default class UserLib {
|
|
|
|
private user: User;
|
|
|
|
|
|
|
|
constructor (user: User) {
|
|
|
|
this.user = user;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if the current user has privileged access for resources concerning the provided customer
|
|
|
|
*/
|
|
|
|
isPrivileged = (customer: User): boolean => {
|
|
|
|
if (this.user.role === UserRole.Admin) return true;
|
|
|
|
|
|
|
|
if (this.user.role === UserRole.Manager) {
|
|
|
|
return (this.user.id !== customer.id);
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2022-03-29 17:21:29 +02:00
|
|
|
};
|
2022-04-28 17:31:31 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Filter social networks from the user's profile
|
|
|
|
*/
|
2022-05-02 17:54:58 +02:00
|
|
|
getUserSocialNetworks = (customer: User): {name: string, url: string}[] => {
|
2022-04-28 17:31:31 +02:00
|
|
|
const userNetworks = [];
|
|
|
|
const supportedNetworks = ['facebook', 'twitter', 'viadeo', 'linkedin', 'instagram', 'youtube', 'vimeo', 'dailymotion', 'github', 'echosciences', 'pinterest', 'lastfm', 'flickr'];
|
|
|
|
|
|
|
|
for (const [name, url] of Object.entries(customer.profile)) {
|
|
|
|
supportedNetworks.includes(name) && userNetworks.push({ name, url });
|
|
|
|
}
|
|
|
|
return userNetworks;
|
|
|
|
};
|
2021-06-30 15:32:10 +02:00
|
|
|
}
|