Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deny null #1020

Merged
merged 9 commits into from Jun 19, 2019
Merged

deny null #1020

merged 9 commits into from Jun 19, 2019

Conversation

itizawa
Copy link
Contributor

@itizawa itizawa commented Jun 6, 2019

related to #944

@@ -549,7 +549,7 @@ module.exports = function(crowi, app) {
api.create = async function(req, res) {
const body = req.body.body || null;
const pagePath = req.body.path || null;
const grant = req.body.grant || null;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

初期化コードは変えたくないので、null で初期化されても上手く動くように、後続のコードを変えてほしい。

itizawa added 2 commits June 10, 2019 16:03
@@ -561,6 +561,10 @@ module.exports = function(crowi, app) {
return res.json(ApiResponse.error('Parameters body and path are required.'));
}

if (!grant) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

とりあえず grant が設定されているかどうかは grant != null という式にする

@@ -561,6 +561,10 @@ module.exports = function(crowi, app) {
return res.json(ApiResponse.error('Parameters body and path are required.'));
}

if (!grant) {
return res.json(ApiResponse.error('Grant is not selected'));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

解はこれじゃないなあ。

まず仕様理解

grant が設定されていない場合は、最終的なデータとしては grant を 1(published)、grantUserGroupId を null に設定しないといけない(両方書き換えないといけない)。
なぜかは説明できる?

手段の話

そして最初のFBの「後続の処理」というのは、このファイルだけにとどまらない。
models/page.jsapplyScope もチェックして。routes/page.js で直すべき箇所もあるし、models/page.js で直した方がいい箇所もある。

捕捉

因みに 1 というマジックナンバーは使わないように。models/page.js に定数がある。

@yuki-takei
Copy link
Member

yuki-takei commented Jun 17, 2019

6/10にFBしたように、「grant が設定されていない場合(クライアントからパラメータが指定されなかった場合」も正常に動くように routes/page.js を修正しないといけない。create と update 両方でエラーなく動くことを確認している?

@@ -1012,7 +1016,7 @@ module.exports = function(crowi) {
validateCrowi();

const Revision = crowi.model('Revision');
const grant = options.grant || null;
const grant = options.grant || GRANT_PUBLIC;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updateでnullをチェックして、nullだったらgrant:1にする。
createでは
let grant = options.grant || GRANT_PUBLIC;
となっている

@@ -481,6 +481,10 @@ module.exports = function(crowi) {
if (grant === GRANT_USER_GROUP) {
this.grantedGroup = grantUserGroupId;
}

if (grant === GRANT_PUBLIC && grantUserGroupId !== null) {
this.grantedGroup = null;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

grantが1でgroupidが存在すると異常なのでnullに書き換える

// reset
this.grantedUsers = [];
this.grantedGroup = null;

this.grant = grant || GRANT_PUBLIC;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

null, undefined の場合に public にするのは最後の砦であるこのメソッドで行う

@@ -934,7 +934,7 @@ module.exports = function(crowi) {
.cursor();
};

async function pushRevision(pageData, newRevision, user, grant, grantUserGroupId) {
async function pushRevision(pageData, newRevision, user) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これはただのゴミ掃除

@@ -973,7 +973,7 @@ module.exports = function(crowi) {
// sanitize path
path = crowi.xss.process(path); // eslint-disable-line no-param-reassign

let grant = options.grant || GRANT_PUBLIC;
let grant = options.grant;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Page.create に渡ってきたものはそのまま使う(portal の場合だけ public にする)

@@ -997,7 +997,7 @@ module.exports = function(crowi) {

let savedPage = await page.save();
const newRevision = Revision.prepareRevision(savedPage, body, null, user, { format });
const revision = await pushRevision(savedPage, newRevision, user, grant, grantUserGroupId);
const revision = await pushRevision(savedPage, newRevision, user);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これはただのゴミ掃除

const grant = options.grant || null;
const grantUserGroupId = options.grantUserGroupId || null;
const grant = options.grant || pageData.grant; // use the previous data if absence
const grantUserGroupId = options.grantUserGroupId || pageData.grantUserGroupId; // use the previous data if absence
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update 時は指定がなければ元の値を使う

@@ -1023,7 +1023,7 @@ module.exports = function(crowi) {
// update existing page
let savedPage = await pageData.save();
const newRevision = await Revision.prepareRevision(pageData, body, previousBody, user);
const revision = await pushRevision(savedPage, newRevision, user, grant, grantUserGroupId);
const revision = await pushRevision(savedPage, newRevision, user);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

これはただのゴミ掃除

if (grant != null) {
options.grant = grant;
options.grantUserGroupId = grantUserGroupId;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • router の create では、API body で指定がなければ options にも入れない
    • router の update での仕様に揃えた
    • undefied, null 値でも model の applyScope がよしなにやってくれるので router のスコープ外という考え方

@@ -1116,6 +1119,8 @@ module.exports = function(crowi, app) {
req.body.path = newPagePath;
req.body.body = page.revision.body;
req.body.grant = page.grant;
req.body.grantedUsers = page.grantedUsers;
req.body.grantedGroup = page.grantedGroup;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

duplicate 時に元々バグがあった部分。コピー元データを使うように修正。

@@ -648,8 +651,6 @@ module.exports = function(crowi, app) {
const options = { isSyncRevisionToHackmd, socketClientId };
if (grant != null) {
options.grant = grant;
}
if (grantUserGroupId != null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

applyScope が賢くなったので、ここは grant が指定されているかどうかだけ見て grantUserGroupId も options に入れた。仮に grant: 1grantUserGroupId に値が入っている不正な状態でも、applyScode が是正してくれる。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants