簡易的なパーミッションの後方互換 (#4687)

This commit is contained in:
rinsuki 2019-04-15 03:48:54 +09:00 committed by syuilo
parent 0565454419
commit ea3e311528
1 changed files with 5 additions and 1 deletions

View File

@ -3,6 +3,7 @@ import $ from 'cafy';
import define from '../../define';
import { Apps } from '../../../../models';
import { genId } from '../../../../misc/gen-id';
import { unique } from '../../../../prelude/array';
export const meta = {
tags: ['app'],
@ -34,6 +35,9 @@ export default define(meta, async (ps, user) => {
// Generate secret
const secret = rndstr('a-zA-Z0-9', 32);
// for backward compatibility
const permission = unique(ps.permission.map(v => v.replace(/^(.+)(\/|-)(read|write)$/, '$3:$1')));
// Create account
const app = await Apps.save({
id: genId(),
@ -41,7 +45,7 @@ export default define(meta, async (ps, user) => {
userId: user ? user.id : null,
name: ps.name,
description: ps.description,
permission: ps.permission,
permission,
callbackUrl: ps.callbackUrl,
secret: secret
});