Is the user allowed to edit the given label?

@param stdClass $label
@param AccountInterface $account
@return boolean
497257
public function canEditLabel(\stdClass $label, AccountInterface $account = null)
    {
        if ($account === null) {
            global $user;
            $account = $user;
        }

        return ($label->is_locked == 0)
            ? user_access(LabelAccess::PERM_EDIT_NON_LOCKED, $account)
            : user_access(LabelAccess::PERM_EDIT_LOCKED, $account);
    }
682576
public function myTopicAccess(AccountInterface $account) {
    // Fetch user from url.
    $user = $this->requestStack->getCurrentRequest()->get('user');

    // If we don't have a user in the request, assume it's my own profile.
    if (is_null($user)) {
      // Usecase is the user menu, which is generated on all LU pages.
      $user = User::load($account->id());
    }

    // If not a user then just return neutral.
    if (!$user instanceof User) {
      $user = User::load($user);

      if (!$user instanceof User) {
        return AccessResult::neutral();
      }
    }

    // Own profile?
    if ($user->id() === $account->id()) {
      return AccessResult::allowedIfHasPermission($account, 'view topics on my profile');
    }
    return AccessResult::allowedIfHasPermission($account, 'view topics on other profiles');
  }
1204616
public function can_edit(field_controller $field, int $instanceid = 0) : bool {
        if ($instanceid) {
            $context = $this->get_instance_context($instanceid);
            return (!$field->get_configdata_property('locked') ||
                    has_capability('moodle/course:changelockedcustomfields', $context));
        } else {
            $context = $this->get_parent_context();
            return (!$field->get_configdata_property('locked') ||
                guess_if_creator_will_have_course_capability('moodle/course:changelockedcustomfields', $context));
        }
    }
502057
@SuppressWarnings("unchecked")
	public Account getAccByLabel(final String labelAccount) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Account.class);
		criteria.add(Restrictions.eq(Account.PROP_LABEL, labelAccount));
		List<Account> acc = getHibernateTemplate().findByCriteria(criteria); 
		if (acc.size() != 0) { return acc.get(0);
		} else { return null; }
		
	}
1222349
protected function checkAccess(EntityInterface $entity, $operation, AccountInterface $account) {
    switch ($operation) {
    case 'view':
      return AccessResult::allowedIfHasPermission($account, 'access content');

    case 'edit':
      return AccessResult::allowedIfHasPermission($account, 'administer site commerce');

    case 'update':
      return AccessResult::allowedIfHasPermission($account, 'administer site commerce');

    case 'duplicate':
      return AccessResult::allowedIfHasPermission($account, 'administer site commerce');

    case 'delete':
      return AccessResult::allowedIfHasPermission($account, 'administer site commerce');
    }

    return AccessResult::forbidden();
  }
394956
protected function voteOnAttribute($attribute, $subject, TokenInterface $token)
    {
        $allowedRoles = $this->getAllowedRoles(get_class($subject));

        if (count($allowedRoles) > 0) {
            return $this->decisionManager->decide($token, $allowedRoles);
        }

        // default conclusion is access denied
        return false;
    }
711507
public function userCanEditNodeSeo(AccountInterface $account, NodeInterface $node) : bool
    {
        return
            !$this->isNodeBlacklisted($node) && (
                ($account->hasPermission(SeoService::PERM_SEO_CONTENT_OWN) && $node->access('update', $account)) ||
                ($account->hasPermission(SeoService::PERM_SEO_CONTENT_ALL) && $node->access('view', $account))
            )
        ;
    }
393163
public function blockAccess(AccountInterface $account) {
    $current_user = \Drupal::currentUser();
    $route_user_id = \Drupal::routeMatch()->getParameter('user');

    // Show this block only on current user Groups page.
    $can_create_groups = FALSE;
    foreach (GroupType::loadMultiple() as $group_type) {
      $permissions = 'create ' . $group_type->id() . ' group';
      if ($account->hasPermission($permissions)) {
        $can_create_groups = TRUE;
        break;
      }
    }
    if ($current_user->id() == $route_user_id && $can_create_groups) {
      return AccessResult::allowed();
    }

    // By default, the block is not visible.
    return AccessResult::forbidden();
  }
1006050
public function can_edit_post(stdClass $user, discussion_entity $discussion, post_entity $post) : bool {
        global $CFG;

        $context = $this->get_context();
        $ownpost = $post->is_owned_by_user($user);
        $ineditingtime = $post->get_age() < $CFG->maxeditingtime;

        switch ($this->forum->get_type()) {
            case 'news':
                // Allow editing of news posts once the discussion has started.
                $ineditingtime = !$post->has_parent() && $discussion->has_started();
                break;
            case 'single':
                return $discussion->is_first_post($post) && has_capability('moodle/course:manageactivities', $context, $user);
        }

        return ($ownpost && $ineditingtime) || has_capability('mod/forum:editanypost', $context, $user);
    }
951554
protected function blockAccess(AccountInterface $account) {
    // If tagging is off, deny access always.
    if (!$this->tagService->active() || !$this->tagService->groupActive()) {
      return AccessResult::forbidden();
    }

    // Routes we don't want to display the tag block on.
    $ignore_routes = [
      'entity.group.join',
      'entity.group.leave',
      'entity.group.edit_form',
      'entity.group.delete_form',
      'entity.group_content.collection',
    ];

    // Don't display on group edit.
    if (in_array($this->routeMatch->getRouteName(), $ignore_routes)) {
      return AccessResult::forbidden();
    }

    // Get group from route.
    $group = $this->routeMatch->getParameter('group');

    if ($group instanceof Group) {
      if ($group->hasField('social_tagging')) {
        if (!empty(($group->get('social_tagging')->getValue()))) {
          // We only show the block if the field contains values.
          return AccessResult::allowed();
        }
      }
    }

    return AccessResult::forbidden();
  }
445238
public function canEditMenu(Menu $menu, AccountInterface $account)
    {
        return $account->hasPermission(self::PERM_MANAGE_ALL_MENU) || $this->isUserWebmaster($menu, $account);
    }
793253
protected function doPut(AccountInterface $account, Request $request)
    {
        $account->setName($request->get('name'));
        $account->setCorporation($request->get('corporation'));
        $accountManager = $this->getAccountManager();

        if (null !== $request->get('uid')) {
            $account->setUid($request->get('uid'));
        }

        if (null !== $request->get('note')) {
            $account->setNote($request->get('note'));
        }

        $logo = $request->get('logo', []);
        if ($logo && array_key_exists('id', $logo)) {
            $accountManager->setLogo($account, $request->get('logo')['id']);
        }

        $this->setParent($request->get('parent'), $account);

        $user = $this->getUser();
        $account->setChanger($user);

        // Process details
        if (!($accountManager->processUrls($account, $request->get('urls', []))
            && $accountManager->processEmails($account, $request->get('emails', []))
            && $accountManager->processFaxes($account, $request->get('faxes', []))
            && $accountManager->processSocialMediaProfiles($account, $request->get('socialMediaProfiles', []))
            && $accountManager->processPhones($account, $request->get('phones', []))
            && $accountManager->processAddresses($account, $request->get('addresses', []))
            && $accountManager->processTags($account, $request->get('tags', []))
            && $accountManager->processNotes($account, $request->get('notes', []))
            && $accountManager->processCategories($account, $request->get('categories', []))
            && $accountManager->processBankAccounts($account, $request->get('bankAccounts', [])))
        ) {
            throw new RestException('Updating dependencies is not possible', 0);
        }
    }
155311
protected function blockAccess(AccountInterface $account) {
    $route_user_id = $this->routeMatch->getParameter('user');
    if ($account->id() == $route_user_id && $account->hasPermission("create event content")) {
      return AccessResult::allowed();
    }
    // By default, the block is not visible.
    return AccessResult::forbidden();
  }
1122151
public function deleteLabel(\stdClass $label)
    {
        // Prevents to delete a label which has children.
        if ($this->hasChildren($label)) {
            throw new \LogicException("Can't delete a label which has children.");
        }
        return taxonomy_term_delete($label->tid);
    }
385927
public function setLabel($label)
    {
        if (!(is_scalar($label) || is_null($label))) {
            return false;
        }

        $this->label = $label;
    }
1266485
protected function voteOnAttribute($attribute, $subject, TokenInterface $token): bool
    {
        $user = $token->getUser();

        if (!$user instanceof UserInterface) {
            return false;
        }

        $invitation = $subject;

        switch ($attribute) {
            case self::RESPOND:
                return $user->getUsername() == $invitation->getInvitee();
        }
    }
695643
public function campaignPagesReportsAccess(NodeInterface $node, AccountInterface $account) {
    return AccessResult::allowedIf($account->hasPermission('view retention campaign reports') && $node->getType() == 'campaign');
  }