class KeyAccessCheck in Translation Management Tool 8
Checks access for TMGMT job item.
Hierarchy
- class \Drupal\tmgmt_content\Access\KeyAccessCheck implements AccessInterface
Expanded class hierarchy of KeyAccessCheck
1 string reference to 'KeyAccessCheck'
- tmgmt_content.services.yml in sources/
content/ tmgmt_content.services.yml - sources/content/tmgmt_content.services.yml
1 service uses KeyAccessCheck
File
- sources/
content/ src/ Access/ KeyAccessCheck.php, line 15
Namespace
Drupal\tmgmt_content\AccessView source
class KeyAccessCheck implements RoutingAccessInterface {
/**
* Checks access for TMGMT job item.
*
* Checks access for TMGMT job item by comparing the hashed key from job item
* data and key from the request.
*
* @param \Symfony\Component\HttpFoundation\Request $request
* The incoming request.
* @param \Drupal\tmgmt\JobItemInterface $tmgmt_job_item
* Job item.
*
* @return AccessResult
* Returns TRUE if right key is in the request.
*/
public function access(Request $request, JobItemInterface $tmgmt_job_item) {
$key_from_request = $request->query
->get('key');
$result = AccessResult::forbidden();
if ($key_from_request) {
if ($key_from_request === $this
->getKey($tmgmt_job_item) && $tmgmt_job_item
->getJob()
->isActive() && !($tmgmt_job_item
->isAborted() || $tmgmt_job_item
->isAccepted())) {
$result = AccessResult::allowed();
}
}
return $result
->setCacheMaxAge(0);
}
/**
* Generates a key from job item data that can be used in the URL.
*
* @param \Drupal\tmgmt\JobItemInterface $tmgmt_job_item
* Job item.
*
* @return string
* Returns hashed key that is safe to use in the URL.
*/
public function getKey(JobItemInterface $tmgmt_job_item) {
return Crypt::hmacBase64($tmgmt_job_item
->id(), Settings::getHashSalt());
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
KeyAccessCheck:: |
public | function | Checks access for TMGMT job item. | |
KeyAccessCheck:: |
public | function | Generates a key from job item data that can be used in the URL. |