Wiki-Quellcode von NotificationsPreferencesMacros
Zuletzt geändert von Daniel Herrmann am 2025/02/24 17:44
Verstecke letzte Bearbeiter
| author | version | line-number | content |
|---|---|---|---|
| |
1.1 | 1 | {{velocity output="false"}} |
| 2 | #if (!$XWikiNotificationsCodeNotificationsPreferencesMacrosIncluded) | ||
| 3 | #set ($XWikiNotificationsCodeNotificationsPreferencesMacrosIncluded = true) | ||
| 4 | ## | ||
| 5 | ## Get all event types and group them by applications | ||
| 6 | ## | ||
| 7 | #set ($types = []) | ||
| 8 | #foreach ($descriptor in $services.eventstream.getRecordableEventDescriptors($xcontext.isMainWiki())) | ||
| 9 | #set ($discard = $types.add({ | ||
| 10 | 'applicationName' : "$!services.localization.render($descriptor.applicationName)", | ||
| 11 | 'applicationIcon' : "$!services.icon.renderHTML($descriptor.applicationIcon)", | ||
| 12 | 'description' : "$!services.localization.render($descriptor.description)", | ||
| 13 | 'eventType' : "$!descriptor.eventType", | ||
| 14 | 'filter' : "$!descriptor.filter", | ||
| 15 | 'applicationId' : "$!descriptor.applicationId" | ||
| 16 | })) | ||
| 17 | #end | ||
| 18 | #set ($apps = []) | ||
| 19 | #set ($lastAppId = '') | ||
| 20 | #foreach ($type in $collectiontool.sort($types, ['applicationName', 'eventType'])) | ||
| 21 | #if ($lastAppId != $type.applicationId) | ||
| 22 | #set ($lastAppId = $type.applicationId) | ||
| 23 | #set ($lastApp = []) | ||
| 24 | #set ($discard = $apps.add($lastApp)) | ||
| 25 | #end | ||
| 26 | #set ($discard = $lastApp.add($type)) | ||
| 27 | #end | ||
| 28 | #end | ||
| 29 | |||
| 30 | ## | ||
| 31 | ## Check that the macro preferences parameters are ok and the current user have proper permissions. | ||
| 32 | ## | ||
| 33 | #macro (checkMacroNotificationPreferencesParameters $checkResult) | ||
| 34 | #set ($checkResult = false) | ||
| 35 | #if (!$xcontext.userReference && $wikimacro.parameters.target == 'user') | ||
| 36 | {{info}} | ||
| 37 | {{translation key="notifications.settings.applications.forGuest" /}} | ||
| 38 | {{/info}} | ||
| 39 | #elseif ($wikimacro.parameters.target == 'wiki' && !$services.security.authorization.hasAccess('admin', $services.model.createWikiReference($services.wiki.currentWikiId))) | ||
| 40 | {{error}} | ||
| 41 | {{translation key="notifications.settings.error.notAdmin" /}} | ||
| 42 | {{/error}} | ||
| 43 | #elseif ($wikimacro.parameters.target == 'user' && "$!wikimacro.parameters.user" != "" && $wikimacro.parameters.user.class.simpleName != 'DocumentUserReference') | ||
| 44 | {{error}} | ||
| 45 | {{translation key="notifications.settings.error.userReferenceNotSupported" /}} | ||
| 46 | {{/error}} | ||
| 47 | #elseif ($wikimacro.parameters.target == 'user' && "$!wikimacro.parameters.user" != "" && !$services.security.authorization.hasAccess('admin', $wikimacro.parameters.user.reference) && !$xcontext.userReference.equals($wikimacro.parameters.user.reference)) | ||
| 48 | {{error}} | ||
| 49 | {{translation key="notifications.settings.error.userReferenceAdminForbidden" /}} | ||
| 50 | {{/error}} | ||
| 51 | #else | ||
| 52 | #set ($checkResult = true) | ||
| 53 | #end | ||
| 54 | #end | ||
| 55 | {{/velocity}} |