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
deny null #1020
Conversation
src/server/routes/page.js
Outdated
@@ -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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
初期化コードは変えたくないので、null で初期化されても上手く動くように、後続のコードを変えてほしい。
src/server/routes/page.js
Outdated
@@ -561,6 +561,10 @@ module.exports = function(crowi, app) { | |||
return res.json(ApiResponse.error('Parameters body and path are required.')); | |||
} | |||
|
|||
if (!grant) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
とりあえず grant が設定されているかどうかは grant != null
という式にする
src/server/routes/page.js
Outdated
@@ -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')); |
There was a problem hiding this comment.
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.js
の applyScope
もチェックして。routes/page.js
で直すべき箇所もあるし、models/page.js
で直した方がいい箇所もある。
捕捉
因みに 1
というマジックナンバーは使わないように。models/page.js
に定数がある。
6/10にFBしたように、「grant が設定されていない場合(クライアントからパラメータが指定されなかった場合」も正常に動くように |
src/server/models/page.js
Outdated
@@ -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; |
There was a problem hiding this comment.
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;
となっている
src/server/models/page.js
Outdated
@@ -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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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; | ||
} |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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: 1
で grantUserGroupId
に値が入っている不正な状態でも、applyScode が是正してくれる。
related to #944