Skip to content

Commit

Permalink
Fix problem where user wasn't returned their token by /api/v1/tokens
Browse files Browse the repository at this point in the history
    The search field must be specified to AccountScopeFilter
    A few other places were checked and updated.
  • Loading branch information
Misterblue committed Dec 18, 2020
1 parent cc8e9d6 commit 8cf1eee
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/routes/api/v1/account/accountId/tokens.ts
Expand Up @@ -31,7 +31,7 @@ import { AuthToken } from '@Entities/AuthToken';
const procGetAccountTokens: RequestHandler = async (req: Request, resp: Response, next: NextFunction) => {
if (req.vRestResp && req.vAuthAccount && req.vAccount) {
const pager = new PaginationInfo();
const scoper = new AccountScopeFilter(req.vAuthAccount);
const scoper = new AccountScopeFilter(req.vAuthAccount, 'accountId');
pager.parametersFromRequest(req);
scoper.parametersFromRequest(req);
const acctFilter = new GenericFilter( { 'accountId': req.vAccount.id } );
Expand Down
4 changes: 2 additions & 2 deletions src/routes/api/v1/account/accountId/tokens/tokenId.ts
Expand Up @@ -32,13 +32,13 @@ import { Accounts } from '@Entities/Accounts';
// either 'vAuthAccount' is an admin or is the same as 'vAccount'.
const procDeleteToken: RequestHandler = async (req: Request, resp: Response, next: NextFunction) => {
if (req.vRestResp && req.vAuthAccount && req.vAccount && req.vTokenId) {
const scoper = new AccountScopeFilter(req.vAuthAccount);
const scoper = new AccountScopeFilter(req.vAuthAccount, 'accountId');
scoper.parametersFromRequest(req);

const tok = await Tokens.getTokenWithTokenId(req.vTokenId);
if (tok) {
if ( scoper.AsAdmin() && Accounts.isAdmin(req.vAuthAccount)
|| req.vAuthAccount.id === tok.accountId) {
|| req.vAuthAccount.id === tok.accountId) {
if (req.vAccount.id === tok.accountId) {
await Tokens.removeToken(tok);
}
Expand Down
2 changes: 1 addition & 1 deletion src/routes/api/v1/tokens.ts
Expand Up @@ -28,7 +28,7 @@ const procGetTokens: RequestHandler = async (req: Request, resp: Response, next:
Logger.debug('procGetTokens');
if (req.vAuthAccount) {
const pager = new PaginationInfo();
const scoper = new AccountScopeFilter(req.vAuthAccount);
const scoper = new AccountScopeFilter(req.vAuthAccount, 'accountId');
pager.parametersFromRequest(req);
scoper.parametersFromRequest(req);

Expand Down
1 change: 0 additions & 1 deletion src/routes/api/v1/user/places.ts
Expand Up @@ -29,7 +29,6 @@ import { Places } from '@Entities/Places';
import { Maturity } from '@Entities/Sets/Maturity';

import { PaginationInfo } from '@Entities/EntityFilters/PaginationInfo';
import { AccountScopeFilter } from '@Entities/EntityFilters/AccountScopeFilter';
import { PlaceFilterInfo } from '@Entities/EntityFilters/PlaceFilterInfo';
import { Domains } from '@Entities/Domains';

Expand Down

0 comments on commit 8cf1eee

Please sign in to comment.