Source of file UserRoleExtension.php
Size: 2,473 Bytes - Last Modified: 2021-12-23T10:08:54+00:00
/var/www/docs.ssmods.com/process/src/src/Extensions/UserRoleExtension.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 | <?php /** * This file contains the "UserRoleExtension" class. * * @category SilverStripe_Project * @package SDLT * @author Catalyst I.T. SilverStripe Team 2018 <silverstripedev@catalyst.net.nz> * @copyright NZ Transport Agency * @license BSD-3 * @link https://www.catalyst.net.nz */ namespace NZTA\SDLT\Extension; use NZTA\SDLT\Constant\UserGroupConstant; use SilverStripe\ORM\DataExtension; use NZTA\SDLT\Extension\GroupExtension; /** * Class UserRoleExtension */ class UserRoleExtension extends DataExtension { /** * Check if the member is a Security Architect * * @return boolean */ public function getIsSA() { // SA and CISO can view it return $this->owner ->Groups() ->filter('Code', GroupExtension::security_architect_group()->Code) ->exists(); } /** * Check if the member is a Chief Information Security Officer * * @return boolean */ public function getIsCISO() { return $this->owner ->Groups() ->filter('Code', GroupExtension::ciso_group()->Code) ->exists(); } /** * Check if the member is a Reporter. * * @return boolean */ public function getIsReporter() { return $this->owner ->Groups() ->filter('Code', UserGroupConstant::GROUP_CODE_REPORTER) ->exists(); } /** * Check if the member is a SilverStripe administrator * * @return boolean */ public function getIsAdmin() { return $this->owner ->Groups() ->filter('Code', UserGroupConstant::GROUP_CODE_ADMIN) ->exists(); } /** * Return the role-name for a given user. The returned string is in compound * form, but you can use {@link FormField::name_to_label()} to prettify it. * * @return string */ public function getRoleName() : string { switch ($this->getOwner()) { case $this->getIsSA(): return UserGroupConstant::ROLE_CODE_SA; case $this->getIsCISO(): return UserGroupConstant::ROLE_CODE_CISO; case $this->getIsReporter(): return UserGroupConstant::ROLE_CODE_REPORTER; case $this->getIsAdmin(): return UserGroupConstant::ROLE_CODE_ADMIN; default: return ''; } } } |