From 0854f2e180be7b2ed4e7ea68d7f45cc156a95627 Mon Sep 17 00:00:00 2001
From: MeiMei <30769358+mei23@users.noreply.github.com>
Date: Sat, 26 Jan 2019 17:53:35 +0900
Subject: [PATCH] =?UTF-8?q?=E7=AE=A1=E7=90=86=E7=94=BB=E9=9D=A2=E3=81=8B?=
=?UTF-8?q?=E3=82=89=E3=83=AA=E3=83=A2=E3=83=BC=E3=83=88=E3=83=A6=E3=83=BC?=
=?UTF-8?q?=E3=82=B6=E3=83=BC=E6=83=85=E5=A0=B1=E3=82=92=E6=9B=B4=E6=96=B0?=
=?UTF-8?q?=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB=20(#3992?=
=?UTF-8?q?)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
locales/ja-JP.yml | 2 +
src/client/app/admin/views/users.vue | 16 ++++++-
src/server/api/common/getters.ts | 42 +++++++++++++++++++
.../api/endpoints/admin/update-remote-user.ts | 36 ++++++++++++++++
4 files changed, 94 insertions(+), 2 deletions(-)
create mode 100644 src/server/api/endpoints/admin/update-remote-user.ts
diff --git a/locales/ja-JP.yml b/locales/ja-JP.yml
index 01b1dfa2c4..1735376b2a 100644
--- a/locales/ja-JP.yml
+++ b/locales/ja-JP.yml
@@ -1280,6 +1280,8 @@ admin/views/users.vue:
unverify: "公式アカウントを解除する"
unverify-confirm: "公式アカウントを解除しますか?"
unverified: "公式アカウントを解除しました"
+ update-remote-user: "リモートユーザー情報の更新"
+ remote-user-updated: "リモートユーザー情報を更新しました"
users:
title: "ユーザー"
sort:
diff --git a/src/client/app/admin/views/users.vue b/src/client/app/admin/views/users.vue
index 6b829a2f8d..09d074eee2 100644
--- a/src/client/app/admin/views/users.vue
+++ b/src/client/app/admin/views/users.vue
@@ -20,6 +20,7 @@
{{ $t('suspend') }}
{{ $t('unsuspend') }}
+ {{ $t('update-remote-user') }}
@@ -65,7 +66,7 @@
import Vue from 'vue';
import i18n from '../../i18n';
import parseAcct from "../../../../misc/acct/parse";
-import { faCertificate, faUsers, faTerminal, faSearch, faKey } from '@fortawesome/free-solid-svg-icons';
+import { faCertificate, faUsers, faTerminal, faSearch, faKey, faSync } from '@fortawesome/free-solid-svg-icons';
import { faSnowflake } from '@fortawesome/free-regular-svg-icons';
import XUser from './users.user.vue';
@@ -89,7 +90,7 @@ export default Vue.extend({
offset: 0,
users: [],
existMore: false,
- faTerminal, faCertificate, faUsers, faSnowflake, faSearch, faKey
+ faTerminal, faCertificate, faUsers, faSnowflake, faSearch, faKey, faSync
};
},
@@ -265,6 +266,17 @@ export default Vue.extend({
this.refreshUser();
},
+ async updateRemoteUser() {
+ this.$root.api('admin/update-remote-user', { userId: this.user._id }).then(res => {
+ this.$root.dialog({
+ type: 'success',
+ text: this.$t('remote-user-updated')
+ });
+ });
+
+ this.refreshUser();
+ },
+
async getConfirmed(text: string): Promise {
const confirm = await this.$root.dialog({
type: 'warning',
diff --git a/src/server/api/common/getters.ts b/src/server/api/common/getters.ts
index 1fce58b20a..1cd054cab1 100644
--- a/src/server/api/common/getters.ts
+++ b/src/server/api/common/getters.ts
@@ -1,5 +1,6 @@
import * as mongo from 'mongodb';
import Note from "../../../models/note";
+import User, { isRemoteUser, isLocalUser } from "../../../models/user";
/**
* Get valied note for API processing
@@ -16,3 +17,44 @@ export async function getValiedNote(noteId: mongo.ObjectID) {
return note;
}
+
+/**
+ * Get user for API processing
+ */
+export async function getUser(userId: mongo.ObjectID) {
+ const user = await User.findOne({
+ _id: userId
+ });
+
+ if (user == null) {
+ throw 'user not found';
+ }
+
+ return user;
+}
+
+/**
+ * Get remote user for API processing
+ */
+export async function getRemoteUser(userId: mongo.ObjectID) {
+ const user = await getUser(userId);
+
+ if (!isRemoteUser(user)) {
+ throw 'user is not a remote user';
+ }
+
+ return user;
+}
+
+/**
+ * Get local user for API processing
+ */
+export async function getLocalUser(userId: mongo.ObjectID) {
+ const user = await getUser(userId);
+
+ if (!isLocalUser(user)) {
+ throw 'user is not a local user';
+ }
+
+ return user;
+}
diff --git a/src/server/api/endpoints/admin/update-remote-user.ts b/src/server/api/endpoints/admin/update-remote-user.ts
new file mode 100644
index 0000000000..9288ce1fb7
--- /dev/null
+++ b/src/server/api/endpoints/admin/update-remote-user.ts
@@ -0,0 +1,36 @@
+import * as mongo from 'mongodb';
+import $ from 'cafy';
+import ID, { transform } from '../../../../misc/cafy-id';
+import define from '../../define';
+import { getRemoteUser } from '../../common/getters';
+import { updatePerson } from '../../../../remote/activitypub/models/person';
+
+export const meta = {
+ desc: {
+ 'ja-JP': '指定されたリモートユーザーの情報を更新します。',
+ 'en-US': 'Update specified remote user information.'
+ },
+
+ requireCredential: true,
+ requireModerator: true,
+
+ params: {
+ userId: {
+ validator: $.type(ID),
+ transform: transform,
+ desc: {
+ 'ja-JP': '対象のユーザーID',
+ 'en-US': 'The user ID which you want to update'
+ }
+ },
+ }
+};
+
+export default define(meta, (ps) => new Promise((res, rej) => {
+ updatePersonById(ps.userId).then(() => res(), e => rej(e));
+}));
+
+async function updatePersonById(userId: mongo.ObjectID) {
+ const user = await getRemoteUser(userId);
+ await updatePerson(user.uri);
+}