fix: use iAmAdmin, iAmModerator instead of $i.isAdmin value

This commit is contained in:
オスカー、 2024-08-13 16:54:28 +09:00
parent ab68d1f75e
commit 8f66932737
Signed by: SWREI
GPG Key ID: 139D6573F92DA9F7
20 changed files with 50 additions and 51 deletions

8
locales/index.d.ts vendored
View File

@ -4012,6 +4012,14 @@ export interface Locale extends ILocale {
* Botアカウントでログイン中
*/
"loggedInAsBot": string;
/**
* Botアカウント
*/
"isBot": string;
/**
*
*/
"isLocked": string;
/**
*
*/

View File

@ -999,6 +999,8 @@ windowMinimize: "最小化"
windowRestore: "元に戻す"
caption: "キャプション"
loggedInAsBot: "Botアカウントでログイン中"
isBot: "Botアカウント"
isLocked: "フォロー申請が必要"
tools: "ツール"
cannotLoad: "読み込めません"
numberOfProfileView: "プロフィール表示回数"

View File

@ -996,6 +996,8 @@ windowMinimize: "최소화"
windowRestore: "복구"
caption: "캡션"
loggedInAsBot: "봇 계정으로 로그인 중"
isBot: "봇"
isLocked: "팔로우 요청 필요"
tools: "도구"
cannotLoad: "불러오지 못했습니다"
numberOfProfileView: "프로필 뷰 수"

View File

@ -1,6 +1,6 @@
{
"name": "misskey",
"version": "2024.5.0-oscar.9b",
"version": "2024.5.0-oscar.10",
"codename": "nasubi",
"repository": {
"type": "git",

View File

@ -310,7 +310,7 @@ export class ApiCallService implements OnApplicationShutdown {
}
}
if (ep.meta.requireModerator || ep.meta.requireAdmin) {
if ((ep.meta.requireModerator || ep.meta.requireAdmin) && !user!.isRoot) {
const myRoles = await this.roleService.getUserRoles(user!.id);
const isModerator = myRoles.some(r => r.isModerator || r.isAdministrator);
const isAdmin = myRoles.some(r => r.isAdministrator);
@ -324,14 +324,6 @@ export class ApiCallService implements OnApplicationShutdown {
id: 'abce13fe-1d9f-4e85-8f00-4a5251155470',
});
}
if (!user!.isRoot) {
throw new ApiError({
message: 'You are not assigned to a proper role.',
code: 'ROLE_PERMISSION_DENIED',
kind: 'permission',
id: 'd33d5333-db36-423d-a8f9-1a2b9549da41',
});
}
if (ep.meta.requireModerator && !isModerator) {
throw new ApiError({
message: 'You are not assigned to a proper role.',

View File

@ -24,8 +24,8 @@ const accountData = miLocalStorage.getItem('account');
// TODO: 外部からはreadonlyに
export const $i = accountData ? reactive(JSON.parse(accountData) as Account) : null;
export const iAmModerator = $i != null && ($i.isAdmin === true || $i.isModerator === true);
export const iAmAdmin = $i != null && $i.isAdmin;
export const iAmModerator = $i != null && ($i.isAdmin === true || $i.isModerator === true) && $i.twoFactorEnabled;
export const iAmAdmin = $i != null && $i.isAdmin && $i.twoFactorEnabled;
export function signinRequired() {
if ($i == null) throw new Error('signin required');

View File

@ -5,7 +5,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template>
<div class="_gaps">
<MkButton v-if="$i && ($i.isModerator || $i.policies.canManageCustomEmojis)" primary link to="/custom-emojis-manager">{{ i18n.ts.manageCustomEmojis }}</MkButton>
<MkButton v-if="$i && (iAmAdmin || $i.policies.canManageCustomEmojis)" primary link to="/custom-emojis-manager">{{ i18n.ts.manageCustomEmojis }}</MkButton>
<div class="query">
<MkInput v-model="q" class="" :placeholder="i18n.ts.search" autocapitalize="off">
@ -44,7 +44,7 @@ import MkInput from '@/components/MkInput.vue';
import MkFoldableSection from '@/components/MkFoldableSection.vue';
import { customEmojis, customEmojiCategories, getCustomEmojiTags } from '@/custom-emojis.js';
import { i18n } from '@/i18n.js';
import { $i } from '@/account.js';
import { $i, iAmAdmin } from '@/account.js';
const customEmojiTags = getCustomEmojiTags();
const q = ref('');

View File

@ -196,7 +196,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</div>
<div v-else-if="tab === 'raw'" class="_gaps_m">
<MkObjectView v-if="info && $i.isAdmin" tall :value="info">
<MkObjectView v-if="info && iAmAdmin" tall :value="info">
</MkObjectView>
<MkObjectView tall :value="user">
@ -229,7 +229,7 @@ import { url } from '@/config.js';
import { acct } from '@/filters/user.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { i18n } from '@/i18n.js';
import { iAmAdmin, iAmModerator, $i } from '@/account.js';
import { iAmAdmin, iAmModerator } from '@/account.js';
import MkRolePreview from '@/components/MkRolePreview.vue';
import MkPagination from '@/components/MkPagination.vue';

View File

@ -8,7 +8,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<template #header>
<MkPageHeader/>
</template>
<MKSpacer v-if="!instance.disableRegistration || !($i && ($i.isAdmin || $i.policies.canInvite))" :contentMax="1200">
<MKSpacer v-if="!instance.disableRegistration || !($i && (iAmAdmin || $i.policies.canInvite))" :contentMax="1200">
<div :class="$style.root">
<img :class="$style.img" :src="serverErrorImageUrl" class="_ghost"/>
<div :class="$style.text">
@ -46,7 +46,7 @@ import MkPagination, { Paging } from '@/components/MkPagination.vue';
import MkInviteCode from '@/components/MkInviteCode.vue';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { serverErrorImageUrl, instance } from '@/instance.js';
import { $i } from '@/account.js';
import { $i, iAmAdmin } from '@/account.js';
const pagingComponent = shallowRef<InstanceType<typeof MkPagination>>();
const currentInviteLimit = ref<null | number>(null);

View File

@ -109,11 +109,11 @@ SPDX-License-Identifier: AGPL-3.0-only
</MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;">
<template #key>isModerator</template>
<template #value>{{ $i.isModerator ? i18n.ts.yes : i18n.ts.no }}</template>
<template #value>{{ iAmModerator ? i18n.ts.yes : i18n.ts.no }}</template>
</MkKeyValue>
<MkKeyValue oneline style="margin: 1em 0;">
<template #key>isAdmin</template>
<template #value>{{ $i.isAdmin ? i18n.ts.yes : i18n.ts.no }}</template>
<template #value>{{ iAmAdmin ? i18n.ts.yes : i18n.ts.no }}</template>
</MkKeyValue>
</FormSection>
</div>
@ -125,7 +125,7 @@ import FormSection from '@/components/form/section.vue';
import MkKeyValue from '@/components/MkKeyValue.vue';
import number from '@/filters/number.js';
import bytes from '@/filters/bytes.js';
import { $i } from '@/account.js';
import { $i, iAmAdmin, iAmModerator } from '@/account.js';
import { i18n } from '@/i18n.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { misskeyApi } from '@/scripts/misskey-api.js';

View File

@ -23,9 +23,9 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkUserName class="name" :user="user" :nowrap="true"/>
<div class="bottom">
<span class="username"><MkAcct :user="user" :detail="true"/></span>
<span v-if="user.isAdmin" :title="i18n.ts.isAdmin" style="color: var(--badge);"><i class="ti ti-shield"></i></span>
<span v-if="user.isLocked" :title="i18n.ts.isLocked"><i class="ti ti-lock"></i></span>
<span v-if="user.isBot" :title="i18n.ts.isBot"><i class="ti ti-robot"></i></span>
<span v-if="user.isAdmin" v-tooltip.noDelay="i18n.ts.administrator" style="color: var(--badge);"><i class="ti ti-shield"></i></span>
<span v-if="user.isLocked" v-tooltip.noDelay="i18n.ts.isLocked"><i class="ti ti-lock"></i></span>
<span v-if="user.isBot" v-tooltip.noDelay="i18n.ts.isBot"><i class="ti ti-robot"></i></span>
<button v-if="$i && !isEditingMemo && !memoDraft" class="_button add-note-button" @click="showMemoTextarea">
<i class="ti ti-edit"/> {{ i18n.ts.addMemo }}
</button>
@ -42,7 +42,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<MkUserName :user="user" :nowrap="false" class="name"/>
<div class="bottom">
<span class="username"><MkAcct :user="user" :detail="true"/></span>
<span v-if="user.isAdmin" :title="i18n.ts.isAdmin" style="color: var(--badge);"><i class="ti ti-shield"></i></span>
<span v-if="user.isAdmin" :title="i18n.ts.administrator" style="color: var(--badge);"><i class="ti ti-shield"></i></span>
<span v-if="user.isLocked" :title="i18n.ts.isLocked"><i class="ti ti-lock"></i></span>
<span v-if="user.isBot" :title="i18n.ts.isBot"><i class="ti ti-robot"></i></span>
</div>

View File

@ -43,7 +43,7 @@ import { acct as getAcct } from '@/filters/user.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { definePageMetadata } from '@/scripts/page-metadata.js';
import { i18n } from '@/i18n.js';
import { $i } from '@/account.js';
import { $i, iAmModerator } from '@/account.js';
import MkUserNotFound from '@/components/MkUserNotFound.vue';
import MkUserSuspended from '@/components/MkUserSuspended.vue';
import MkHorizontalSwipe from '@/components/MkHorizontalSwipe.vue';
@ -111,7 +111,7 @@ const headerTabs = computed(() => user.value ? [{
key: 'achievements',
title: i18n.ts.achievements,
icon: 'ti ti-medal',
}] : []), ...($i && ($i.id === user.value.id || $i.isAdmin || $i.isModerator)) || user.value.publicReactions ? [{
}] : []), ...($i && ($i.id === user.value.id || iAmModerator )) || user.value.publicReactions ? [{
key: 'reactions',
title: i18n.ts.reaction,
icon: 'ti ti-mood-happy',

View File

@ -6,7 +6,7 @@
import { defineAsyncComponent, Ref, ShallowRef } from 'vue';
import * as Misskey from 'misskey-js';
import { claimAchievement } from './achievements.js';
import { $i } from '@/account.js';
import { $i, iAmModerator } from '@/account.js';
import { i18n } from '@/i18n.js';
import { instance } from '@/instance.js';
import * as os from '@/os.js';
@ -372,7 +372,7 @@ export function getNoteMenu(props: {
},
},
/*
...($i.isModerator || $i.isAdmin ? [
...(iAmModerator ? [
{ type: 'divider' },
{
icon: 'ti ti-speakerphone',
@ -387,7 +387,7 @@ export function getNoteMenu(props: {
]
: []
),
...(appearNote.channel && (appearNote.channel.userId === $i.id || $i.isModerator || $i.isAdmin) ? [
...(appearNote.channel && (appearNote.channel.userId === $i.id || iAmModerator) ? [
{ type: 'divider' },
{
type: 'parent' as const,
@ -423,7 +423,7 @@ export function getNoteMenu(props: {
]
: []
),
...(appearNote.userId === $i.id || $i.isModerator || $i.isAdmin ? [
...(appearNote.userId === $i.id || iAmModerator ? [
{ type: 'divider' },
appearNote.userId === $i.id ? {
icon: 'ti ti-edit',

View File

@ -51,13 +51,13 @@ SPDX-License-Identifier: AGPL-3.0-only
import { ref } from 'vue';
import { instanceName } from '@/config.js';
import { instance } from '@/instance.js';
import { $i } from '@/account.js';
import { $i, iAmModerator } from '@/account.js';
import { i18n } from '@/i18n.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
const unresolvedReportCount = ref<number>(0);
if ($i?.isAdmin || $i?.isModerator) {
if (iAmModerator) {
misskeyApi('admin/abuse-user-reports', {
state: 'unresolved',
}).then(reports => {

View File

@ -3,13 +3,12 @@
* SPDX-License-Identifier: AGPL-3.0-only
*/
import { defineAsyncComponent } from 'vue';
import type { MenuItem } from '@/types/menu.js';
import * as os from '@/os.js';
import { instance } from '@/instance.js';
import { host } from '@/config.js';
import { i18n } from '@/i18n.js';
import { $i } from '@/account.js';
import { $i, iAmAdmin } from '@/account.js';
import { defaultStore } from '@/store.js';
function toolsMenuItems(): MenuItem[] {
@ -28,12 +27,12 @@ function toolsMenuItems(): MenuItem[] {
to: '/clicker',
text: '🍪👈',
icon: 'ti ti-cookie',
}, ($i && ($i.isAdmin || $i.policies.canManageCustomEmojis)) ? {
}, ($i && (iAmAdmin || $i.policies.canManageCustomEmojis)) ? {
type: 'link',
to: '/custom-emojis-manager',
text: i18n.ts.manageCustomEmojis,
icon: 'ti ti-icons',
} : undefined, ($i && ($i.isAdmin || $i.policies.canManageAvatarDecorations)) ? {
} : undefined, ($i && (iAmAdmin || $i.policies.canManageAvatarDecorations)) ? {
type: 'link',
to: '/avatar-decorations',
text: i18n.ts.manageAvatarDecorations,
@ -70,7 +69,7 @@ export function openInstanceMenu(ev: MouseEvent) {
text: i18n.ts.ads,
icon: 'ti ti-ad',
to: '/ads',
}, ($i && ($i.isAdmin || $i.policies.canInvite) && instance.disableRegistration) ? {
}, ($i && (iAmAdmin || $i.policies.canInvite) && instance.disableRegistration) ? {
type: 'link',
to: '/invite',
text: i18n.ts.invite,

View File

@ -27,7 +27,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</component>
</template>
<div :class="$style.divider"></div>
<MkA v-if="$i.isAdmin || $i.isModerator" :class="$style.item" :activeClass="$style.active" to="/admin">
<MkA v-if="iAmModerator" :class="$style.item" :activeClass="$style.active" to="/admin">
<i :class="$style.itemIcon" class="ti ti-dashboard ti-fw"></i><span :class="$style.itemText">{{ i18n.ts.controlPanel }}</span>
</MkA>
<button :class="$style.item" class="_button" @click="more">
@ -54,7 +54,7 @@ import { computed, defineAsyncComponent, toRef } from 'vue';
import { openInstanceMenu } from './common.js';
import * as os from '@/os.js';
import { navbarItemDef } from '@/navbar.js';
import { $i, openAccountMenu as openAccountMenu_ } from '@/account.js';
import { $i, iAmModerator, openAccountMenu as openAccountMenu_ } from '@/account.js';
import { defaultStore } from '@/store.js';
import { i18n } from '@/i18n.js';
import { instance } from '@/instance.js';

View File

@ -37,7 +37,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</component>
</template>
<div :class="$style.divider"></div>
<MkA v-if="$i.isAdmin || $i.isModerator" v-tooltip.noDelay.right="i18n.ts.controlPanel" :class="$style.item" :activeClass="$style.active" to="/admin">
<MkA v-if="($i?.isAdmin || $i?.isModerator) && $i?.twoFactorEnabled" v-tooltip.noDelay.right="i18n.ts.controlPanel" :class="$style.item" :activeClass="$style.active" to="/admin">
<i :class="$style.itemIcon" class="ti ti-dashboard ti-fw"></i><span :class="$style.itemText">{{ i18n.ts.controlPanel }}</span>
<span v-if="unresolvedReportAvailable" :class="$style.itemIndicator">
<i class="_indicatorCircle"></i>

View File

@ -21,7 +21,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</component>
</template>
<div class="divider"></div>
<MkA v-if="$i.isAdmin || $i.isModerator" v-click-anime v-tooltip="i18n.ts.controlPanel" class="item" activeClass="active" to="/admin" :behavior="settingsWindowed ? 'window' : null">
<MkA v-if="iAmModerator" v-click-anime v-tooltip="i18n.ts.controlPanel" class="item" activeClass="active" to="/admin" :behavior="settingsWindowed ? 'window' : null">
<i class="ti ti-dashboard ti-fw"></i>
</MkA>
<button v-click-anime class="item _button" @click="more">
@ -51,7 +51,7 @@ import { computed, defineAsyncComponent, onMounted, ref } from 'vue';
import { openInstanceMenu } from './_common_/common.js';
import * as os from '@/os.js';
import { navbarItemDef } from '@/navbar.js';
import { openAccountMenu as openAccountMenu_, $i } from '@/account.js';
import { $i, iAmModerator, openAccountMenu as openAccountMenu_ } from '@/account.js';
import MkButton from '@/components/MkButton.vue';
import { defaultStore } from '@/store.js';
import { instance } from '@/instance.js';

View File

@ -28,7 +28,7 @@ SPDX-License-Identifier: AGPL-3.0-only
</component>
</template>
<div class="divider"></div>
<MkA v-if="$i.isAdmin || $i.isModerator" v-click-anime class="item" activeClass="active" to="/admin" :behavior="settingsWindowed ? 'window' : null">
<MkA v-if="iAmModerator" v-click-anime class="item" activeClass="active" to="/admin" :behavior="settingsWindowed ? 'window' : null">
<i class="ti ti-dashboard ti-fw"></i><span class="text">{{ i18n.ts.controlPanel }}</span>
</MkA>
<button v-click-anime class="item _button" @click="more">
@ -51,14 +51,10 @@ SPDX-License-Identifier: AGPL-3.0-only
<script lang="ts" setup>
import { defineAsyncComponent, computed, watch, ref, shallowRef } from 'vue';
import { openInstanceMenu } from './_common_/common.js';
// import { host } from '@/config.js';
import * as os from '@/os.js';
import { navbarItemDef } from '@/navbar.js';
import { openAccountMenu as openAccountMenu_, $i } from '@/account.js';
import { $i, iAmModerator, openAccountMenu as openAccountMenu_ } from '@/account.js';
import MkButton from '@/components/MkButton.vue';
// import { StickySidebar } from '@/scripts/sticky-sidebar.js';
// import { mainRouter } from '@/router.js';
//import MisskeyLogo from '@assets/client/misskey.svg';
import { defaultStore } from '@/store.js';
import { instance } from '@/instance.js';
import { i18n } from '@/i18n.js';

View File

@ -1,7 +1,7 @@
{
"type": "module",
"name": "misskey-js",
"version": "2024.5.0-oscar.9b",
"version": "2024.5.0-oscar.10",
"description": "Misskey SDK for JavaScript",
"types": "./built/dts/index.d.ts",
"exports": {