add: achievement toggle

Closes #16
This commit is contained in:
Mar0xy 2023-09-29 00:57:38 +02:00
parent 0c7011bd02
commit fc00f08d5b
No known key found for this signature in database
GPG key ID: 56569BBE47D2C828
9 changed files with 45 additions and 1 deletions

View file

@ -0,0 +1,11 @@
export class EnableAchievements1695937489995 {
name = 'EnableAchievements1695937489995'
async up(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" ADD "enableAchievements" boolean NOT NULL DEFAULT true`);
}
async down(queryRunner) {
await queryRunner.query(`ALTER TABLE "meta" DROP COLUMN "enableAchievements"`);
}
}

View file

@ -449,6 +449,11 @@ export class MiMeta {
}) })
public enableIdenticonGeneration: boolean; public enableIdenticonGeneration: boolean;
@Column('boolean', {
default: true,
})
public enableAchievements: boolean;
@Column('jsonb', { @Column('jsonb', {
default: { }, default: { },
}) })

View file

@ -282,6 +282,10 @@ export const meta = {
type: 'boolean', type: 'boolean',
optional: false, nullable: false, optional: false, nullable: false,
}, },
enableAchievements: {
type: 'boolean',
optional: false, nullable: false,
},
enableIdenticonGeneration: { enableIdenticonGeneration: {
type: 'boolean', type: 'boolean',
optional: false, nullable: false, optional: false, nullable: false,
@ -396,6 +400,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
enableChartsForRemoteUser: instance.enableChartsForRemoteUser, enableChartsForRemoteUser: instance.enableChartsForRemoteUser,
enableChartsForFederatedInstances: instance.enableChartsForFederatedInstances, enableChartsForFederatedInstances: instance.enableChartsForFederatedInstances,
enableServerMachineStats: instance.enableServerMachineStats, enableServerMachineStats: instance.enableServerMachineStats,
enableAchievements: instance.enableAchievements,
enableIdenticonGeneration: instance.enableIdenticonGeneration, enableIdenticonGeneration: instance.enableIdenticonGeneration,
policies: { ...DEFAULT_POLICIES, ...instance.policies }, policies: { ...DEFAULT_POLICIES, ...instance.policies },
manifestJsonOverride: instance.manifestJsonOverride, manifestJsonOverride: instance.manifestJsonOverride,

View file

@ -104,6 +104,7 @@ export const paramDef = {
enableChartsForRemoteUser: { type: 'boolean' }, enableChartsForRemoteUser: { type: 'boolean' },
enableChartsForFederatedInstances: { type: 'boolean' }, enableChartsForFederatedInstances: { type: 'boolean' },
enableServerMachineStats: { type: 'boolean' }, enableServerMachineStats: { type: 'boolean' },
enableAchievements: { type: 'boolean' },
enableIdenticonGeneration: { type: 'boolean' }, enableIdenticonGeneration: { type: 'boolean' },
serverRules: { type: 'array', items: { type: 'string' } }, serverRules: { type: 'array', items: { type: 'string' } },
preservedUsernames: { type: 'array', items: { type: 'string' } }, preservedUsernames: { type: 'array', items: { type: 'string' } },
@ -425,6 +426,10 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
set.enableServerMachineStats = ps.enableServerMachineStats; set.enableServerMachineStats = ps.enableServerMachineStats;
} }
if (ps.enableAchievements !== undefined) {
set.enableAchievements = ps.enableAchievements;
}
if (ps.enableIdenticonGeneration !== undefined) { if (ps.enableIdenticonGeneration !== undefined) {
set.enableIdenticonGeneration = ps.enableIdenticonGeneration; set.enableIdenticonGeneration = ps.enableIdenticonGeneration;
} }

View file

@ -6,6 +6,7 @@
import { Injectable } from '@nestjs/common'; import { Injectable } from '@nestjs/common';
import { Endpoint } from '@/server/api/endpoint-base.js'; import { Endpoint } from '@/server/api/endpoint-base.js';
import { AchievementService, ACHIEVEMENT_TYPES } from '@/core/AchievementService.js'; import { AchievementService, ACHIEVEMENT_TYPES } from '@/core/AchievementService.js';
import { MetaService } from '@/core/MetaService.js';
export const meta = { export const meta = {
requireCredential: true, requireCredential: true,
@ -24,8 +25,12 @@ export const paramDef = {
export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-disable-line import/no-default-export
constructor( constructor(
private achievementService: AchievementService, private achievementService: AchievementService,
private metaService: MetaService,
) { ) {
super(meta, paramDef, async (ps, me) => { super(meta, paramDef, async (ps, me) => {
const meta = await this.metaService.fetch();
if (!meta.enableAchievements) return;
await this.achievementService.create(me.id, ps.name); await this.achievementService.create(me.id, ps.name);
}); });
} }

View file

@ -304,6 +304,7 @@ export default class extends Endpoint<typeof meta, typeof paramDef> { // eslint-
enableHcaptcha: instance.enableHcaptcha, enableHcaptcha: instance.enableHcaptcha,
hcaptchaSiteKey: instance.hcaptchaSiteKey, hcaptchaSiteKey: instance.hcaptchaSiteKey,
enableRecaptcha: instance.enableRecaptcha, enableRecaptcha: instance.enableRecaptcha,
enableAchievements: instance.enableAchievements,
recaptchaSiteKey: instance.recaptchaSiteKey, recaptchaSiteKey: instance.recaptchaSiteKey,
enableTurnstile: instance.enableTurnstile, enableTurnstile: instance.enableTurnstile,
turnstileSiteKey: instance.turnstileSiteKey, turnstileSiteKey: instance.turnstileSiteKey,

View file

@ -12,6 +12,7 @@ import * as os from '@/os.js';
import { i18n } from '@/i18n.js'; import { i18n } from '@/i18n.js';
import { ui } from '@/config.js'; import { ui } from '@/config.js';
import { unisonReload } from '@/scripts/unison-reload.js'; import { unisonReload } from '@/scripts/unison-reload.js';
import { instance } from './instance.js';
export const navbarItemDef = reactive({ export const navbarItemDef = reactive({
notifications: { notifications: {
@ -104,7 +105,7 @@ export const navbarItemDef = reactive({
achievements: { achievements: {
title: i18n.ts.achievements, title: i18n.ts.achievements,
icon: 'ti ti-medal', icon: 'ti ti-medal',
show: computed(() => $i != null), show: computed(() => $i != null && instance.enableAchievements),
to: '/my/achievements', to: '/my/achievements',
}, },
ui: { ui: {

View file

@ -16,6 +16,13 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkSwitch> </MkSwitch>
</div> </div>
<div class="_panel" style="padding: 16px;">
<MkSwitch v-model="enableAchievements">
<template #label>Enable Achievements</template>
<template #caption>Turning this off will disable the achievement system</template>
</MkSwitch>
</div>
<div class="_panel" style="padding: 16px;"> <div class="_panel" style="padding: 16px;">
<MkSwitch v-model="enableIdenticonGeneration"> <MkSwitch v-model="enableIdenticonGeneration">
<template #label>{{ i18n.ts.enableIdenticonGeneration }}</template> <template #label>{{ i18n.ts.enableIdenticonGeneration }}</template>
@ -53,6 +60,7 @@ import { definePageMetadata } from '@/scripts/page-metadata.js';
import MkSwitch from '@/components/MkSwitch.vue'; import MkSwitch from '@/components/MkSwitch.vue';
let enableServerMachineStats: boolean = $ref(false); let enableServerMachineStats: boolean = $ref(false);
let enableAchievements: boolean = $ref(false);
let enableIdenticonGeneration: boolean = $ref(false); let enableIdenticonGeneration: boolean = $ref(false);
let enableChartsForRemoteUser: boolean = $ref(false); let enableChartsForRemoteUser: boolean = $ref(false);
let enableChartsForFederatedInstances: boolean = $ref(false); let enableChartsForFederatedInstances: boolean = $ref(false);
@ -60,6 +68,7 @@ let enableChartsForFederatedInstances: boolean = $ref(false);
async function init() { async function init() {
const meta = await os.api('admin/meta'); const meta = await os.api('admin/meta');
enableServerMachineStats = meta.enableServerMachineStats; enableServerMachineStats = meta.enableServerMachineStats;
enableAchievements = meta.enableAchievements;
enableIdenticonGeneration = meta.enableIdenticonGeneration; enableIdenticonGeneration = meta.enableIdenticonGeneration;
enableChartsForRemoteUser = meta.enableChartsForRemoteUser; enableChartsForRemoteUser = meta.enableChartsForRemoteUser;
enableChartsForFederatedInstances = meta.enableChartsForFederatedInstances; enableChartsForFederatedInstances = meta.enableChartsForFederatedInstances;
@ -68,6 +77,7 @@ async function init() {
function save() { function save() {
os.apiWithDialog('admin/update-meta', { os.apiWithDialog('admin/update-meta', {
enableServerMachineStats, enableServerMachineStats,
enableAchievements,
enableIdenticonGeneration, enableIdenticonGeneration,
enableChartsForRemoteUser, enableChartsForRemoteUser,
enableChartsForFederatedInstances, enableChartsForFederatedInstances,

View file

@ -344,6 +344,7 @@ export type LiteInstanceMetadata = {
enableTwitterIntegration: boolean; enableTwitterIntegration: boolean;
enableGithubIntegration: boolean; enableGithubIntegration: boolean;
enableDiscordIntegration: boolean; enableDiscordIntegration: boolean;
enableAchievements: boolean;
enableServiceWorker: boolean; enableServiceWorker: boolean;
emojis: CustomEmoji[]; emojis: CustomEmoji[];
defaultDarkTheme: string | null; defaultDarkTheme: string | null;