管理画面からリモートユーザー情報を更新できるように (#3992)
This commit is contained in:
@ -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;
|
||||
}
|
||||
|
36
src/server/api/endpoints/admin/update-remote-user.ts
Normal file
36
src/server/api/endpoints/admin/update-remote-user.ts
Normal file
@ -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);
|
||||
}
|
Reference in New Issue
Block a user