You are here

public function ShurlyDeactivateForm::access in ShURLy 8

Access check for deactivating a short url.

Parameters

\Drupal\Core\Session\AccountInterface $account:

$rid:

1 string reference to 'ShurlyDeactivateForm::access'
shurly.routing.yml in ./shurly.routing.yml
shurly.routing.yml

File

src/Form/ShurlyDeactivateForm.php, line 21

Class

ShurlyDeactivateForm
ShurlyDeactivateForm.

Namespace

Drupal\shurly\Form

Code

public function access(AccountInterface $account, $rid) {
  if (is_numeric($rid)) {
    $row = \Drupal::database()
      ->query('SELECT uid, source, destination FROM {shurly} WHERE rid = :rid', [
      'rid' => $rid,
    ])
      ->fetchObject();

    // If there's a row, and either the user is an admin, or they've got permission to create and they own this URL, then let them access.
    return AccessResult::allowedIf($account
      ->hasPermission('administer short URLs') || $account
      ->hasPermission('deactivate own URLs') && $row->uid == $account
      ->id());
  }
}