(core) freshen grist-admin doc-info and add a test for it

Summary:
The ./test/grist-admin doc-info command line tool was out of date
and not showing user access correctly anymore. This freshens the tool and
adds a small test for it.

Test Plan: Added test.

Reviewers: dsagal

Reviewed By: dsagal

Differential Revision: https://phab.getgrist.com/D3182
This commit is contained in:
Paul Fitzpatrick 2021-12-10 10:41:22 -05:00
parent 8100272e9a
commit 648cb67ee8

View File

@ -1477,7 +1477,7 @@ export class HomeDBManager extends EventEmitter {
// This option is used during imports, where it is convenient not to add a row to the // This option is used during imports, where it is convenient not to add a row to the
// document database until the document has actually been imported. // document database until the document has actually been imported.
public async addDocument(scope: Scope, wsId: number, props: Partial<DocumentProperties>, public async addDocument(scope: Scope, wsId: number, props: Partial<DocumentProperties>,
docId?: string): Promise<QueryResult<number>> { docId?: string): Promise<QueryResult<string>> {
const name = props.name; const name = props.name;
if (!name) { if (!name) {
return { return {
@ -2093,8 +2093,11 @@ export class HomeDBManager extends EventEmitter {
maxInheritedRole = null; maxInheritedRole = null;
} }
// Unless we have special access to the document, or are an owner, limit user information
// returned to being about the current user.
const thisUser = users.find(user => user.id === scope.userId); const thisUser = users.find(user => user.id === scope.userId);
if (!thisUser || getRealAccess(thisUser, { maxInheritedRole, users }) !== 'owners') { if (scope.specialPermit?.docId !== doc.id &&
(!thisUser || getRealAccess(thisUser, { maxInheritedRole, users }) !== 'owners')) {
// If not an owner, don't return information about other users. // If not an owner, don't return information about other users.
users = thisUser ? [thisUser] : []; users = thisUser ? [thisUser] : [];
} }