@@ -34,27 +34,27 @@ |
||
34 | 34 | |
35 | 35 | class TwoFactorSettingsController extends Controller { |
36 | 36 | |
37 | - /** @var MandatoryTwoFactor */ |
|
38 | - private $mandatoryTwoFactor; |
|
37 | + /** @var MandatoryTwoFactor */ |
|
38 | + private $mandatoryTwoFactor; |
|
39 | 39 | |
40 | - public function __construct(string $appName, |
|
41 | - IRequest $request, |
|
42 | - MandatoryTwoFactor $mandatoryTwoFactor) { |
|
43 | - parent::__construct($appName, $request); |
|
40 | + public function __construct(string $appName, |
|
41 | + IRequest $request, |
|
42 | + MandatoryTwoFactor $mandatoryTwoFactor) { |
|
43 | + parent::__construct($appName, $request); |
|
44 | 44 | |
45 | - $this->mandatoryTwoFactor = $mandatoryTwoFactor; |
|
46 | - } |
|
45 | + $this->mandatoryTwoFactor = $mandatoryTwoFactor; |
|
46 | + } |
|
47 | 47 | |
48 | - public function index(): JSONResponse { |
|
49 | - return new JSONResponse($this->mandatoryTwoFactor->getState()); |
|
50 | - } |
|
48 | + public function index(): JSONResponse { |
|
49 | + return new JSONResponse($this->mandatoryTwoFactor->getState()); |
|
50 | + } |
|
51 | 51 | |
52 | - public function update(bool $enforced, array $enforcedGroups = [], array $excludedGroups = []): JSONResponse { |
|
53 | - $this->mandatoryTwoFactor->setState( |
|
54 | - new EnforcementState($enforced, $enforcedGroups, $excludedGroups) |
|
55 | - ); |
|
52 | + public function update(bool $enforced, array $enforcedGroups = [], array $excludedGroups = []): JSONResponse { |
|
53 | + $this->mandatoryTwoFactor->setState( |
|
54 | + new EnforcementState($enforced, $enforcedGroups, $excludedGroups) |
|
55 | + ); |
|
56 | 56 | |
57 | - return new JSONResponse($this->mandatoryTwoFactor->getState()); |
|
58 | - } |
|
57 | + return new JSONResponse($this->mandatoryTwoFactor->getState()); |
|
58 | + } |
|
59 | 59 | |
60 | 60 | } |
@@ -26,71 +26,71 @@ |
||
26 | 26 | |
27 | 27 | class Setting implements ISetting { |
28 | 28 | |
29 | - /** @var IL10N */ |
|
30 | - protected $l; |
|
29 | + /** @var IL10N */ |
|
30 | + protected $l; |
|
31 | 31 | |
32 | - /** |
|
33 | - * @param IL10N $l10n |
|
34 | - */ |
|
35 | - public function __construct(IL10N $l10n) { |
|
36 | - $this->l = $l10n; |
|
37 | - } |
|
32 | + /** |
|
33 | + * @param IL10N $l10n |
|
34 | + */ |
|
35 | + public function __construct(IL10N $l10n) { |
|
36 | + $this->l = $l10n; |
|
37 | + } |
|
38 | 38 | |
39 | - /** |
|
40 | - * @return string Lowercase a-z and underscore only identifier |
|
41 | - * @since 11.0.0 |
|
42 | - */ |
|
43 | - public function getIdentifier() { |
|
44 | - return 'personal_settings'; |
|
45 | - } |
|
39 | + /** |
|
40 | + * @return string Lowercase a-z and underscore only identifier |
|
41 | + * @since 11.0.0 |
|
42 | + */ |
|
43 | + public function getIdentifier() { |
|
44 | + return 'personal_settings'; |
|
45 | + } |
|
46 | 46 | |
47 | - /** |
|
48 | - * @return string A translated string |
|
49 | - * @since 11.0.0 |
|
50 | - */ |
|
51 | - public function getName() { |
|
52 | - return $this->l->t('Your <strong>password</strong> or <strong>email</strong> was modified'); |
|
53 | - } |
|
47 | + /** |
|
48 | + * @return string A translated string |
|
49 | + * @since 11.0.0 |
|
50 | + */ |
|
51 | + public function getName() { |
|
52 | + return $this->l->t('Your <strong>password</strong> or <strong>email</strong> was modified'); |
|
53 | + } |
|
54 | 54 | |
55 | - /** |
|
56 | - * @return int whether the filter should be rather on the top or bottom of |
|
57 | - * the admin section. The filters are arranged in ascending order of the |
|
58 | - * priority values. It is required to return a value between 0 and 100. |
|
59 | - * @since 11.0.0 |
|
60 | - */ |
|
61 | - public function getPriority() { |
|
62 | - return 0; |
|
63 | - } |
|
55 | + /** |
|
56 | + * @return int whether the filter should be rather on the top or bottom of |
|
57 | + * the admin section. The filters are arranged in ascending order of the |
|
58 | + * priority values. It is required to return a value between 0 and 100. |
|
59 | + * @since 11.0.0 |
|
60 | + */ |
|
61 | + public function getPriority() { |
|
62 | + return 0; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * @return bool True when the option can be changed for the stream |
|
67 | - * @since 11.0.0 |
|
68 | - */ |
|
69 | - public function canChangeStream() { |
|
70 | - return false; |
|
71 | - } |
|
65 | + /** |
|
66 | + * @return bool True when the option can be changed for the stream |
|
67 | + * @since 11.0.0 |
|
68 | + */ |
|
69 | + public function canChangeStream() { |
|
70 | + return false; |
|
71 | + } |
|
72 | 72 | |
73 | - /** |
|
74 | - * @return bool True when the option can be changed for the stream |
|
75 | - * @since 11.0.0 |
|
76 | - */ |
|
77 | - public function isDefaultEnabledStream() { |
|
78 | - return true; |
|
79 | - } |
|
73 | + /** |
|
74 | + * @return bool True when the option can be changed for the stream |
|
75 | + * @since 11.0.0 |
|
76 | + */ |
|
77 | + public function isDefaultEnabledStream() { |
|
78 | + return true; |
|
79 | + } |
|
80 | 80 | |
81 | - /** |
|
82 | - * @return bool True when the option can be changed for the mail |
|
83 | - * @since 11.0.0 |
|
84 | - */ |
|
85 | - public function canChangeMail() { |
|
86 | - return false; |
|
87 | - } |
|
81 | + /** |
|
82 | + * @return bool True when the option can be changed for the mail |
|
83 | + * @since 11.0.0 |
|
84 | + */ |
|
85 | + public function canChangeMail() { |
|
86 | + return false; |
|
87 | + } |
|
88 | 88 | |
89 | - /** |
|
90 | - * @return bool True when the option can be changed for the stream |
|
91 | - * @since 11.0.0 |
|
92 | - */ |
|
93 | - public function isDefaultEnabledMail() { |
|
94 | - return false; |
|
95 | - } |
|
89 | + /** |
|
90 | + * @return bool True when the option can be changed for the stream |
|
91 | + * @since 11.0.0 |
|
92 | + */ |
|
93 | + public function isDefaultEnabledMail() { |
|
94 | + return false; |
|
95 | + } |
|
96 | 96 | } |
@@ -28,39 +28,39 @@ |
||
28 | 28 | |
29 | 29 | class SecurityFilter implements IFilter { |
30 | 30 | |
31 | - /** @var IURLGenerator */ |
|
32 | - private $urlGenerator; |
|
31 | + /** @var IURLGenerator */ |
|
32 | + private $urlGenerator; |
|
33 | 33 | |
34 | - /** @var IL10N */ |
|
35 | - private $l10n; |
|
34 | + /** @var IL10N */ |
|
35 | + private $l10n; |
|
36 | 36 | |
37 | - public function __construct(IURLGenerator $urlGenerator, IL10N $l10n) { |
|
38 | - $this->urlGenerator = $urlGenerator; |
|
39 | - $this->l10n = $l10n; |
|
40 | - } |
|
37 | + public function __construct(IURLGenerator $urlGenerator, IL10N $l10n) { |
|
38 | + $this->urlGenerator = $urlGenerator; |
|
39 | + $this->l10n = $l10n; |
|
40 | + } |
|
41 | 41 | |
42 | - public function allowedApps() { |
|
43 | - return []; |
|
44 | - } |
|
42 | + public function allowedApps() { |
|
43 | + return []; |
|
44 | + } |
|
45 | 45 | |
46 | - public function filterTypes(array $types) { |
|
47 | - return array_intersect(['security'], $types); |
|
48 | - } |
|
46 | + public function filterTypes(array $types) { |
|
47 | + return array_intersect(['security'], $types); |
|
48 | + } |
|
49 | 49 | |
50 | - public function getIcon() { |
|
51 | - return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg')); |
|
52 | - } |
|
50 | + public function getIcon() { |
|
51 | + return $this->urlGenerator->getAbsoluteURL($this->urlGenerator->imagePath('core', 'actions/password.svg')); |
|
52 | + } |
|
53 | 53 | |
54 | - public function getIdentifier() { |
|
55 | - return 'security'; |
|
56 | - } |
|
54 | + public function getIdentifier() { |
|
55 | + return 'security'; |
|
56 | + } |
|
57 | 57 | |
58 | - public function getName() { |
|
59 | - return $this->l10n->t('Security'); |
|
60 | - } |
|
58 | + public function getName() { |
|
59 | + return $this->l10n->t('Security'); |
|
60 | + } |
|
61 | 61 | |
62 | - public function getPriority() { |
|
63 | - return 30; |
|
64 | - } |
|
62 | + public function getPriority() { |
|
63 | + return 30; |
|
64 | + } |
|
65 | 65 | |
66 | 66 | } |
@@ -169,7 +169,7 @@ |
||
169 | 169 | protected function setSubjects(IEvent $event, string $subject, array $parameters): void { |
170 | 170 | $placeholders = $replacements = []; |
171 | 171 | foreach ($parameters as $placeholder => $parameter) { |
172 | - $placeholders[] = '{' . $placeholder . '}'; |
|
172 | + $placeholders[] = '{'.$placeholder.'}'; |
|
173 | 173 | $replacements[] = $parameter['name']; |
174 | 174 | } |
175 | 175 |
@@ -35,143 +35,143 @@ |
||
35 | 35 | use OCP\L10N\IFactory as L10nFactory; |
36 | 36 | |
37 | 37 | class GroupProvider implements IProvider { |
38 | - public const ADDED_TO_GROUP = 'group_added'; |
|
39 | - public const REMOVED_FROM_GROUP = 'group_removed'; |
|
40 | - |
|
41 | - /** @var L10nFactory */ |
|
42 | - private $l10n; |
|
43 | - /** @var IURLGenerator */ |
|
44 | - private $urlGenerator; |
|
45 | - /** @var IManager */ |
|
46 | - private $activityManager; |
|
47 | - /** @var IUserManager */ |
|
48 | - protected $userManager; |
|
49 | - /** @var IGroupManager */ |
|
50 | - protected $groupManager; |
|
51 | - |
|
52 | - /** @var string[] */ |
|
53 | - protected $groupDisplayNames = []; |
|
54 | - |
|
55 | - |
|
56 | - public function __construct(L10nFactory $l10n, |
|
57 | - IURLGenerator $urlGenerator, |
|
58 | - IManager $activityManager, |
|
59 | - IUserManager $userManager, |
|
60 | - IGroupManager $groupManager) { |
|
61 | - $this->urlGenerator = $urlGenerator; |
|
62 | - $this->l10n = $l10n; |
|
63 | - $this->activityManager = $activityManager; |
|
64 | - $this->userManager = $userManager; |
|
65 | - $this->groupManager = $groupManager; |
|
66 | - } |
|
67 | - |
|
68 | - public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
69 | - if ($event->getType() !== 'group_settings') { |
|
70 | - throw new InvalidArgumentException(); |
|
71 | - } |
|
72 | - |
|
73 | - $l = $this->l10n->get('settings', $language); |
|
74 | - |
|
75 | - $params = $event->getSubjectParameters(); |
|
76 | - $parsedParameters = [ |
|
77 | - 'user' => $this->generateUserParameter($params['user']), |
|
78 | - 'group' => $this->generateGroupParameter($params['group']), |
|
79 | - ]; |
|
80 | - |
|
81 | - if (isset($params['actor'])) { |
|
82 | - $parsedParameters['actor'] = $this->generateUserParameter($params['actor']); |
|
83 | - } |
|
84 | - |
|
85 | - switch ($event->getSubject()) { |
|
86 | - case self::ADDED_TO_GROUP: |
|
87 | - if (isset($parsedParameters['actor'])) { |
|
88 | - if ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
89 | - $subject = $l->t('{actor} added you to group {group}'); |
|
90 | - } elseif (isset($params['actor']) && $this->activityManager->getCurrentUserId() === $params['actor']) { |
|
91 | - $subject = $l->t('You added {user} to group {group}'); |
|
92 | - } else { |
|
93 | - $subject = $l->t('{actor} added {user} to group {group}'); |
|
94 | - } |
|
95 | - } elseif ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
96 | - $subject = $l->t('An administrator added you to group {group}'); |
|
97 | - } else { |
|
98 | - $subject = $l->t('An administrator added {user} to group {group}'); |
|
99 | - } |
|
100 | - break; |
|
101 | - case self::REMOVED_FROM_GROUP: |
|
102 | - if (isset($parsedParameters['actor'])) { |
|
103 | - if ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
104 | - $subject = $l->t('{actor} removed you from group {group}'); |
|
105 | - } elseif (isset($params['actor']) && $this->activityManager->getCurrentUserId() === $params['actor']) { |
|
106 | - $subject = $l->t('You removed {user} from group {group}'); |
|
107 | - } else { |
|
108 | - $subject = $l->t('{actor} removed {user} from group {group}'); |
|
109 | - } |
|
110 | - } elseif ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
111 | - $subject = $l->t('An administrator removed you from group {group}'); |
|
112 | - } else { |
|
113 | - $subject = $l->t('An administrator removed {user} from group {group}'); |
|
114 | - } |
|
115 | - break; |
|
116 | - default: |
|
117 | - throw new InvalidArgumentException(); |
|
118 | - } |
|
119 | - |
|
120 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
121 | - |
|
122 | - return $event; |
|
123 | - } |
|
124 | - |
|
125 | - /** |
|
126 | - * @param IEvent $event |
|
127 | - * @param string $subject |
|
128 | - * @param array $parameters |
|
129 | - * @throws \InvalidArgumentException |
|
130 | - */ |
|
131 | - protected function setSubjects(IEvent $event, string $subject, array $parameters): void { |
|
132 | - $placeholders = $replacements = []; |
|
133 | - foreach ($parameters as $placeholder => $parameter) { |
|
134 | - $placeholders[] = '{' . $placeholder . '}'; |
|
135 | - $replacements[] = $parameter['name']; |
|
136 | - } |
|
137 | - |
|
138 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
139 | - ->setRichSubject($subject, $parameters); |
|
140 | - } |
|
141 | - |
|
142 | - /** |
|
143 | - * @param string $gid |
|
144 | - * @return array |
|
145 | - */ |
|
146 | - protected function generateGroupParameter(string $gid): array { |
|
147 | - if (!isset($this->groupDisplayNames[$gid])) { |
|
148 | - $this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid); |
|
149 | - } |
|
150 | - |
|
151 | - return [ |
|
152 | - 'type' => 'user-group', |
|
153 | - 'id' => $gid, |
|
154 | - 'name' => $this->groupDisplayNames[$gid], |
|
155 | - ]; |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @param string $gid |
|
160 | - * @return string |
|
161 | - */ |
|
162 | - protected function getGroupDisplayName(string $gid): string { |
|
163 | - $group = $this->groupManager->get($gid); |
|
164 | - if ($group instanceof IGroup) { |
|
165 | - return $group->getDisplayName(); |
|
166 | - } |
|
167 | - return $gid; |
|
168 | - } |
|
169 | - |
|
170 | - protected function generateUserParameter(string $uid): array { |
|
171 | - return [ |
|
172 | - 'type' => 'user', |
|
173 | - 'id' => $uid, |
|
174 | - 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
175 | - ]; |
|
176 | - } |
|
38 | + public const ADDED_TO_GROUP = 'group_added'; |
|
39 | + public const REMOVED_FROM_GROUP = 'group_removed'; |
|
40 | + |
|
41 | + /** @var L10nFactory */ |
|
42 | + private $l10n; |
|
43 | + /** @var IURLGenerator */ |
|
44 | + private $urlGenerator; |
|
45 | + /** @var IManager */ |
|
46 | + private $activityManager; |
|
47 | + /** @var IUserManager */ |
|
48 | + protected $userManager; |
|
49 | + /** @var IGroupManager */ |
|
50 | + protected $groupManager; |
|
51 | + |
|
52 | + /** @var string[] */ |
|
53 | + protected $groupDisplayNames = []; |
|
54 | + |
|
55 | + |
|
56 | + public function __construct(L10nFactory $l10n, |
|
57 | + IURLGenerator $urlGenerator, |
|
58 | + IManager $activityManager, |
|
59 | + IUserManager $userManager, |
|
60 | + IGroupManager $groupManager) { |
|
61 | + $this->urlGenerator = $urlGenerator; |
|
62 | + $this->l10n = $l10n; |
|
63 | + $this->activityManager = $activityManager; |
|
64 | + $this->userManager = $userManager; |
|
65 | + $this->groupManager = $groupManager; |
|
66 | + } |
|
67 | + |
|
68 | + public function parse($language, IEvent $event, IEvent $previousEvent = null) { |
|
69 | + if ($event->getType() !== 'group_settings') { |
|
70 | + throw new InvalidArgumentException(); |
|
71 | + } |
|
72 | + |
|
73 | + $l = $this->l10n->get('settings', $language); |
|
74 | + |
|
75 | + $params = $event->getSubjectParameters(); |
|
76 | + $parsedParameters = [ |
|
77 | + 'user' => $this->generateUserParameter($params['user']), |
|
78 | + 'group' => $this->generateGroupParameter($params['group']), |
|
79 | + ]; |
|
80 | + |
|
81 | + if (isset($params['actor'])) { |
|
82 | + $parsedParameters['actor'] = $this->generateUserParameter($params['actor']); |
|
83 | + } |
|
84 | + |
|
85 | + switch ($event->getSubject()) { |
|
86 | + case self::ADDED_TO_GROUP: |
|
87 | + if (isset($parsedParameters['actor'])) { |
|
88 | + if ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
89 | + $subject = $l->t('{actor} added you to group {group}'); |
|
90 | + } elseif (isset($params['actor']) && $this->activityManager->getCurrentUserId() === $params['actor']) { |
|
91 | + $subject = $l->t('You added {user} to group {group}'); |
|
92 | + } else { |
|
93 | + $subject = $l->t('{actor} added {user} to group {group}'); |
|
94 | + } |
|
95 | + } elseif ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
96 | + $subject = $l->t('An administrator added you to group {group}'); |
|
97 | + } else { |
|
98 | + $subject = $l->t('An administrator added {user} to group {group}'); |
|
99 | + } |
|
100 | + break; |
|
101 | + case self::REMOVED_FROM_GROUP: |
|
102 | + if (isset($parsedParameters['actor'])) { |
|
103 | + if ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
104 | + $subject = $l->t('{actor} removed you from group {group}'); |
|
105 | + } elseif (isset($params['actor']) && $this->activityManager->getCurrentUserId() === $params['actor']) { |
|
106 | + $subject = $l->t('You removed {user} from group {group}'); |
|
107 | + } else { |
|
108 | + $subject = $l->t('{actor} removed {user} from group {group}'); |
|
109 | + } |
|
110 | + } elseif ($this->activityManager->getCurrentUserId() === $params['user']) { |
|
111 | + $subject = $l->t('An administrator removed you from group {group}'); |
|
112 | + } else { |
|
113 | + $subject = $l->t('An administrator removed {user} from group {group}'); |
|
114 | + } |
|
115 | + break; |
|
116 | + default: |
|
117 | + throw new InvalidArgumentException(); |
|
118 | + } |
|
119 | + |
|
120 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
121 | + |
|
122 | + return $event; |
|
123 | + } |
|
124 | + |
|
125 | + /** |
|
126 | + * @param IEvent $event |
|
127 | + * @param string $subject |
|
128 | + * @param array $parameters |
|
129 | + * @throws \InvalidArgumentException |
|
130 | + */ |
|
131 | + protected function setSubjects(IEvent $event, string $subject, array $parameters): void { |
|
132 | + $placeholders = $replacements = []; |
|
133 | + foreach ($parameters as $placeholder => $parameter) { |
|
134 | + $placeholders[] = '{' . $placeholder . '}'; |
|
135 | + $replacements[] = $parameter['name']; |
|
136 | + } |
|
137 | + |
|
138 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
139 | + ->setRichSubject($subject, $parameters); |
|
140 | + } |
|
141 | + |
|
142 | + /** |
|
143 | + * @param string $gid |
|
144 | + * @return array |
|
145 | + */ |
|
146 | + protected function generateGroupParameter(string $gid): array { |
|
147 | + if (!isset($this->groupDisplayNames[$gid])) { |
|
148 | + $this->groupDisplayNames[$gid] = $this->getGroupDisplayName($gid); |
|
149 | + } |
|
150 | + |
|
151 | + return [ |
|
152 | + 'type' => 'user-group', |
|
153 | + 'id' => $gid, |
|
154 | + 'name' => $this->groupDisplayNames[$gid], |
|
155 | + ]; |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @param string $gid |
|
160 | + * @return string |
|
161 | + */ |
|
162 | + protected function getGroupDisplayName(string $gid): string { |
|
163 | + $group = $this->groupManager->get($gid); |
|
164 | + if ($group instanceof IGroup) { |
|
165 | + return $group->getDisplayName(); |
|
166 | + } |
|
167 | + return $gid; |
|
168 | + } |
|
169 | + |
|
170 | + protected function generateUserParameter(string $uid): array { |
|
171 | + return [ |
|
172 | + 'type' => 'user', |
|
173 | + 'id' => $uid, |
|
174 | + 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
175 | + ]; |
|
176 | + } |
|
177 | 177 | } |
@@ -169,7 +169,7 @@ |
||
169 | 169 | protected function setSubjects(IEvent $event, string $subject, array $parameters): void { |
170 | 170 | $placeholders = $replacements = []; |
171 | 171 | foreach ($parameters as $placeholder => $parameter) { |
172 | - $placeholders[] = '{' . $placeholder . '}'; |
|
172 | + $placeholders[] = '{'.$placeholder.'}'; |
|
173 | 173 | $replacements[] = $parameter['name']; |
174 | 174 | } |
175 | 175 |
@@ -38,175 +38,175 @@ |
||
38 | 38 | use OCP\L10N\IFactory; |
39 | 39 | |
40 | 40 | class Provider implements IProvider { |
41 | - public const PASSWORD_CHANGED_BY = 'password_changed_by'; |
|
42 | - public const PASSWORD_CHANGED_SELF = 'password_changed_self'; |
|
43 | - public const PASSWORD_RESET = 'password_changed'; |
|
44 | - public const PASSWORD_RESET_SELF = 'password_reset_self'; |
|
45 | - public const EMAIL_CHANGED_BY = 'email_changed_by'; |
|
46 | - public const EMAIL_CHANGED_SELF = 'email_changed_self'; |
|
47 | - public const EMAIL_CHANGED = 'email_changed'; |
|
48 | - public const APP_TOKEN_CREATED = 'app_token_created'; |
|
49 | - public const APP_TOKEN_DELETED = 'app_token_deleted'; |
|
50 | - public const APP_TOKEN_RENAMED = 'app_token_renamed'; |
|
51 | - public const APP_TOKEN_FILESYSTEM_GRANTED = 'app_token_filesystem_granted'; |
|
52 | - public const APP_TOKEN_FILESYSTEM_REVOKED = 'app_token_filesystem_revoked'; |
|
53 | - |
|
54 | - /** @var IFactory */ |
|
55 | - protected $languageFactory; |
|
56 | - |
|
57 | - /** @var IL10N */ |
|
58 | - protected $l; |
|
59 | - |
|
60 | - /** @var IURLGenerator */ |
|
61 | - protected $url; |
|
62 | - |
|
63 | - /** @var IUserManager */ |
|
64 | - protected $userManager; |
|
65 | - |
|
66 | - /** @var IManager */ |
|
67 | - private $activityManager; |
|
68 | - |
|
69 | - public function __construct(IFactory $languageFactory, |
|
70 | - IURLGenerator $url, |
|
71 | - IUserManager $userManager, |
|
72 | - IManager $activityManager) { |
|
73 | - $this->languageFactory = $languageFactory; |
|
74 | - $this->url = $url; |
|
75 | - $this->userManager = $userManager; |
|
76 | - $this->activityManager = $activityManager; |
|
77 | - } |
|
78 | - |
|
79 | - /** |
|
80 | - * @param string $language |
|
81 | - * @param IEvent $event |
|
82 | - * @param IEvent|null $previousEvent |
|
83 | - * @return IEvent |
|
84 | - * @throws \InvalidArgumentException |
|
85 | - * @since 11.0.0 |
|
86 | - */ |
|
87 | - public function parse($language, IEvent $event, IEvent $previousEvent = null): IEvent { |
|
88 | - if ($event->getApp() !== 'settings') { |
|
89 | - throw new \InvalidArgumentException('Unknown app'); |
|
90 | - } |
|
91 | - |
|
92 | - $this->l = $this->languageFactory->get('settings', $language); |
|
93 | - |
|
94 | - if ($this->activityManager->getRequirePNG()) { |
|
95 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.png'))); |
|
96 | - } else { |
|
97 | - $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.svg'))); |
|
98 | - } |
|
99 | - |
|
100 | - if ($event->getSubject() === self::PASSWORD_CHANGED_BY) { |
|
101 | - $subject = $this->l->t('{actor} changed your password'); |
|
102 | - } elseif ($event->getSubject() === self::PASSWORD_CHANGED_SELF) { |
|
103 | - $subject = $this->l->t('You changed your password'); |
|
104 | - } elseif ($event->getSubject() === self::PASSWORD_RESET) { |
|
105 | - $subject = $this->l->t('Your password was reset by an administrator'); |
|
106 | - } elseif ($event->getSubject() === self::PASSWORD_RESET_SELF) { |
|
107 | - $subject = $this->l->t('Your password was reset'); |
|
108 | - } elseif ($event->getSubject() === self::EMAIL_CHANGED_BY) { |
|
109 | - $subject = $this->l->t('{actor} changed your email address'); |
|
110 | - } elseif ($event->getSubject() === self::EMAIL_CHANGED_SELF) { |
|
111 | - $subject = $this->l->t('You changed your email address'); |
|
112 | - } elseif ($event->getSubject() === self::EMAIL_CHANGED) { |
|
113 | - $subject = $this->l->t('Your email address was changed by an administrator'); |
|
114 | - } elseif ($event->getSubject() === self::APP_TOKEN_CREATED) { |
|
115 | - if ($event->getAffectedUser() === $event->getAuthor()) { |
|
116 | - $subject = $this->l->t('You created app password "{token}"'); |
|
117 | - } else { |
|
118 | - $subject = $this->l->t('An administrator created app password "{token}"'); |
|
119 | - } |
|
120 | - } elseif ($event->getSubject() === self::APP_TOKEN_DELETED) { |
|
121 | - $subject = $this->l->t('You deleted app password "{token}"'); |
|
122 | - } elseif ($event->getSubject() === self::APP_TOKEN_RENAMED) { |
|
123 | - $subject = $this->l->t('You renamed app password "{token}" to "{newToken}"'); |
|
124 | - } elseif ($event->getSubject() === self::APP_TOKEN_FILESYSTEM_GRANTED) { |
|
125 | - $subject = $this->l->t('You granted filesystem access to app password "{token}"'); |
|
126 | - } elseif ($event->getSubject() === self::APP_TOKEN_FILESYSTEM_REVOKED) { |
|
127 | - $subject = $this->l->t('You revoked filesystem access from app password "{token}"'); |
|
128 | - } else { |
|
129 | - throw new \InvalidArgumentException('Unknown subject'); |
|
130 | - } |
|
131 | - |
|
132 | - $parsedParameters = $this->getParameters($event); |
|
133 | - $this->setSubjects($event, $subject, $parsedParameters); |
|
134 | - |
|
135 | - return $event; |
|
136 | - } |
|
137 | - |
|
138 | - /** |
|
139 | - * @param IEvent $event |
|
140 | - * @return array |
|
141 | - * @throws \InvalidArgumentException |
|
142 | - */ |
|
143 | - protected function getParameters(IEvent $event): array { |
|
144 | - $subject = $event->getSubject(); |
|
145 | - $parameters = $event->getSubjectParameters(); |
|
146 | - |
|
147 | - switch ($subject) { |
|
148 | - case self::PASSWORD_CHANGED_SELF: |
|
149 | - case self::PASSWORD_RESET: |
|
150 | - case self::PASSWORD_RESET_SELF: |
|
151 | - case self::EMAIL_CHANGED_SELF: |
|
152 | - case self::EMAIL_CHANGED: |
|
153 | - return []; |
|
154 | - case self::PASSWORD_CHANGED_BY: |
|
155 | - case self::EMAIL_CHANGED_BY: |
|
156 | - return [ |
|
157 | - 'actor' => $this->generateUserParameter($parameters[0]), |
|
158 | - ]; |
|
159 | - case self::APP_TOKEN_CREATED: |
|
160 | - case self::APP_TOKEN_DELETED: |
|
161 | - case self::APP_TOKEN_FILESYSTEM_GRANTED: |
|
162 | - case self::APP_TOKEN_FILESYSTEM_REVOKED: |
|
163 | - return [ |
|
164 | - 'token' => [ |
|
165 | - 'type' => 'highlight', |
|
166 | - 'id' => $event->getObjectId(), |
|
167 | - 'name' => $parameters['name'], |
|
168 | - ] |
|
169 | - ]; |
|
170 | - case self::APP_TOKEN_RENAMED: |
|
171 | - return [ |
|
172 | - 'token' => [ |
|
173 | - 'type' => 'highlight', |
|
174 | - 'id' => $event->getObjectId(), |
|
175 | - 'name' => $parameters['name'], |
|
176 | - ], |
|
177 | - 'newToken' => [ |
|
178 | - 'type' => 'highlight', |
|
179 | - 'id' => $event->getObjectId(), |
|
180 | - 'name' => $parameters['newName'], |
|
181 | - ] |
|
182 | - ]; |
|
183 | - } |
|
184 | - |
|
185 | - throw new \InvalidArgumentException('Unknown subject'); |
|
186 | - } |
|
187 | - |
|
188 | - /** |
|
189 | - * @param IEvent $event |
|
190 | - * @param string $subject |
|
191 | - * @param array $parameters |
|
192 | - * @throws \InvalidArgumentException |
|
193 | - */ |
|
194 | - protected function setSubjects(IEvent $event, string $subject, array $parameters): void { |
|
195 | - $placeholders = $replacements = []; |
|
196 | - foreach ($parameters as $placeholder => $parameter) { |
|
197 | - $placeholders[] = '{' . $placeholder . '}'; |
|
198 | - $replacements[] = $parameter['name']; |
|
199 | - } |
|
200 | - |
|
201 | - $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
202 | - ->setRichSubject($subject, $parameters); |
|
203 | - } |
|
204 | - |
|
205 | - protected function generateUserParameter(string $uid): array { |
|
206 | - return [ |
|
207 | - 'type' => 'user', |
|
208 | - 'id' => $uid, |
|
209 | - 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
210 | - ]; |
|
211 | - } |
|
41 | + public const PASSWORD_CHANGED_BY = 'password_changed_by'; |
|
42 | + public const PASSWORD_CHANGED_SELF = 'password_changed_self'; |
|
43 | + public const PASSWORD_RESET = 'password_changed'; |
|
44 | + public const PASSWORD_RESET_SELF = 'password_reset_self'; |
|
45 | + public const EMAIL_CHANGED_BY = 'email_changed_by'; |
|
46 | + public const EMAIL_CHANGED_SELF = 'email_changed_self'; |
|
47 | + public const EMAIL_CHANGED = 'email_changed'; |
|
48 | + public const APP_TOKEN_CREATED = 'app_token_created'; |
|
49 | + public const APP_TOKEN_DELETED = 'app_token_deleted'; |
|
50 | + public const APP_TOKEN_RENAMED = 'app_token_renamed'; |
|
51 | + public const APP_TOKEN_FILESYSTEM_GRANTED = 'app_token_filesystem_granted'; |
|
52 | + public const APP_TOKEN_FILESYSTEM_REVOKED = 'app_token_filesystem_revoked'; |
|
53 | + |
|
54 | + /** @var IFactory */ |
|
55 | + protected $languageFactory; |
|
56 | + |
|
57 | + /** @var IL10N */ |
|
58 | + protected $l; |
|
59 | + |
|
60 | + /** @var IURLGenerator */ |
|
61 | + protected $url; |
|
62 | + |
|
63 | + /** @var IUserManager */ |
|
64 | + protected $userManager; |
|
65 | + |
|
66 | + /** @var IManager */ |
|
67 | + private $activityManager; |
|
68 | + |
|
69 | + public function __construct(IFactory $languageFactory, |
|
70 | + IURLGenerator $url, |
|
71 | + IUserManager $userManager, |
|
72 | + IManager $activityManager) { |
|
73 | + $this->languageFactory = $languageFactory; |
|
74 | + $this->url = $url; |
|
75 | + $this->userManager = $userManager; |
|
76 | + $this->activityManager = $activityManager; |
|
77 | + } |
|
78 | + |
|
79 | + /** |
|
80 | + * @param string $language |
|
81 | + * @param IEvent $event |
|
82 | + * @param IEvent|null $previousEvent |
|
83 | + * @return IEvent |
|
84 | + * @throws \InvalidArgumentException |
|
85 | + * @since 11.0.0 |
|
86 | + */ |
|
87 | + public function parse($language, IEvent $event, IEvent $previousEvent = null): IEvent { |
|
88 | + if ($event->getApp() !== 'settings') { |
|
89 | + throw new \InvalidArgumentException('Unknown app'); |
|
90 | + } |
|
91 | + |
|
92 | + $this->l = $this->languageFactory->get('settings', $language); |
|
93 | + |
|
94 | + if ($this->activityManager->getRequirePNG()) { |
|
95 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.png'))); |
|
96 | + } else { |
|
97 | + $event->setIcon($this->url->getAbsoluteURL($this->url->imagePath('settings', 'personal.svg'))); |
|
98 | + } |
|
99 | + |
|
100 | + if ($event->getSubject() === self::PASSWORD_CHANGED_BY) { |
|
101 | + $subject = $this->l->t('{actor} changed your password'); |
|
102 | + } elseif ($event->getSubject() === self::PASSWORD_CHANGED_SELF) { |
|
103 | + $subject = $this->l->t('You changed your password'); |
|
104 | + } elseif ($event->getSubject() === self::PASSWORD_RESET) { |
|
105 | + $subject = $this->l->t('Your password was reset by an administrator'); |
|
106 | + } elseif ($event->getSubject() === self::PASSWORD_RESET_SELF) { |
|
107 | + $subject = $this->l->t('Your password was reset'); |
|
108 | + } elseif ($event->getSubject() === self::EMAIL_CHANGED_BY) { |
|
109 | + $subject = $this->l->t('{actor} changed your email address'); |
|
110 | + } elseif ($event->getSubject() === self::EMAIL_CHANGED_SELF) { |
|
111 | + $subject = $this->l->t('You changed your email address'); |
|
112 | + } elseif ($event->getSubject() === self::EMAIL_CHANGED) { |
|
113 | + $subject = $this->l->t('Your email address was changed by an administrator'); |
|
114 | + } elseif ($event->getSubject() === self::APP_TOKEN_CREATED) { |
|
115 | + if ($event->getAffectedUser() === $event->getAuthor()) { |
|
116 | + $subject = $this->l->t('You created app password "{token}"'); |
|
117 | + } else { |
|
118 | + $subject = $this->l->t('An administrator created app password "{token}"'); |
|
119 | + } |
|
120 | + } elseif ($event->getSubject() === self::APP_TOKEN_DELETED) { |
|
121 | + $subject = $this->l->t('You deleted app password "{token}"'); |
|
122 | + } elseif ($event->getSubject() === self::APP_TOKEN_RENAMED) { |
|
123 | + $subject = $this->l->t('You renamed app password "{token}" to "{newToken}"'); |
|
124 | + } elseif ($event->getSubject() === self::APP_TOKEN_FILESYSTEM_GRANTED) { |
|
125 | + $subject = $this->l->t('You granted filesystem access to app password "{token}"'); |
|
126 | + } elseif ($event->getSubject() === self::APP_TOKEN_FILESYSTEM_REVOKED) { |
|
127 | + $subject = $this->l->t('You revoked filesystem access from app password "{token}"'); |
|
128 | + } else { |
|
129 | + throw new \InvalidArgumentException('Unknown subject'); |
|
130 | + } |
|
131 | + |
|
132 | + $parsedParameters = $this->getParameters($event); |
|
133 | + $this->setSubjects($event, $subject, $parsedParameters); |
|
134 | + |
|
135 | + return $event; |
|
136 | + } |
|
137 | + |
|
138 | + /** |
|
139 | + * @param IEvent $event |
|
140 | + * @return array |
|
141 | + * @throws \InvalidArgumentException |
|
142 | + */ |
|
143 | + protected function getParameters(IEvent $event): array { |
|
144 | + $subject = $event->getSubject(); |
|
145 | + $parameters = $event->getSubjectParameters(); |
|
146 | + |
|
147 | + switch ($subject) { |
|
148 | + case self::PASSWORD_CHANGED_SELF: |
|
149 | + case self::PASSWORD_RESET: |
|
150 | + case self::PASSWORD_RESET_SELF: |
|
151 | + case self::EMAIL_CHANGED_SELF: |
|
152 | + case self::EMAIL_CHANGED: |
|
153 | + return []; |
|
154 | + case self::PASSWORD_CHANGED_BY: |
|
155 | + case self::EMAIL_CHANGED_BY: |
|
156 | + return [ |
|
157 | + 'actor' => $this->generateUserParameter($parameters[0]), |
|
158 | + ]; |
|
159 | + case self::APP_TOKEN_CREATED: |
|
160 | + case self::APP_TOKEN_DELETED: |
|
161 | + case self::APP_TOKEN_FILESYSTEM_GRANTED: |
|
162 | + case self::APP_TOKEN_FILESYSTEM_REVOKED: |
|
163 | + return [ |
|
164 | + 'token' => [ |
|
165 | + 'type' => 'highlight', |
|
166 | + 'id' => $event->getObjectId(), |
|
167 | + 'name' => $parameters['name'], |
|
168 | + ] |
|
169 | + ]; |
|
170 | + case self::APP_TOKEN_RENAMED: |
|
171 | + return [ |
|
172 | + 'token' => [ |
|
173 | + 'type' => 'highlight', |
|
174 | + 'id' => $event->getObjectId(), |
|
175 | + 'name' => $parameters['name'], |
|
176 | + ], |
|
177 | + 'newToken' => [ |
|
178 | + 'type' => 'highlight', |
|
179 | + 'id' => $event->getObjectId(), |
|
180 | + 'name' => $parameters['newName'], |
|
181 | + ] |
|
182 | + ]; |
|
183 | + } |
|
184 | + |
|
185 | + throw new \InvalidArgumentException('Unknown subject'); |
|
186 | + } |
|
187 | + |
|
188 | + /** |
|
189 | + * @param IEvent $event |
|
190 | + * @param string $subject |
|
191 | + * @param array $parameters |
|
192 | + * @throws \InvalidArgumentException |
|
193 | + */ |
|
194 | + protected function setSubjects(IEvent $event, string $subject, array $parameters): void { |
|
195 | + $placeholders = $replacements = []; |
|
196 | + foreach ($parameters as $placeholder => $parameter) { |
|
197 | + $placeholders[] = '{' . $placeholder . '}'; |
|
198 | + $replacements[] = $parameter['name']; |
|
199 | + } |
|
200 | + |
|
201 | + $event->setParsedSubject(str_replace($placeholders, $replacements, $subject)) |
|
202 | + ->setRichSubject($subject, $parameters); |
|
203 | + } |
|
204 | + |
|
205 | + protected function generateUserParameter(string $uid): array { |
|
206 | + return [ |
|
207 | + 'type' => 'user', |
|
208 | + 'id' => $uid, |
|
209 | + 'name' => $this->userManager->getDisplayName($uid) ?? $uid, |
|
210 | + ]; |
|
211 | + } |
|
212 | 212 | } |
@@ -27,39 +27,39 @@ |
||
27 | 27 | |
28 | 28 | class SecuritySetting implements ISetting { |
29 | 29 | |
30 | - /** @var IL10N */ |
|
31 | - private $l10n; |
|
30 | + /** @var IL10N */ |
|
31 | + private $l10n; |
|
32 | 32 | |
33 | - public function __construct(IL10N $l10n) { |
|
34 | - $this->l10n = $l10n; |
|
35 | - } |
|
33 | + public function __construct(IL10N $l10n) { |
|
34 | + $this->l10n = $l10n; |
|
35 | + } |
|
36 | 36 | |
37 | - public function canChangeMail() { |
|
38 | - return false; |
|
39 | - } |
|
37 | + public function canChangeMail() { |
|
38 | + return false; |
|
39 | + } |
|
40 | 40 | |
41 | - public function canChangeStream() { |
|
42 | - return false; |
|
43 | - } |
|
41 | + public function canChangeStream() { |
|
42 | + return false; |
|
43 | + } |
|
44 | 44 | |
45 | - public function getIdentifier() { |
|
46 | - return 'security'; |
|
47 | - } |
|
45 | + public function getIdentifier() { |
|
46 | + return 'security'; |
|
47 | + } |
|
48 | 48 | |
49 | - public function getName() { |
|
50 | - return $this->l10n->t('Security'); |
|
51 | - } |
|
49 | + public function getName() { |
|
50 | + return $this->l10n->t('Security'); |
|
51 | + } |
|
52 | 52 | |
53 | - public function getPriority() { |
|
54 | - return 30; |
|
55 | - } |
|
53 | + public function getPriority() { |
|
54 | + return 30; |
|
55 | + } |
|
56 | 56 | |
57 | - public function isDefaultEnabledMail() { |
|
58 | - return true; |
|
59 | - } |
|
57 | + public function isDefaultEnabledMail() { |
|
58 | + return true; |
|
59 | + } |
|
60 | 60 | |
61 | - public function isDefaultEnabledStream() { |
|
62 | - return true; |
|
63 | - } |
|
61 | + public function isDefaultEnabledStream() { |
|
62 | + return true; |
|
63 | + } |
|
64 | 64 | |
65 | 65 | } |
@@ -370,18 +370,18 @@ discard block |
||
370 | 370 | private function findFileWithExtension($class, $ext) |
371 | 371 | { |
372 | 372 | // PSR-4 lookup |
373 | - $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR) . $ext; |
|
373 | + $logicalPathPsr4 = strtr($class, '\\', DIRECTORY_SEPARATOR).$ext; |
|
374 | 374 | |
375 | 375 | $first = $class[0]; |
376 | 376 | if (isset($this->prefixLengthsPsr4[$first])) { |
377 | 377 | $subPath = $class; |
378 | 378 | while (false !== $lastPos = strrpos($subPath, '\\')) { |
379 | 379 | $subPath = substr($subPath, 0, $lastPos); |
380 | - $search = $subPath . '\\'; |
|
380 | + $search = $subPath.'\\'; |
|
381 | 381 | if (isset($this->prefixDirsPsr4[$search])) { |
382 | - $pathEnd = DIRECTORY_SEPARATOR . substr($logicalPathPsr4, $lastPos + 1); |
|
382 | + $pathEnd = DIRECTORY_SEPARATOR.substr($logicalPathPsr4, $lastPos + 1); |
|
383 | 383 | foreach ($this->prefixDirsPsr4[$search] as $dir) { |
384 | - if (file_exists($file = $dir . $pathEnd)) { |
|
384 | + if (file_exists($file = $dir.$pathEnd)) { |
|
385 | 385 | return $file; |
386 | 386 | } |
387 | 387 | } |
@@ -391,7 +391,7 @@ discard block |
||
391 | 391 | |
392 | 392 | // PSR-4 fallback dirs |
393 | 393 | foreach ($this->fallbackDirsPsr4 as $dir) { |
394 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr4)) { |
|
394 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr4)) { |
|
395 | 395 | return $file; |
396 | 396 | } |
397 | 397 | } |
@@ -403,14 +403,14 @@ discard block |
||
403 | 403 | . strtr(substr($logicalPathPsr4, $pos + 1), '_', DIRECTORY_SEPARATOR); |
404 | 404 | } else { |
405 | 405 | // PEAR-like class name |
406 | - $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR) . $ext; |
|
406 | + $logicalPathPsr0 = strtr($class, '_', DIRECTORY_SEPARATOR).$ext; |
|
407 | 407 | } |
408 | 408 | |
409 | 409 | if (isset($this->prefixesPsr0[$first])) { |
410 | 410 | foreach ($this->prefixesPsr0[$first] as $prefix => $dirs) { |
411 | 411 | if (0 === strpos($class, $prefix)) { |
412 | 412 | foreach ($dirs as $dir) { |
413 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
413 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
414 | 414 | return $file; |
415 | 415 | } |
416 | 416 | } |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | |
421 | 421 | // PSR-0 fallback dirs |
422 | 422 | foreach ($this->fallbackDirsPsr0 as $dir) { |
423 | - if (file_exists($file = $dir . DIRECTORY_SEPARATOR . $logicalPathPsr0)) { |
|
423 | + if (file_exists($file = $dir.DIRECTORY_SEPARATOR.$logicalPathPsr0)) { |
|
424 | 424 | return $file; |
425 | 425 | } |
426 | 426 | } |
@@ -6,5 +6,5 @@ |
||
6 | 6 | $baseDir = $vendorDir; |
7 | 7 | |
8 | 8 | return array( |
9 | - 'OCA\\Settings\\' => array($baseDir . '/../lib'), |
|
9 | + 'OCA\\Settings\\' => array($baseDir.'/../lib'), |
|
10 | 10 | ); |
@@ -142,18 +142,18 @@ discard block |
||
142 | 142 | protected function convertLevelString($level) { |
143 | 143 | $level = strtolower($level); |
144 | 144 | switch ($level) { |
145 | - case 'debug': |
|
146 | - return 0; |
|
147 | - case 'info': |
|
148 | - return 1; |
|
149 | - case 'warning': |
|
150 | - case 'warn': |
|
151 | - return 2; |
|
152 | - case 'error': |
|
153 | - case 'err': |
|
154 | - return 3; |
|
155 | - case 'fatal': |
|
156 | - return 4; |
|
145 | + case 'debug': |
|
146 | + return 0; |
|
147 | + case 'info': |
|
148 | + return 1; |
|
149 | + case 'warning': |
|
150 | + case 'warn': |
|
151 | + return 2; |
|
152 | + case 'error': |
|
153 | + case 'err': |
|
154 | + return 3; |
|
155 | + case 'fatal': |
|
156 | + return 4; |
|
157 | 157 | } |
158 | 158 | throw new \InvalidArgumentException('Invalid log level string'); |
159 | 159 | } |
@@ -165,16 +165,16 @@ discard block |
||
165 | 165 | */ |
166 | 166 | protected function convertLevelNumber($levelNum) { |
167 | 167 | switch ($levelNum) { |
168 | - case 0: |
|
169 | - return 'Debug'; |
|
170 | - case 1: |
|
171 | - return 'Info'; |
|
172 | - case 2: |
|
173 | - return 'Warning'; |
|
174 | - case 3: |
|
175 | - return 'Error'; |
|
176 | - case 4: |
|
177 | - return 'Fatal'; |
|
168 | + case 0: |
|
169 | + return 'Debug'; |
|
170 | + case 1: |
|
171 | + return 'Info'; |
|
172 | + case 2: |
|
173 | + return 'Warning'; |
|
174 | + case 3: |
|
175 | + return 'Error'; |
|
176 | + case 4: |
|
177 | + return 'Fatal'; |
|
178 | 178 | } |
179 | 179 | throw new \InvalidArgumentException('Invalid log level number'); |
180 | 180 | } |
@@ -35,175 +35,175 @@ |
||
35 | 35 | use Symfony\Component\Console\Output\OutputInterface; |
36 | 36 | |
37 | 37 | class Manage extends Command implements CompletionAwareInterface { |
38 | - public const DEFAULT_BACKEND = 'file'; |
|
39 | - public const DEFAULT_LOG_LEVEL = 2; |
|
40 | - public const DEFAULT_TIMEZONE = 'UTC'; |
|
41 | - |
|
42 | - protected IConfig $config; |
|
43 | - |
|
44 | - public function __construct(IConfig $config) { |
|
45 | - $this->config = $config; |
|
46 | - parent::__construct(); |
|
47 | - } |
|
48 | - |
|
49 | - protected function configure() { |
|
50 | - $this |
|
51 | - ->setName('log:manage') |
|
52 | - ->setDescription('manage logging configuration') |
|
53 | - ->addOption( |
|
54 | - 'backend', |
|
55 | - null, |
|
56 | - InputOption::VALUE_REQUIRED, |
|
57 | - 'set the logging backend [file, syslog, errorlog, systemd]' |
|
58 | - ) |
|
59 | - ->addOption( |
|
60 | - 'level', |
|
61 | - null, |
|
62 | - InputOption::VALUE_REQUIRED, |
|
63 | - 'set the log level [debug, info, warning, error, fatal]' |
|
64 | - ) |
|
65 | - ->addOption( |
|
66 | - 'timezone', |
|
67 | - null, |
|
68 | - InputOption::VALUE_REQUIRED, |
|
69 | - 'set the logging timezone' |
|
70 | - ) |
|
71 | - ; |
|
72 | - } |
|
73 | - |
|
74 | - protected function execute(InputInterface $input, OutputInterface $output): int { |
|
75 | - // collate config setting to the end, to avoid partial configuration |
|
76 | - $toBeSet = []; |
|
77 | - |
|
78 | - if ($backend = $input->getOption('backend')) { |
|
79 | - $this->validateBackend($backend); |
|
80 | - $toBeSet['log_type'] = $backend; |
|
81 | - } |
|
82 | - |
|
83 | - $level = $input->getOption('level'); |
|
84 | - if ($level !== null) { |
|
85 | - if (is_numeric($level)) { |
|
86 | - $levelNum = $level; |
|
87 | - // sanity check |
|
88 | - $this->convertLevelNumber($levelNum); |
|
89 | - } else { |
|
90 | - $levelNum = $this->convertLevelString($level); |
|
91 | - } |
|
92 | - $toBeSet['loglevel'] = $levelNum; |
|
93 | - } |
|
94 | - |
|
95 | - if ($timezone = $input->getOption('timezone')) { |
|
96 | - $this->validateTimezone($timezone); |
|
97 | - $toBeSet['logtimezone'] = $timezone; |
|
98 | - } |
|
99 | - |
|
100 | - // set config |
|
101 | - foreach ($toBeSet as $option => $value) { |
|
102 | - $this->config->setSystemValue($option, $value); |
|
103 | - } |
|
104 | - |
|
105 | - // display configuration |
|
106 | - $backend = $this->config->getSystemValue('log_type', self::DEFAULT_BACKEND); |
|
107 | - $output->writeln('Enabled logging backend: '.$backend); |
|
108 | - |
|
109 | - $levelNum = $this->config->getSystemValue('loglevel', self::DEFAULT_LOG_LEVEL); |
|
110 | - $level = $this->convertLevelNumber($levelNum); |
|
111 | - $output->writeln('Log level: '.$level.' ('.$levelNum.')'); |
|
112 | - |
|
113 | - $timezone = $this->config->getSystemValue('logtimezone', self::DEFAULT_TIMEZONE); |
|
114 | - $output->writeln('Log timezone: '.$timezone); |
|
115 | - return 0; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * @param string $backend |
|
120 | - * @throws \InvalidArgumentException |
|
121 | - */ |
|
122 | - protected function validateBackend($backend) { |
|
123 | - if (!class_exists('OC\\Log\\'.ucfirst($backend))) { |
|
124 | - throw new \InvalidArgumentException('Invalid backend'); |
|
125 | - } |
|
126 | - } |
|
127 | - |
|
128 | - /** |
|
129 | - * @param string $timezone |
|
130 | - * @throws \Exception |
|
131 | - */ |
|
132 | - protected function validateTimezone($timezone) { |
|
133 | - new \DateTimeZone($timezone); |
|
134 | - } |
|
135 | - |
|
136 | - /** |
|
137 | - * @param string $level |
|
138 | - * @return int |
|
139 | - * @throws \InvalidArgumentException |
|
140 | - */ |
|
141 | - protected function convertLevelString($level) { |
|
142 | - $level = strtolower($level); |
|
143 | - switch ($level) { |
|
144 | - case 'debug': |
|
145 | - return 0; |
|
146 | - case 'info': |
|
147 | - return 1; |
|
148 | - case 'warning': |
|
149 | - case 'warn': |
|
150 | - return 2; |
|
151 | - case 'error': |
|
152 | - case 'err': |
|
153 | - return 3; |
|
154 | - case 'fatal': |
|
155 | - return 4; |
|
156 | - } |
|
157 | - throw new \InvalidArgumentException('Invalid log level string'); |
|
158 | - } |
|
159 | - |
|
160 | - /** |
|
161 | - * @param int $levelNum |
|
162 | - * @return string |
|
163 | - * @throws \InvalidArgumentException |
|
164 | - */ |
|
165 | - protected function convertLevelNumber($levelNum) { |
|
166 | - switch ($levelNum) { |
|
167 | - case 0: |
|
168 | - return 'Debug'; |
|
169 | - case 1: |
|
170 | - return 'Info'; |
|
171 | - case 2: |
|
172 | - return 'Warning'; |
|
173 | - case 3: |
|
174 | - return 'Error'; |
|
175 | - case 4: |
|
176 | - return 'Fatal'; |
|
177 | - } |
|
178 | - throw new \InvalidArgumentException('Invalid log level number'); |
|
179 | - } |
|
180 | - |
|
181 | - /** |
|
182 | - * @param string $optionName |
|
183 | - * @param CompletionContext $context |
|
184 | - * @return string[] |
|
185 | - */ |
|
186 | - public function completeOptionValues($optionName, CompletionContext $context) { |
|
187 | - if ($optionName === 'backend') { |
|
188 | - return ['file', 'syslog', 'errorlog', 'systemd']; |
|
189 | - } elseif ($optionName === 'level') { |
|
190 | - return ['debug', 'info', 'warning', 'error', 'fatal']; |
|
191 | - } elseif ($optionName === 'timezone') { |
|
192 | - $identifier = \DateTimeZone::listIdentifiers(); |
|
193 | - if ($identifier === false) { |
|
194 | - return []; |
|
195 | - } |
|
196 | - return $identifier; |
|
197 | - } |
|
198 | - return []; |
|
199 | - } |
|
200 | - |
|
201 | - /** |
|
202 | - * @param string $argumentName |
|
203 | - * @param CompletionContext $context |
|
204 | - * @return string[] |
|
205 | - */ |
|
206 | - public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
207 | - return []; |
|
208 | - } |
|
38 | + public const DEFAULT_BACKEND = 'file'; |
|
39 | + public const DEFAULT_LOG_LEVEL = 2; |
|
40 | + public const DEFAULT_TIMEZONE = 'UTC'; |
|
41 | + |
|
42 | + protected IConfig $config; |
|
43 | + |
|
44 | + public function __construct(IConfig $config) { |
|
45 | + $this->config = $config; |
|
46 | + parent::__construct(); |
|
47 | + } |
|
48 | + |
|
49 | + protected function configure() { |
|
50 | + $this |
|
51 | + ->setName('log:manage') |
|
52 | + ->setDescription('manage logging configuration') |
|
53 | + ->addOption( |
|
54 | + 'backend', |
|
55 | + null, |
|
56 | + InputOption::VALUE_REQUIRED, |
|
57 | + 'set the logging backend [file, syslog, errorlog, systemd]' |
|
58 | + ) |
|
59 | + ->addOption( |
|
60 | + 'level', |
|
61 | + null, |
|
62 | + InputOption::VALUE_REQUIRED, |
|
63 | + 'set the log level [debug, info, warning, error, fatal]' |
|
64 | + ) |
|
65 | + ->addOption( |
|
66 | + 'timezone', |
|
67 | + null, |
|
68 | + InputOption::VALUE_REQUIRED, |
|
69 | + 'set the logging timezone' |
|
70 | + ) |
|
71 | + ; |
|
72 | + } |
|
73 | + |
|
74 | + protected function execute(InputInterface $input, OutputInterface $output): int { |
|
75 | + // collate config setting to the end, to avoid partial configuration |
|
76 | + $toBeSet = []; |
|
77 | + |
|
78 | + if ($backend = $input->getOption('backend')) { |
|
79 | + $this->validateBackend($backend); |
|
80 | + $toBeSet['log_type'] = $backend; |
|
81 | + } |
|
82 | + |
|
83 | + $level = $input->getOption('level'); |
|
84 | + if ($level !== null) { |
|
85 | + if (is_numeric($level)) { |
|
86 | + $levelNum = $level; |
|
87 | + // sanity check |
|
88 | + $this->convertLevelNumber($levelNum); |
|
89 | + } else { |
|
90 | + $levelNum = $this->convertLevelString($level); |
|
91 | + } |
|
92 | + $toBeSet['loglevel'] = $levelNum; |
|
93 | + } |
|
94 | + |
|
95 | + if ($timezone = $input->getOption('timezone')) { |
|
96 | + $this->validateTimezone($timezone); |
|
97 | + $toBeSet['logtimezone'] = $timezone; |
|
98 | + } |
|
99 | + |
|
100 | + // set config |
|
101 | + foreach ($toBeSet as $option => $value) { |
|
102 | + $this->config->setSystemValue($option, $value); |
|
103 | + } |
|
104 | + |
|
105 | + // display configuration |
|
106 | + $backend = $this->config->getSystemValue('log_type', self::DEFAULT_BACKEND); |
|
107 | + $output->writeln('Enabled logging backend: '.$backend); |
|
108 | + |
|
109 | + $levelNum = $this->config->getSystemValue('loglevel', self::DEFAULT_LOG_LEVEL); |
|
110 | + $level = $this->convertLevelNumber($levelNum); |
|
111 | + $output->writeln('Log level: '.$level.' ('.$levelNum.')'); |
|
112 | + |
|
113 | + $timezone = $this->config->getSystemValue('logtimezone', self::DEFAULT_TIMEZONE); |
|
114 | + $output->writeln('Log timezone: '.$timezone); |
|
115 | + return 0; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * @param string $backend |
|
120 | + * @throws \InvalidArgumentException |
|
121 | + */ |
|
122 | + protected function validateBackend($backend) { |
|
123 | + if (!class_exists('OC\\Log\\'.ucfirst($backend))) { |
|
124 | + throw new \InvalidArgumentException('Invalid backend'); |
|
125 | + } |
|
126 | + } |
|
127 | + |
|
128 | + /** |
|
129 | + * @param string $timezone |
|
130 | + * @throws \Exception |
|
131 | + */ |
|
132 | + protected function validateTimezone($timezone) { |
|
133 | + new \DateTimeZone($timezone); |
|
134 | + } |
|
135 | + |
|
136 | + /** |
|
137 | + * @param string $level |
|
138 | + * @return int |
|
139 | + * @throws \InvalidArgumentException |
|
140 | + */ |
|
141 | + protected function convertLevelString($level) { |
|
142 | + $level = strtolower($level); |
|
143 | + switch ($level) { |
|
144 | + case 'debug': |
|
145 | + return 0; |
|
146 | + case 'info': |
|
147 | + return 1; |
|
148 | + case 'warning': |
|
149 | + case 'warn': |
|
150 | + return 2; |
|
151 | + case 'error': |
|
152 | + case 'err': |
|
153 | + return 3; |
|
154 | + case 'fatal': |
|
155 | + return 4; |
|
156 | + } |
|
157 | + throw new \InvalidArgumentException('Invalid log level string'); |
|
158 | + } |
|
159 | + |
|
160 | + /** |
|
161 | + * @param int $levelNum |
|
162 | + * @return string |
|
163 | + * @throws \InvalidArgumentException |
|
164 | + */ |
|
165 | + protected function convertLevelNumber($levelNum) { |
|
166 | + switch ($levelNum) { |
|
167 | + case 0: |
|
168 | + return 'Debug'; |
|
169 | + case 1: |
|
170 | + return 'Info'; |
|
171 | + case 2: |
|
172 | + return 'Warning'; |
|
173 | + case 3: |
|
174 | + return 'Error'; |
|
175 | + case 4: |
|
176 | + return 'Fatal'; |
|
177 | + } |
|
178 | + throw new \InvalidArgumentException('Invalid log level number'); |
|
179 | + } |
|
180 | + |
|
181 | + /** |
|
182 | + * @param string $optionName |
|
183 | + * @param CompletionContext $context |
|
184 | + * @return string[] |
|
185 | + */ |
|
186 | + public function completeOptionValues($optionName, CompletionContext $context) { |
|
187 | + if ($optionName === 'backend') { |
|
188 | + return ['file', 'syslog', 'errorlog', 'systemd']; |
|
189 | + } elseif ($optionName === 'level') { |
|
190 | + return ['debug', 'info', 'warning', 'error', 'fatal']; |
|
191 | + } elseif ($optionName === 'timezone') { |
|
192 | + $identifier = \DateTimeZone::listIdentifiers(); |
|
193 | + if ($identifier === false) { |
|
194 | + return []; |
|
195 | + } |
|
196 | + return $identifier; |
|
197 | + } |
|
198 | + return []; |
|
199 | + } |
|
200 | + |
|
201 | + /** |
|
202 | + * @param string $argumentName |
|
203 | + * @param CompletionContext $context |
|
204 | + * @return string[] |
|
205 | + */ |
|
206 | + public function completeArgumentValues($argumentName, CompletionContext $context) { |
|
207 | + return []; |
|
208 | + } |
|
209 | 209 | } |