Skip to content

Commit

Permalink
Fixup stage 1
Browse files Browse the repository at this point in the history
JSON ์ˆ˜์ • ๋” ํ•ด์•ผํ•จ
๋นก์น˜๋„ค
  • Loading branch information
HotoRas committed Oct 19, 2024
1 parent 736c808 commit dbd3028
Show file tree
Hide file tree
Showing 13 changed files with 41 additions and 44 deletions.
3 changes: 3 additions & 0 deletions packages/backend/src/core/SignupService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ export class SignupService {
passwordHash?: MiUserProfile['password'] | null;
host?: string | null;
ignorePreservedUsernames?: boolean;
reason?: string | null;
}) {
const { username, password, passwordHash, host } = opts;
let hash = passwordHash;
Expand Down Expand Up @@ -130,6 +131,8 @@ export class SignupService {
host: this.utilityService.toPunyNullable(host),
token: secret,
isRoot: isTheFirstUser,
signupReason: opts.reason,
updatedAt: new Date(),
}));

await transactionalEntityManager.save(new MiUserKeypair({
Expand Down
4 changes: 4 additions & 0 deletions packages/backend/src/models/json-schema/meta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,10 @@ export const packedMetaLiteSchema = {
type: 'boolean',
optional: false, nullable: false,
},
approvalRequiredForSignup: {
type: 'boolean',
optional: false, default: false,
},
enableHcaptcha: {
type: 'boolean',
optional: false, nullable: false,
Expand Down
4 changes: 1 addition & 3 deletions packages/backend/src/server/api/ApiCallService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,6 @@ export class ApiCallService implements OnApplicationShutdown {
}
}

const instance = await this.metaService.fetch(true);

if (ep.meta.requireCredential || ep.meta.requireModerator || ep.meta.requireAdmin) {
if (user == null) {
throw new ApiError({
Expand All @@ -359,7 +357,7 @@ export class ApiCallService implements OnApplicationShutdown {
kind: 'permission',
id: 'a8c724b3-6e9c-4b46-b1a8-bc3ed6258370',
});
} else if (instance.approvalRequiredForSignup && user!.approved === false) {
} else if (this.meta.approvalRequiredForSignup && user!.approved === false) {
throw new ApiError({
message: 'Your account is not approved yet.',
code: 'YOUR_ACCOUNT_NOT_APPROVED',
Expand Down
12 changes: 5 additions & 7 deletions packages/backend/src/server/api/SignupApiService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ import { MiLocalUser } from '@/models/User.js';
import { FastifyReplyError } from '@/misc/fastify-reply-error.js';
import { bindThis } from '@/decorators.js';
import { L_CHARS, secureRndstr } from '@/misc/secure-rndstr.js';
import { RoleService } from '@/core/RoleService.js';
import { SigninService } from './SigninService.js';
import type { FastifyRequest, FastifyReply } from 'fastify';
import instance from './endpoints/charts/instance.js';
import { RoleService } from '@/core/RoleService.js';
import type { FastifyRequest, FastifyReply } from 'fastify';

@Injectable()
export class SignupApiService {
Expand Down Expand Up @@ -125,7 +125,7 @@ export class SignupApiService {
}
}

if (instance.approvalRequiredForSignup) {
if (this.meta.approvalRequiredForSignup) {
if (reason == null || typeof reason !== 'string') {
reply.code(400);
return;
Expand Down Expand Up @@ -218,7 +218,7 @@ export class SignupApiService {

reply.code(204);
return;
} else if (instance.approvalRequiredForSignup) {
} else if (this.meta.approvalRequiredForSignup) {
const { account } = await this.signupService.signup({
username, password, host, reason,
});
Expand Down Expand Up @@ -286,8 +286,6 @@ export class SignupApiService {

const code = body['code'];

const instance = await this.metaService.fetch(true);

try {
const pendingUser = await this.userPendingsRepository.findOneByOrFail({ code });

Expand Down Expand Up @@ -322,7 +320,7 @@ export class SignupApiService {
});
}

if (instance.approvalRequiredForSignup) {
if (this.meta.approvalRequiredForSignup) {
if (pendingUser.email) {
this.emailService.sendEmail(pendingUser.email, 'Approval pending',
'Congratulations! Your account is now pending approval. You will get notified when you have been accepted.',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const meta = {
requireCredential: true,
requireModerator: true,
kind: 'write:admin:approve-account',
secure: true,
} as const;

export const paramDef = {
Expand Down
4 changes: 2 additions & 2 deletions packages/frontend/src/components/MkApprovalUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SPDX-License-Identifier: AGPL-3.0-only
<div :class="$style.items">
<div>
<div :class="$style.label">{{ i18n.ts.createdAt }}</div>
<div><MkTime :time="user.createdAt" mode="absolute"/></div>
<div><MkTime :time="user.updatedAt" mode="absolute"/></div>
</div>
<div v-if="email">
<div :class="$style.label">{{ i18n.ts.emailAddress }}</div>
Expand Down Expand Up @@ -52,7 +52,7 @@ function getReason() {
userId: props.user.id,
}).then(info => {
reason.value = info.signupReason;
email.value = info.email;
email.value = info.email ?? '';
});
}
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkSignupDialog.form.vue
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ SPDX-License-Identifier: AGPL-3.0-only
import { ref, computed } from 'vue';
import { toUnicode } from 'punycode/';
import * as Misskey from 'misskey-js';
import * as config from '@@/js/config.js';
import MkButton from './MkButton.vue';
import MkInput from './MkInput.vue';
import MkCaptcha, { type Captcha } from '@/components/MkCaptcha.vue';
import * as config from '@@/js/config.js';
import * as os from '@/os.js';
import { misskeyApi } from '@/scripts/misskey-api.js';
import { login } from '@/account.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkSignupDialog.vue
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ function onSignupEmailPending() {
}
function onApprovalPending() {
dialog.value.close();
dialog.value?.close();
}
</script>
Expand Down
20 changes: 10 additions & 10 deletions packages/frontend/src/pages/admin-user.vue
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function createFetcher() {
moderationNote.value = info.value.moderationNote;
watch(moderationNote, async () => {
await misskeyApi('admin/update-user-note', { userId: user.value.id, text: moderationNote.value });
await misskeyApi('admin/update-user-note', { userId: user.value!.id, text: moderationNote.value });
await refreshUser();
});
});
Expand All @@ -294,7 +294,7 @@ function refreshUser() {
}
async function updateRemoteUser() {
await os.apiWithDialog('federation/update-remote-user', { userId: user.value.id });
await os.apiWithDialog('federation/update-remote-user', { userId: user.value!.id });
refreshUser();
}
Expand All @@ -307,7 +307,7 @@ async function resetPassword() {
return;
} else {
const { password } = await misskeyApi('admin/reset-password', {
userId: user.value.id,
userId: user.value!.id,
});
os.alert({
type: 'success',
Expand All @@ -324,7 +324,7 @@ async function toggleSuspend(v) {
if (confirm.canceled) {
suspended.value = !v;
} else {
await misskeyApi(v ? 'admin/suspend-user' : 'admin/unsuspend-user', { userId: user.value.id });
await misskeyApi(v ? 'admin/suspend-user' : 'admin/unsuspend-user', { userId: user.value!.id });
await refreshUser();
}
}
Expand All @@ -336,7 +336,7 @@ async function unsetUserAvatar() {
});
if (confirm.canceled) return;
const process = async () => {
await misskeyApi('admin/unset-user-avatar', { userId: user.value.id });
await misskeyApi('admin/unset-user-avatar', { userId: user.value!.id });
os.success();
};
await process().catch(err => {
Expand All @@ -355,7 +355,7 @@ async function unsetUserBanner() {
});
if (confirm.canceled) return;
const process = async () => {
await misskeyApi('admin/unset-user-banner', { userId: user.value.id });
await misskeyApi('admin/unset-user-banner', { userId: user.value!.id });
os.success();
};
await process().catch(err => {
Expand All @@ -374,7 +374,7 @@ async function deleteAllFiles() {
});
if (confirm.canceled) return;
const process = async () => {
await misskeyApi('admin/delete-all-files-of-a-user', { userId: user.value.id });
await misskeyApi('admin/delete-all-files-of-a-user', { userId: user.value!.id });
os.success();
};
await process().catch(err => {
Expand Down Expand Up @@ -443,7 +443,7 @@ async function assignRole() {
: period === 'oneMonth' ? Date.now() + (1000 * 60 * 60 * 24 * 30)
: null;
await os.apiWithDialog('admin/roles/assign', { roleId, userId: user.value.id, expiresAt });
await os.apiWithDialog('admin/roles/assign', { roleId, userId: user.value!.id, expiresAt });
refreshUser();
}
Expand All @@ -453,7 +453,7 @@ async function unassignRole(role, ev) {
icon: 'ti ti-x',
danger: true,
action: async () => {
await os.apiWithDialog('admin/roles/unassign', { roleId: role.id, userId: user.value.id });
await os.apiWithDialog('admin/roles/unassign', { roleId: role.id, userId: user.value!.id });
refreshUser();
},
}], ev.currentTarget ?? ev.target);
Expand Down Expand Up @@ -492,7 +492,7 @@ watch(() => props.userId, () => {
watch(user, () => {
misskeyApi('ap/get', {
uri: user.value.uri ?? `${url}/users/${user.value.id}`,
uri: user.value?.uri ?? `${url}/users/${user.value!.id}`,
}).then(res => {
ap.value = res;
});
Expand Down
22 changes: 5 additions & 17 deletions packages/misskey-js/etc/misskey-js.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,14 +89,7 @@ type AdminAdCreateResponse = operations['admin___ad___create']['responses']['200
type AdminAdDeleteRequest = operations['admin___ad___delete']['requestBody']['content']['application/json'];

// @public (undocumented)
<<<<<<< HEAD
type AdminAdListRequest = operations['admin___ad___list']['requestBody']['content']['application/json'];
=======
type AdminApproveUserRequest = operations['admin/approve-user']['requestBody']['content']['application/json'];

// @public (undocumented)
type AdminAvatarDecorationsCreateRequest = operations['admin/avatar-decorations/create']['requestBody']['content']['application/json'];
>>>>>>> 0e2e4c353f6d2fd2cc650007ec2f6a876acde8f7

// @public (undocumented)
type AdminAdListResponse = operations['admin___ad___list']['responses']['200']['content']['application/json'];
Expand All @@ -122,6 +115,9 @@ type AdminAnnouncementsListResponse = operations['admin___announcements___list']
// @public (undocumented)
type AdminAnnouncementsUpdateRequest = operations['admin___announcements___update']['requestBody']['content']['application/json'];

// @public (undocumented)
type AdminApproveUserRequest = operations['admin___approve-user']['requestBody']['content']['application/json'];

// @public (undocumented)
type AdminAvatarDecorationsCreateRequest = operations['admin___avatar-decorations___create']['requestBody']['content']['application/json'];

Expand Down Expand Up @@ -2578,11 +2574,7 @@ type ModerationLog = {
});

// @public (undocumented)
<<<<<<< HEAD
export const moderationLogTypes: readonly ["updateServerSettings", "suspend", "unsuspend", "updateUserNote", "addCustomEmoji", "updateCustomEmoji", "deleteCustomEmoji", "assignRole", "unassignRole", "createRole", "updateRole", "deleteRole", "clearQueue", "promoteQueue", "deleteDriveFile", "deleteNote", "createGlobalAnnouncement", "createUserAnnouncement", "updateGlobalAnnouncement", "updateUserAnnouncement", "deleteGlobalAnnouncement", "deleteUserAnnouncement", "resetPassword", "suspendRemoteInstance", "unsuspendRemoteInstance", "updateRemoteInstanceNote", "markSensitiveDriveFile", "unmarkSensitiveDriveFile", "resolveAbuseReport", "createInvitation", "createAd", "updateAd", "deleteAd", "createAvatarDecoration", "updateAvatarDecoration", "deleteAvatarDecoration", "unsetUserAvatar", "unsetUserBanner", "createSystemWebhook", "updateSystemWebhook", "deleteSystemWebhook", "createAbuseReportNotificationRecipient", "updateAbuseReportNotificationRecipient", "deleteAbuseReportNotificationRecipient", "deleteAccount", "deletePage", "deleteFlash", "deleteGalleryPost"];
=======
export const moderationLogTypes: readonly ["updateServerSettings", "suspend", "approve", "unsuspend", "updateUserNote", "addCustomEmoji", "updateCustomEmoji", "deleteCustomEmoji", "assignRole", "unassignRole", "createRole", "updateRole", "deleteRole", "clearQueue", "promoteQueue", "deleteDriveFile", "deleteNote", "createGlobalAnnouncement", "createUserAnnouncement", "updateGlobalAnnouncement", "updateUserAnnouncement", "deleteGlobalAnnouncement", "deleteUserAnnouncement", "resetPassword", "suspendRemoteInstance", "unsuspendRemoteInstance", "markSensitiveDriveFile", "unmarkSensitiveDriveFile", "resolveAbuseReport", "createInvitation", "createAd", "updateAd", "deleteAd", "createAvatarDecoration", "updateAvatarDecoration", "deleteAvatarDecoration", "unsetUserAvatar", "unsetUserBanner"];
>>>>>>> 0e2e4c353f6d2fd2cc650007ec2f6a876acde8f7
export const moderationLogTypes: readonly ["updateServerSettings", "suspend", "approve", "unsuspend", "updateUserNote", "addCustomEmoji", "updateCustomEmoji", "deleteCustomEmoji", "assignRole", "unassignRole", "createRole", "updateRole", "deleteRole", "clearQueue", "promoteQueue", "deleteDriveFile", "deleteNote", "createGlobalAnnouncement", "createUserAnnouncement", "updateGlobalAnnouncement", "updateUserAnnouncement", "deleteGlobalAnnouncement", "deleteUserAnnouncement", "resetPassword", "suspendRemoteInstance", "unsuspendRemoteInstance", "updateRemoteInstanceNote", "markSensitiveDriveFile", "unmarkSensitiveDriveFile", "resolveAbuseReport", "createInvitation", "createAd", "updateAd", "deleteAd", "createAvatarDecoration", "updateAvatarDecoration", "deleteAvatarDecoration", "unsetUserAvatar", "unsetUserBanner", "createSystemWebhook", "updateSystemWebhook", "deleteSystemWebhook", "createAbuseReportNotificationRecipient", "updateAbuseReportNotificationRecipient", "deleteAbuseReportNotificationRecipient", "deleteAccount", "deletePage", "deleteFlash", "deleteGalleryPost"];

// @public (undocumented)
type MuteCreateRequest = operations['mute___create']['requestBody']['content']['application/json'];
Expand Down Expand Up @@ -2853,11 +2845,7 @@ type PartialRolePolicyOverride = Partial<{
}>;

// @public (undocumented)
<<<<<<< HEAD
export const permissions: readonly ["read:account", "write:account", "read:blocks", "write:blocks", "read:drive", "write:drive", "read:favorites", "write:favorites", "read:following", "write:following", "read:messaging", "write:messaging", "read:mutes", "write:mutes", "write:notes", "read:notifications", "write:notifications", "read:reactions", "write:reactions", "write:votes", "read:pages", "write:pages", "write:page-likes", "read:page-likes", "read:user-groups", "write:user-groups", "read:channels", "write:channels", "read:gallery", "write:gallery", "read:gallery-likes", "write:gallery-likes", "read:flash", "write:flash", "read:flash-likes", "write:flash-likes", "read:admin:abuse-user-reports", "write:admin:delete-account", "write:admin:delete-all-files-of-a-user", "read:admin:index-stats", "read:admin:table-stats", "read:admin:user-ips", "read:admin:meta", "write:admin:reset-password", "write:admin:resolve-abuse-user-report", "write:admin:send-email", "read:admin:server-info", "read:admin:show-moderation-log", "read:admin:show-user", "write:admin:suspend-user", "write:admin:unset-user-avatar", "write:admin:unset-user-banner", "write:admin:unsuspend-user", "write:admin:meta", "write:admin:user-note", "write:admin:roles", "read:admin:roles", "write:admin:relays", "read:admin:relays", "write:admin:invite-codes", "read:admin:invite-codes", "write:admin:announcements", "read:admin:announcements", "write:admin:avatar-decorations", "read:admin:avatar-decorations", "write:admin:federation", "write:admin:account", "read:admin:account", "write:admin:emoji", "read:admin:emoji", "write:admin:queue", "read:admin:queue", "write:admin:promo", "write:admin:drive", "read:admin:drive", "write:admin:ad", "read:admin:ad", "write:invite-codes", "read:invite-codes", "write:clip-favorite", "read:clip-favorite", "read:federation", "write:report-abuse"];
=======
export const permissions: readonly ["read:account", "write:account", "read:blocks", "write:blocks", "read:drive", "write:drive", "read:favorites", "write:favorites", "read:following", "write:following", "read:messaging", "write:messaging", "read:mutes", "write:mutes", "write:notes", "read:notifications", "write:notifications", "read:reactions", "write:reactions", "write:votes", "read:pages", "write:pages", "write:page-likes", "read:page-likes", "read:user-groups", "write:user-groups", "read:channels", "write:channels", "read:gallery", "write:gallery", "read:gallery-likes", "write:gallery-likes", "read:flash", "write:flash", "read:flash-likes", "write:flash-likes", "read:admin:abuse-user-reports", "write:admin:delete-account", "write:admin:delete-all-files-of-a-user", "write:admin:approve-account", "read:admin:index-stats", "read:admin:table-stats", "read:admin:user-ips", "read:admin:meta", "write:admin:reset-password", "write:admin:resolve-abuse-user-report", "write:admin:send-email", "read:admin:server-info", "read:admin:show-moderation-log", "read:admin:show-user", "read:admin:show-users", "write:admin:suspend-user", "write:admin:unset-user-avatar", "write:admin:unset-user-banner", "write:admin:unsuspend-user", "write:admin:meta", "write:admin:user-note", "write:admin:roles", "read:admin:roles", "write:admin:relays", "read:admin:relays", "write:admin:invite-codes", "read:admin:invite-codes", "write:admin:announcements", "read:admin:announcements", "write:admin:avatar-decorations", "read:admin:avatar-decorations", "write:admin:federation", "write:admin:account", "read:admin:account", "write:admin:emoji", "read:admin:emoji", "write:admin:queue", "read:admin:queue", "write:admin:promo", "write:admin:drive", "read:admin:drive", "write:admin:ad", "read:admin:ad", "write:invite-codes", "read:invite-codes", "write:clip-favorite", "read:clip-favorite", "read:federation", "write:report-abuse"];
>>>>>>> 0e2e4c353f6d2fd2cc650007ec2f6a876acde8f7
export const permissions: readonly ["read:account", "write:account", "read:blocks", "write:blocks", "read:drive", "write:drive", "read:favorites", "write:favorites", "read:following", "write:following", "read:messaging", "write:messaging", "read:mutes", "write:mutes", "write:notes", "read:notifications", "write:notifications", "read:reactions", "write:reactions", "write:votes", "read:pages", "write:pages", "write:page-likes", "read:page-likes", "read:user-groups", "write:user-groups", "read:channels", "write:channels", "read:gallery", "write:gallery", "read:gallery-likes", "write:gallery-likes", "read:flash", "write:flash", "read:flash-likes", "write:flash-likes", "read:admin:abuse-user-reports", "write:admin:delete-account", "write:admin:delete-all-files-of-a-user", "write:admin:approve-account", "read:admin:index-stats", "read:admin:table-stats", "read:admin:user-ips", "read:admin:meta", "write:admin:reset-password", "write:admin:resolve-abuse-user-report", "write:admin:send-email", "read:admin:server-info", "read:admin:show-moderation-log", "read:admin:show-user", "write:admin:suspend-user", "write:admin:unset-user-avatar", "write:admin:unset-user-banner", "write:admin:unsuspend-user", "write:admin:meta", "write:admin:user-note", "write:admin:roles", "read:admin:roles", "write:admin:relays", "read:admin:relays", "write:admin:invite-codes", "read:admin:invite-codes", "write:admin:announcements", "read:admin:announcements", "write:admin:avatar-decorations", "read:admin:avatar-decorations", "write:admin:federation", "write:admin:account", "read:admin:account", "write:admin:emoji", "read:admin:emoji", "write:admin:queue", "read:admin:queue", "write:admin:promo", "write:admin:drive", "read:admin:drive", "write:admin:ad", "read:admin:ad", "write:invite-codes", "read:invite-codes", "write:clip-favorite", "read:clip-favorite", "read:federation", "write:report-abuse"];

// @public (undocumented)
type PingResponse = operations['ping']['responses']['200']['content']['application/json'];
Expand Down
1 change: 1 addition & 0 deletions packages/misskey-js/src/autogen/apiClientJSDoc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,6 +760,7 @@ declare module '../api.js' {
/**
* No description provided.
*
* **Internal Endpoint**: This endpoint is an API for the misskey mainframe and is not intended for use by third parties.
* **Credential required**: *Yes* / **Permission**: *write:admin:approve-account*
*/
request<E extends 'admin/approve-user', P extends Endpoints[E]['req']>(
Expand Down
2 changes: 1 addition & 1 deletion packages/misskey-js/src/autogen/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ export type AdminShowUserResponse = operations['admin___show-user']['responses']
export type AdminShowUsersRequest = operations['admin___show-users']['requestBody']['content']['application/json'];
export type AdminShowUsersResponse = operations['admin___show-users']['responses']['200']['content']['application/json'];
export type AdminSuspendUserRequest = operations['admin___suspend-user']['requestBody']['content']['application/json'];
export type AdminApproveUserRequest = operations['admin__approve-user']['requestBody']['content']['application/json'];
export type AdminApproveUserRequest = operations['admin___approve-user']['requestBody']['content']['application/json'];
export type AdminUnsuspendUserRequest = operations['admin___unsuspend-user']['requestBody']['content']['application/json'];
export type AdminUpdateMetaRequest = operations['admin___update-meta']['requestBody']['content']['application/json'];
export type AdminDeleteAccountRequest = operations['admin___delete-account']['requestBody']['content']['application/json'];
Expand Down
Loading

0 comments on commit dbd3028

Please sign in to comment.