<?php
namespace Harmonizely\Service\Subscription\Voter;
use Harmonizely\Model\UserInterface;
use Harmonizely\Service\Panel\AccessVoters\AbstractVoter;
class SubscriptionVoter extends AbstractVoter
{
const RESOURCE_NAME = 'subscription';
const CUSTOM_DOMAIN = 'custom_domain';
const CHANGE_TEMPLATE = 'change_template';
const WHITE_LABEL = 'white_label';
const ORGANIZATION = 'organization';
const SMS = 'sms';
const SMTP = 'smtp';
const FLEXIBLE_DURATION = 'flexible_duration';
const SBPAY_PRO = 'sbpay_pro';
const MULTIPLE_MEETING = 'multiple_meeting';
const MULTIPLE_EMAIL = 'multiple_email';
const EVENT_TYPE_TAG = 'event_type_tag';
const API = 'api';
const USER_RELATION = 'user_relation';
const ROUTING_FORM = 'routing_form';
/**
* @return string
*/
function getResourceName(): string
{
return self::RESOURCE_NAME;
}
/**
* @return string[]
*/
function getResourceAttributes(): array
{
return [
self::CUSTOM_DOMAIN,
self::WHITE_LABEL,
self::CHANGE_TEMPLATE,
self::ORGANIZATION,
self::SMS,
self::SMTP,
self::FLEXIBLE_DURATION,
self::SBPAY_PRO,
self::MULTIPLE_MEETING,
self::MULTIPLE_EMAIL,
self::EVENT_TYPE_TAG,
self::API,
self::USER_RELATION,
self::ROUTING_FORM
];
}
/**
* @param UserInterface $user
* @param $subject
* @return array|string[]
*/
function getAllowedAttributes(UserInterface $user, $subject): array
{
if ($user->hasPaidSubscription()) {
return $this->getResourceAttributes();
}
return [
self::API
];
}
/**
* @param string $attribute
* @param mixed $subject
* @return bool
*/
protected function supports($attribute, $subject): bool
{
if (!in_array($attribute, $this->getResourceAttributes())) {
return false;
}
return true;
}
/**
* @param string $attribute
* @param UserInterface $user
* @return bool
*/
public static function staticVoteOnAttribute(string $attribute, UserInterface $user): bool
{
$instance = new self();
if (!in_array($attribute, $instance->getResourceAttributes())) {
return false;
}
return in_array($attribute, $instance->getAllowedAttributes($user, null));
}
}