68 $this->init_complete =
true;
96 $cache = $this->access_cache;
103 $user_guid = $this->session_manager->getLoggedInUserGuid();
108 $access_array = $cache->load($hash);
109 if ($access_array === null) {
120 $membership_query = $select->subquery(self::MEMBERSHIP_TABLE_NAME);
121 $membership_query->select(
'access_collection_id')
124 $select->select(
'id')
126 ->orWhere($select->compare(
'id',
'in', $membership_query->getSQL()));
128 $collections = $this->db->getData($select);
129 if (!empty($collections)) {
130 foreach ($collections as $collection) {
131 $access_array[] = (int) $collection->id;
135 $ignore_access = $this->capabilities->canBypassPermissionsCheck(
$user_guid);
137 if ($ignore_access ===
true) {
142 if ($this->init_complete) {
143 $cache->save($hash, $access_array);
152 return $this->events->triggerResults(
'access:collections:read',
'user',
$options, $access_array);
195 return $this->entities->getRow($entity->guid,
$user_guid);
225 $cache = $this->access_cache;
232 $user_guid = $this->session_manager->getLoggedInUserGuid();
235 $hash =
$user_guid .
'get_write_access_array';
237 $access_array = $cache->load($hash);
238 if ($access_array === null) {
247 if ($this->init_complete) {
248 $cache->save($hash, $access_array);
257 $access_array = $this->events->triggerResults(
'access:collections:write',
'user',
$options, $access_array);
261 if (!isset($access_array[$access])) {
265 $temp = $access_array[
$access];
266 unset($access_array[$access]);
267 $access_array[
$access] = $temp;
271 return $access_array;
283 $subtypes = $this->events->triggerResults(
'access:collections:write:subtypes',
'user', [
'owner_guid' => $owner_guid], []);
288 $select->compare(
'subtype',
'is null'),
295 ->where($select->compare(
'owner_guid',
'=', $owner_guid,
ELGG_VALUE_GUID))
296 ->andWhere($select->merge($ors,
'OR'))
297 ->orderBy(
'name',
'ASC');
299 $collections = $this->db->getData($select, [$this,
'rowToElggAccessCollection']);
300 if (empty($collections)) {
305 foreach ($collections as $collection) {
306 $result[$collection->id] = $collection->getDisplayName();
336 $collection = $this->
get($collection_id);
341 if ($this->capabilities->canBypassPermissionsCheck(
$user->guid)) {
346 return array_key_exists($collection_id, $write_access);
365 if (!empty($acl->id)) {
366 return $this->
update($acl);
377 $id = $this->db->insertData($insert);
384 $this->access_cache->clear();
398 if (empty($acl->id)) {
399 return $this->
create($acl);
407 ->where($update->compare(
'id',
'=', $acl->id,
ELGG_VALUE_ID));
409 if (!$this->db->updateData($update)) {
413 $this->access_cache->clear();
427 if (empty($acl->id)) {
431 return $this->events->triggerSequence(
'delete', $acl->getType(), $acl,
function (
\ElggAccessCollection $acl) {
435 if (!$this->db->deleteData(
$delete)) {
441 $delete_membership->where($delete_membership->compare(
'access_collection_id',
'=', $acl->id,
ELGG_VALUE_ID));
443 $this->db->deleteData($delete_membership);
446 $this->access_cache->clear();
460 return new \ElggAccessCollection($row);
475 return $this->db->getDataRow(
$query, [$this,
'rowToElggAccessCollection']) ?: null;
505 $collection = $this->
get($collection_id);
510 $user = $this->entities->get($user_guid);
516 'collection_id' => $collection->id,
521 $result = $this->events->triggerResults(
'access:collections:add_user',
'collection',
$event_params,
true);
529 'access_collection_id' => $insert->param($collection_id,
ELGG_VALUE_ID),
534 $result = $this->db->insertData($insert);
536 $prev = $e->getPrevious();
537 if ($prev instanceof UniqueConstraintViolationException) {
545 $this->access_cache->clear();
563 'collection_id' => $collection_id,
568 if (!$this->events->triggerResults(
'access:collections:remove_user',
'collection',
$params,
true)) {
576 $this->access_cache->clear();
578 return (
bool) $this->db->deleteData(
$delete);
590 $supported_options = [
'owner_guid',
'subtype'];
594 ->orderBy(
'name',
'ASC');
596 foreach ($supported_options as $option) {
598 if (!isset($option_value)) {
604 $select->andWhere($select->compare($option,
'=', $option_value,
ELGG_VALUE_GUID));
607 $select->andWhere($select->compare($option,
'=', $option_value,
ELGG_VALUE_STRING));
612 return $this->db->getData($select, [$this,
'rowToElggAccessCollection']);
625 $qb->
join($table_alias, self::MEMBERSHIP_TABLE_NAME,
'acm', $qb->
compare(
'acm.user_guid',
'=',
"{$table_alias}.guid"));
642 $select->join($select->getTableAlias(), self::MEMBERSHIP_TABLE_NAME,
'acm', $select->compare(
"{$select->getTableAlias()}.id",
'=',
'acm.access_collection_id'));
644 $select->select(
"{$select->getTableAlias()}.*")
645 ->where($select->compare(
'acm.user_guid',
'=', $member_guid,
ELGG_VALUE_GUID))
646 ->orderBy(
'name',
'ASC');
648 return $this->db->getData($select, [$this,
'rowToElggAccessCollection']);
669 $translator = $this->translator;
676 ACCESS_PUBLIC => $translator->translate(
'access:label:public'),
679 if (array_key_exists($entity_access_id, $access_array)) {
680 return $access_array[$entity_access_id];
686 $collection = $this->
get($entity_access_id);
690 return $translator->translate(
'access:limited:label');
693 return $collection->getDisplayName();
getReadableAccessLevel(int $entity_access_id)
Return the name of an ACCESS_* constant or an access collection, but only if the logged in user owns ...
canEdit(int $user_guid=null)
Check if user can edit this collection.
elgg_call(int $flags, Closure $closure)
Calls a callable autowiring the arguments using public DI services and applying logic based on flags...
static table(string $table)
Returns a QueryBuilder for updating data in a given table.
removeUser(int $user_guid, int $collection_id)
Removes a user from an access collection.
hasAccessToEntity(\ElggEntity $entity, int $user_guid=0)
Can a user access an entity.
$params
Saves global plugin settings.
__construct(protected Config $config, protected Database $db, protected EntityTable $entities, protected UserCapabilities $capabilities, protected AccessCache $access_cache, protected EventsService $events, protected SessionManagerService $session_manager, protected Translator $translator)
Constructor.
const ELGG_ENFORCE_ACCESS
static find(array $options=[])
Build and execute a new query from an array of legacy options.
markInitComplete()
Mark the access system as initialized.
const ELGG_VALUE_INTEGER
Value types.
const MEMBERSHIP_TABLE_NAME
c Accompany it with the information you received as to the offer to distribute corresponding source complete source code means all the source code for all modules it plus any associated interface definition plus the scripts used to control compilation and installation of the executable as a special the source code distributed need not include anything that is normally and so on of the operating system on which the executable unless that component itself accompanies the executable If distribution of executable or object code is made by offering access to copy from a designated then offering equivalent access to copy the source code from the same place counts as distribution of the source even though third parties are not compelled to copy the source along with the object code You may not or distribute the Program except as expressly provided under this License Any attempt otherwise to sublicense or distribute the Program is void
canEdit(int $collection_id, int $user_guid=null)
Can the user change this access collection?
Database abstraction query builder.
static intoTable(string $table)
Returns a QueryBuilder for inserting data in a given table.
getCollectionsForWriteAccess(int $owner_guid)
Returns an array of access collections to be used in the write access array.
elgg_extract($key, $array, $default=null, bool $strict=true)
Checks for $array[$key] and returns its value if it exists, else returns $default.
$config
Advanced site settings, debugging section.
if($who_can_change_language=== 'nobody') elseif($who_can_change_language=== 'admin_only'&&!elgg_is_admin_logged_in()) $options
getWriteAccessArray(int $user_guid=0, bool $flush=false, array $input_params=[])
Returns an array of access permissions that the user is allowed to save content with.
trait Loggable
Enables adding a logger.
getCollectionsByMember(int $member_guid)
Return an array of collections that the entity is member of.
foreach($recommendedExtensions as $extension) if(empty(ini_get('session.gc_probability'))||empty(ini_get('session.gc_divisor'))) $db
Exception indicating a user could not be looked up for a permissions check.
rowToElggAccessCollection(\stdClass $row)
Transforms a database row to an instance of ElggAccessCollection.
compare(string $x, string $comparison, $y=null, string $type=null, bool $case_sensitive=null)
Build value comparison clause.
A generic parent class for database exceptions.
static fromTable(string $table)
Returns a QueryBuilder for deleting data from a given table.
getEntityCollections(array $options=[])
Returns access collections.
create(\ElggAccessCollection $acl)
Creates a new access collection.
addUser(int $user_guid, int $collection_id)
Adds a user to an access collection.
getAccessArray(int $user_guid=0, bool $flush=false)
Returns an array of access IDs a user is permitted to see.
update(\ElggAccessCollection $acl)
Update an existing access collection.
static fromTable(string $table, string $alias=null)
Returns a QueryBuilder for selecting data from a given table.
join(string $fromAlias, string $join, string $alias,?string $condition=null)
{}
User capabilities service.
$id
Generic annotation delete action.
Entity table database service.
hasUser(int $user_guid, int $collection_id)
Check if user is already in the collection.
getMembers(int $collection_id, array $options=[])
Get members of an access collection.