Skip to content

Commit ca67990

Browse files
committed
fix: No longer provide the "enabled" setting as now all log types are supported
Signed-off-by: Ferdinand Thiessen <[email protected]>
1 parent 3dbc7fc commit ca67990

File tree

9 files changed

+16
-75
lines changed

9 files changed

+16
-75
lines changed

lib/Controller/LogController.php

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,6 @@
2626
use OCA\LogReader\Log\SearchFilter;
2727
use OCA\LogReader\Service\SettingsService;
2828
use OCP\AppFramework\Controller;
29-
use OCP\AppFramework\Http;
3029
use OCP\AppFramework\Http\JSONResponse;
3130
use OCP\IRequest;
3231
use Psr\Log\LoggerInterface;
@@ -55,13 +54,6 @@ public function __construct($appName,
5554
* @return JSONResponse
5655
*/
5756
public function get($query = '', $count = 50, $offset = 0): JSONResponse {
58-
$logType = $this->settingsService->getLoggingType();
59-
// we only support web access when `log_type` is set to `file` (the default)
60-
if ($logType !== 'file') {
61-
$this->logger->debug('File-based logging must be enabled to access logs from the Web UI.');
62-
return new JSONResponse([], Http::STATUS_FAILED_DEPENDENCY);
63-
}
64-
6557
$iterator = $this->logIteratorFactory->getLogIterator($this->settingsService->getShownLevels());
6658

6759
if ($query !== '') {
@@ -100,13 +92,6 @@ private function getLastItem() {
10092
* request.
10193
*/
10294
public function poll(string $lastReqId): JSONResponse {
103-
$logType = $this->settingsService->getLoggingType();
104-
// we only support web access when `log_type` is set to `file` (the default)
105-
if ($logType !== 'file') {
106-
$this->logger->debug('File-based logging must be enabled to access logs from the Web UI.');
107-
return new JSONResponse([], Http::STATUS_FAILED_DEPENDENCY);
108-
}
109-
11095
$lastItem = $this->getLastItem();
11196
if ($lastItem === null || $lastItem['reqId'] === $lastReqId) {
11297
return new JSONResponse([]);

lib/Service/SettingsService.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ public function getAppSettings(): array {
6868
Constants::CONFIG_KEY_DATETIMEFORMAT => $this->getDateTimeFormat(),
6969
Constants::CONFIG_KEY_RELATIVEDATES => $this->getRelativeDates(),
7070
Constants::CONFIG_KEY_LIVELOG => $this->getLiveLog(),
71-
'enabled' => $this->getLoggingType() === 'file',
7271
];
7372
}
7473

src/App.vue

Lines changed: 7 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
</NcButton>
1919
</div>
2020
<!-- Show information / warning message -->
21-
<NcNoteCard v-if="settingsStore.localFile" type="info" class="info-note">
21+
<NcNoteCard v-if="!settingsStore.isServerLogShown" type="info" class="info-note">
2222
<div class="info-note__content">
2323
<p>{{ t('logreader', 'Currently the log file {file} is shown', { file: settingsStore.localFileName }) }}</p>
2424
<NcButton type="secondary" @click="onShowServerLog">
@@ -30,17 +30,13 @@
3030
<p>{{ t('logreader', 'Live view is disabled') }}</p>
3131
</NcNoteCard>
3232
<!-- Show the log file table -->
33-
<LogTable v-if="settingsStore.enabled" :rows="entries" />
34-
<NcEmptyContent v-else :name="t('logreader', 'No log file')">
33+
<LogTable v-if="hasEntries" :rows="entries" />
34+
<NcEmptyContent v-else
35+
:name="t('logreader', 'No log entries')"
36+
:description="t('logreader', 'The log is currently empty. Try to select a different logging level.')">
3537
<template #icon>
3638
<IconFormatList :size="20" />
3739
</template>
38-
<template #description>
39-
{{ t('logreader', 'File-based logging must be enabled to access logs from the Web UI.') }}
40-
<br>
41-
<!-- eslint-disable-next-line vue/no-v-html -->
42-
<span v-html="noLogDescription" />
43-
</template>
4440
</NcEmptyContent>
4541
<!-- App settings dialog will be mounted on page body -->
4642
<AppSettingsDialog :open.sync="areSettingsShown" />
@@ -74,6 +70,8 @@ const loggingStore = useLogStore()
7470
7571
const entries = computed(() => loggingStore.entries)
7672
73+
const hasEntries = computed(() => loggingStore.allEntries.length > 0)
74+
7775
const onShowServerLog = () => {
7876
settingsStore.localFile = undefined
7977
// remove local entries
@@ -99,21 +97,6 @@ onMounted(() => {
9997
onUnmounted(() => {
10098
loggingStore.stopPolling()
10199
})
102-
103-
/** Translated description what to check in case no log can be loaded */
104-
const noLogDescription = t(
105-
'logreader',
106-
'If you feel this is an error, please verify {setting} in your {config} and check the Nextcloud Administration Manual.',
107-
{
108-
setting: '<code>log_type</code>',
109-
config: '<code>config.php</code>',
110-
},
111-
0,
112-
{
113-
sanitize: false,
114-
escape: false,
115-
},
116-
)
117100
</script>
118101

119102
<style lang="scss" scoped>

src/interfaces/IAppSettings.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,4 @@ export interface IAppSettings {
2323
* Wether the log should be polled
2424
*/
2525
liveLog: boolean
26-
/**
27-
* Wether backend is enable = logging is set to file
28-
*/
29-
enabled: boolean
3026
}

src/store/logging.spec.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ describe('store:logging', () => {
5353
// Mock server settings
5454
mockInitialState({
5555
dateTimeFormat: 'local',
56-
enabled: true,
5756
liveLog: true,
5857
shownLevels: [2, 4],
5958
})

src/store/logging.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export const useLogStore = defineStore('logreader-logs', () => {
6565
*/
6666
async function loadMore(older = true) {
6767
// Nothing to do if server logging is disabled
68-
if (!_settings.isEnabled) return
68+
if (!_settings.isServerLogShown) return
6969

7070
// Only load any entries if there is no previous unfinished request
7171
if (!(_loading.value = !_loading.value)) return
@@ -117,7 +117,7 @@ export const useLogStore = defineStore('logreader-logs', () => {
117117
const doPolling = async () => {
118118
try {
119119
// Only poll if not using a local file
120-
if (_settings.isEnabled && query.value === '') {
120+
if (_settings.isServerLogShown && query.value === '') {
121121
const { data } = await pollLog({ lastReqId: allEntries.value[0]?.reqId || '' })
122122
allEntries.value.splice(0, 0, ...data.map(parseRawLogEntry))
123123
}
@@ -153,7 +153,7 @@ export const useLogStore = defineStore('logreader-logs', () => {
153153
query.value = search
154154

155155
// if query changed and server logging is enabled, request new entries
156-
if (search !== oldQuery && _settings.isEnabled) {
156+
if (search !== oldQuery && _settings.isServerLogShown) {
157157
_loading.value = true
158158

159159
try {

src/store/settings.spec.ts

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ describe('store:settings', () => {
3737
beforeAll(() => {
3838
initialState = mockInitialState({
3939
dateTimeFormat: 'local',
40-
enabled: true,
4140
liveLog: true,
4241
shownLevels: [2, 4],
4342
})
@@ -51,7 +50,6 @@ describe('store:settings', () => {
5150

5251
it('loads state from inital-state', () => {
5352
const store = useSettingsStore()
54-
expect(store.enabled).toBe(true)
5553
expect(store.liveLog).toBe(true)
5654
expect(store.shownLevels).toEqual([2, 4])
5755
expect(store.dateTimeFormat).toBe('local')
@@ -73,16 +71,10 @@ describe('store:settings', () => {
7371
it('only enable server logs if available', () => {
7472
const store = useSettingsStore()
7573
// should be enabled currently
76-
expect(store.isEnabled).toBeTruthy()
77-
// server is configured to not use file logs -> enabled=false -> it is disabled
78-
store.enabled = false
79-
expect(store.isEnabled).toBeFalsy()
74+
expect(store.isServerLogShown).toBeTruthy()
8075
// If a local file is used it is disabled too
8176
store.localFile = new File([], 'log')
82-
expect(store.isEnabled).toBeFalsy()
83-
// Also if enabled but a local log file is used we should not fetch from server
84-
store.enabled = true
85-
expect(store.isEnabled).toBeFalsy()
77+
expect(store.isServerLogShown).toBeFalsy()
8678
})
8779

8880
it('sets the state when settings are changed', async () => {
@@ -128,7 +120,6 @@ describe('store:settings', () => {
128120
return {
129121
data: {
130122
dateTimeFormat: 'utc',
131-
enabled: false,
132123
liveLog: false,
133124
shownLevels: [1, 3],
134125
},
@@ -141,12 +132,10 @@ describe('store:settings', () => {
141132
expect(mocks.getAppSettings).toBeCalled()
142133
expect(settings).toEqual({
143134
dateTimeFormat: 'utc',
144-
enabled: false,
145135
liveLog: false,
146136
shownLevels: [1, 3],
147137
})
148138
expect(store.dateTimeFormat).toBe('utc')
149-
expect(store.enabled).toBe(false)
150139
expect(store.liveLog).toBe(false)
151140
expect(store.shownLevels).toEqual([1, 3])
152141
})

src/store/settings.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,13 @@ export const useSettingsStore = defineStore('logreader-settings', () => {
2424
/**
2525
* Saved setting loaded from server
2626
*/
27-
const _loadedSettings = loadState<SettingsState>('logreader', 'settings', { enabled: false, liveLog: false, dateTimeFormat: 'raw', shownLevels: [] })
28-
29-
/**
30-
* Is file logging enabled on server
31-
*/
32-
const enabled = ref(_loadedSettings.enabled)
27+
const _loadedSettings = loadState<SettingsState>('logreader', 'settings', { liveLog: false, dateTimeFormat: 'raw', shownLevels: [] })
3328

3429
/**
3530
* Wether we should load log entries from server
36-
* This checks if file logging is enabled and if a local file is currently shown
31+
* This checks if a local file is currently shown
3732
*/
38-
const isEnabled = computed(() => enabled.value && localFile.value === undefined)
33+
const isServerLogShown = computed(() => localFile.value === undefined)
3934

4035
/**
4136
* Is live log aka polling enabled
@@ -102,5 +97,5 @@ export const useSettingsStore = defineStore('logreader-settings', () => {
10297
return settings.data
10398
}
10499

105-
return { shownLevels, dateTimeFormat, enabled, isEnabled, liveLog, localFile, localFileName, setSetting, getSettings }
100+
return { shownLevels, dateTimeFormat, isServerLogShown, liveLog, localFile, localFileName, setSetting, getSettings }
106101
})

tests/Unit/Controller/SettingsControllerTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,13 @@ public function testGetAppConfig() {
7979
Constants::CONFIG_KEY_DATETIMEFORMAT => 'local',
8080
Constants::CONFIG_KEY_RELATIVEDATES => false,
8181
Constants::CONFIG_KEY_LIVELOG => true,
82-
'enabled' => true,
8382
]);
8483

8584
$this->assertEquals(new JSONResponse([
8685
Constants::CONFIG_KEY_SHOWNLEVELS => Constants::LOGGING_LEVELS,
8786
Constants::CONFIG_KEY_DATETIMEFORMAT => 'local',
8887
Constants::CONFIG_KEY_RELATIVEDATES => false,
8988
Constants::CONFIG_KEY_LIVELOG => true,
90-
'enabled' => true,
9189
]), $this->settingsController->getAppConfig());
9290
}
9391

@@ -127,7 +125,6 @@ public function testUpdateAppConfig(string $configKey, $configValue, string $str
127125
Constants::CONFIG_KEY_DATETIMEFORMAT => 'local',
128126
Constants::CONFIG_KEY_RELATIVEDATES => false,
129127
Constants::CONFIG_KEY_LIVELOG => true,
130-
'enabled' => true,
131128
]);
132129

133130
$this->assertEquals(new JSONResponse(), $this->settingsController->updateAppConfig($configKey, $configValue));
@@ -155,7 +152,6 @@ public function testUpdateAppConfig_invalidType() {
155152
Constants::CONFIG_KEY_DATETIMEFORMAT => 'local',
156153
Constants::CONFIG_KEY_RELATIVEDATES => false,
157154
Constants::CONFIG_KEY_LIVELOG => true,
158-
'enabled' => true,
159155
]);
160156
$this->assertEquals(new JSONResponse([], Http::STATUS_BAD_REQUEST), $this->settingsController->updateAppConfig(Constants::CONFIG_KEY_SHOWNLEVELS, 'debug'));
161157
}
@@ -173,7 +169,6 @@ public function testUpdateAppConfig_invalidLevel() {
173169
Constants::CONFIG_KEY_DATETIMEFORMAT => 'local',
174170
Constants::CONFIG_KEY_RELATIVEDATES => false,
175171
Constants::CONFIG_KEY_LIVELOG => true,
176-
'enabled' => true,
177172
]);
178173

179174
$this->assertEquals(new JSONResponse([], Http::STATUS_BAD_REQUEST), $this->settingsController->updateAppConfig(Constants::CONFIG_KEY_SHOWNLEVELS, ['debug']));

0 commit comments

Comments
 (0)