Skip to content

ActivityPub-federated video streaming platform using P2P directly in your web browser

Add missing download enabled default in admin

Chocobozzz3fb3899efdc1
diff --git a/client/src/app/+admin/config/pages/admin-config-general.component.html b/client/src/app/+admin/config/pages/admin-config-general.component.html
index 3e04bf3a96..1f5ea5ddae 100644
--- a/client/src/app/+admin/config/pages/admin-config-general.component.html
+++ b/client/src/app/+admin/config/pages/admin-config-general.component.html
@@ -524,6 +524,17 @@
<div class="form-error" role="alert">{{ formErrors.defaults.publish.commentsPolicy }}</div>
}
</div>
+
+
+ <div class="form-group">
+ <label i18n for="defaultsDownloadPolicy">Default download policy</label>
+
+ <my-select-options inputId="defaultsDownloadPolicy" [items]="downloadPoliciesOptions" formControlName="downloadPolicy"></my-select-options>
+
+ @if (formErrors.defaults.publish.downloadPolicy) {
+ <div class="form-error" role="alert">{{ formErrors.defaults.publish.downloadPolicy }}</div>
+ }
+ </div>
</ng-container>
</ng-container>
</div>
diff --git a/client/src/app/+admin/config/pages/admin-config-general.component.ts b/client/src/app/+admin/config/pages/admin-config-general.component.ts
index 6bc8152a3e..fd1a285e1e 100644
--- a/client/src/app/+admin/config/pages/admin-config-general.component.ts
+++ b/client/src/app/+admin/config/pages/admin-config-general.component.ts
@@ -24,7 +24,8 @@ import { USER_VIDEO_QUOTA_DAILY_VALIDATOR, USER_VIDEO_QUOTA_VALIDATOR } from '@a
import { FormReactiveService } from '@app/shared/shared-forms/form-reactive.service'
import { AlertComponent } from '@app/shared/shared-main/common/alert.component'
import { VideoService } from '@app/shared/shared-main/video/video.service'
-import { BroadcastMessageLevel, CustomConfig, VideoCommentPolicyType, ConstantLabel, VideoPrivacyType } from '@peertube/peertube-models'
+import { BroadcastMessageLevel, ConstantLabel, CustomConfig, VideoCommentPolicyType, VideoPrivacyType } from '@peertube/peertube-models'
+import merge from 'lodash-es/merge'
import { Subscription } from 'rxjs'
import { pairwise } from 'rxjs/operators'
import { SelectOptionsItem } from 'src/types/select-options-item.model'
@@ -38,6 +39,9 @@ import { SelectVideosSortComponent } from '../../../shared/shared-forms/select/s
import { HelpComponent } from '../../../shared/shared-main/buttons/help.component'
import { UserRealQuotaInfoComponent } from '../../shared/user-real-quota-info.component'
import { AdminSaveBarComponent } from '../shared/admin-save-bar.component'
+import { PartialDeep } from 'type-fest'
+
+type DownloadPolicy = 'allowed' | 'disabled'
type Form = {
instance: FormGroup<{
@@ -190,6 +194,7 @@ type Form = {
defaults: FormGroup<{
publish: FormGroup<{
+ downloadPolicy: FormControl<DownloadPolicy>
commentsPolicy: FormControl<VideoCommentPolicyType>
privacy: FormControl<VideoPrivacyType>
licence: FormControl<number>
@@ -255,6 +260,10 @@ export class AdminConfigGeneralComponent implements OnInit, OnDestroy, CanCompon
privacyOptions: SelectOptionsItem[] = []
commentPoliciesOptions: SelectOptionsItem[] = []
+ downloadPoliciesOptions: SelectOptionsItem<DownloadPolicy>[] = [
+ { id: 'allowed', label: $localize`Allowed` },
+ { id: 'disabled', label: $localize`Disabled` }
+ ]
licenceOptions: SelectOptionsItem[] = []
private customConfig: CustomConfig
@@ -294,7 +303,7 @@ export class AdminConfigGeneralComponent implements OnInit, OnDestroy, CanCompon
.subscribe(customConfig => {
this.customConfig = customConfig
- this.form.patchValue(this.customConfig)
+ this.form.patchValue(this.buildFormValue(this.customConfig))
})
}
@@ -434,6 +443,7 @@ export class AdminConfigGeneralComponent implements OnInit, OnDestroy, CanCompon
},
defaults: {
publish: {
+ downloadPolicy: null,
commentsPolicy: null,
privacy: null,
licence: null
@@ -455,7 +465,7 @@ export class AdminConfigGeneralComponent implements OnInit, OnDestroy, CanCompon
}
}
- const defaultValues: FormDefaultTyped<Form> = this.customConfig
+ const defaultValues: FormDefaultTyped<Form> = this.buildFormValue(this.customConfig)
const {
form,
@@ -468,6 +478,21 @@ export class AdminConfigGeneralComponent implements OnInit, OnDestroy, CanCompon
this.validationMessages = validationMessages
}
+ private buildFormValue (customConfig: CustomConfig) {
+ return merge(
+ customConfig,
+ {
+ defaults: {
+ publish: {
+ downloadPolicy: customConfig.defaults.publish.downloadEnabled
+ ? 'allowed'
+ : 'disabled'
+ }
+ }
+ } satisfies PartialDeep<FormDefaultTyped<Form>>
+ )
+ }
+
canDeactivate () {
return { canDeactivate: !this.form.dirty }
}
@@ -622,7 +647,16 @@ export class AdminConfigGeneralComponent implements OnInit, OnDestroy, CanCompon
this.adminConfigService.saveAndUpdateCurrent({
currentConfig: this.customConfig,
form: this.form,
- formConfig: this.form.value,
+ formConfig: merge(
+ this.form.value,
+ {
+ defaults: {
+ publish: {
+ downloadEnabled: this.form.value.defaults.publish.downloadPolicy === 'allowed'
+ }
+ }
+ } satisfies PartialDeep<CustomConfig>
+ ),
success: $localize`General configuration updated.`
})
}