MCPcopy Create free account
hub / github.com/Rello/analytics / auditShare

Method auditShare

lib/Db/ShareMapper.php:357–417  ·  view source on GitHub ↗
(string $action, array $share, array $changes = [])

Source from the content-addressed store, hash-verified

355 }
356
357 private function auditShare(string $action, array $share, array $changes = []): void
358 {
359 $table = match ($share['item_type']) {
360 'report' => self::TABLE_NAME_REPORT,
361 'panorama' => self::TABLE_NAME_PANORAMA,
362 'dataset' => 'analytics_dataset',
363 default => null,
364 };
365 $name = null;
366 if ($table !== null) {
367 $query = $this->db->getQueryBuilder();
368 $query->select('name')->from($table)
369 ->where($query->expr()->eq('id', $query->createNamedParameter($share['item_source'])));
370 $result = $query->executeQuery();
371 $item = $result->fetch();
372 $result->closeCursor();
373 $name = $item ? $item['name'] : null;
374 }
375 $shareType = match ((int)$share['type']) {
376 0 => 'user',
377 1 => 'group',
378 2 => 'user/group',
379 3 => 'public link',
380 10 => 'Talk room',
381 default => 'unknown recipient type',
382 };
383 $parameters = [
384 'itemType' => in_array($share['item_type'], ['report', 'panorama'], true)
385 ? 'Analytics ' . $share['item_type']
386 : $share['item_type'],
387 'name' => $name ?? '(unavailable)',
388 'itemId' => (int)$share['item_source'],
389 'owner' => $share['uid_initiator'],
390 'shareType' => $shareType,
391 'recipient' => (int)$share['type'] === 3 ? 'anyone with the link' : ($share['uid_owner'] ?? ''),
392 'actor' => $this->userSession->getUser()?->getUID() ?? 'system',
393 'shareId' => (int)$share['id'],
394 ];
395 $message = match ($action) {
396 'created' => 'The %s "%s" with ID "%s" owned by "%s" has been shared to the %s "%s" by "%s" (share ID "%s").',
397 'revoked' => 'The share of the %s "%s" with ID "%s" from "%s" to the %s "%s" has been revoked by "%s" (share ID "%s").',
398 'permissions_changed' => 'The permissions for the %s "%s" with ID "%s" shared from "%s" to the %s "%s" have been changed by "%s" (share ID "%s").',
399 'password_changed' => 'The password for the %s "%s" with ID "%s" shared from "%s" to the %s "%s" has been changed by "%s" (share ID "%s").',
400 'domain_changed' => 'The embedding domain for the %s "%s" with ID "%s" shared from "%s" to the %s "%s" has been changed by "%s" (share ID "%s").',
401 };
402 if ($changes !== []) {
403 if ($action === 'permissions_changed') {
404 foreach ($changes as $key => $value) {
405 $changes[$key] = match ((int)$value) {
406 1 => 'read-only',
407 2 => 'update allowed',
408 default => 'permissions ' . $value,
409 };
410 }
411 }
412 $parameters += $changes;
413 $message .= ' Changed from "%s" to "%s".';
414 }

Callers 3

createShareMethod · 0.95
updateShareFieldMethod · 0.95
deleteAuditedSharesMethod · 0.95

Calls 4

eqMethod · 0.80
fetchMethod · 0.80
getUserMethod · 0.80
dispatchTypedMethod · 0.80

Tested by

no test coverage detected