Oauth - Use selectWhereClause to check perms instead of overriding API4 Get
[civicrm-core.git] / ext / oauth-client / CRM / OAuth / BAO / OAuthContactToken.php
1 <?php
2
3 class CRM_OAuth_BAO_OAuthContactToken extends CRM_OAuth_DAO_OAuthContactToken {
4
5 /**
6 * @inheritDoc
7 */
8 public function addSelectWhereClause() {
9 $clauses = [];
10 $loggedInContactID = CRM_Core_Session::getLoggedInContactID();
11
12 // With 'manage all' permission, apply standard contact ACLs
13 if (CRM_Core_Permission::check(['manage all OAuth contact tokens'])) {
14 $clauses['contact_id'] = CRM_Utils_SQL::mergeSubquery('Contact');
15 }
16 // With 'manage my' permission, limit to just the current user
17 elseif ($loggedInContactID && CRM_Core_Permission::check(['manage my OAuth contact tokens'])) {
18 $clauses['contact_id'] = "= $loggedInContactID";
19 }
20 // No permission, return nothing
21 else {
22 $clauses['contact_id'] = "= -1";
23 }
24 CRM_Utils_Hook::selectWhereClause($this, $clauses);
25 return $clauses;
26 }
27
28 }