0
Fork 0
mirror of https://github.com/logto-io/logto.git synced 2025-02-17 22:04:19 -05:00

fix(core,ui): remove todo comments (#1454)

remove todo comments
This commit is contained in:
simeng-li 2022-07-07 18:10:46 +08:00 committed by GitHub
parent 100bffbc6a
commit d5d6c5ed08
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 1 additions and 59 deletions

View file

@ -1,34 +0,0 @@
import { UserRole } from '@logto/schemas';
import { Context } from 'koa';
import { mockUser } from '@/__mocks__';
import RequestError from '@/errors/RequestError';
import { createContextWithRouteParameters } from '@/utils/test-utils';
import { WithAuthContext } from './koa-auth';
import koaRoleGuard from './koa-role-guard';
import { WithUserInfoContext } from './koa-user-info';
describe('koaRoleGuard middleware', () => {
const baseCtx = createContextWithRouteParameters();
const ctx: WithUserInfoContext<Context & WithAuthContext> = {
...baseCtx,
auth: 'foo',
userInfo: mockUser,
};
const unauthorizedError = new RequestError({ code: 'auth.unauthorized', status: 401 });
const next = jest.fn();
it('should throw if user dose not have admin role', async () => {
ctx.userInfo.roleNames = ['guest'];
await expect(koaRoleGuard(UserRole.Admin)(ctx, next)).rejects.toMatchError(unauthorizedError);
});
it('should not throw for admin user', async () => {
ctx.userInfo.roleNames = ['admin'];
await expect(koaRoleGuard(UserRole.Admin)(ctx, next)).resolves.not.toThrow();
});
});

View file

@ -1,20 +0,0 @@
import { MiddlewareType } from 'koa';
import RequestError from '@/errors/RequestError';
import assertThat from '@/utils/assert-that';
import { WithUserInfoContext } from './koa-user-info';
export default function koaRoleGuard<StateT, ContextT extends WithUserInfoContext, ResponseBodyT>(
// TODO: need to figure out how to infer enum role types from db value
role: string
): MiddlewareType<StateT, ContextT, ResponseBodyT> {
return async ({ userInfo }, next) => {
assertThat(
userInfo.roleNames?.includes(role),
new RequestError({ code: 'auth.unauthorized', status: 401 })
);
return next();
};
}

View file

@ -47,7 +47,6 @@ export const deletePasscodesByIds = async (ids: string[]) => {
`);
if (rowCount !== ids.length) {
// TODO: need to track the failed ids
throw new DeletionError(Passcodes.table, `${ids.join(',')}`);
}
};

View file

@ -27,8 +27,6 @@ export default function resourceRoutes<T extends AuthedRouter>(router: T) {
]);
ctx.pagination.totalCount = count;
// TODO: query scopes of all resources and insert into the response data
ctx.body = resources;
return next();

View file

@ -7,7 +7,7 @@ export type Props = {
htmlType?: 'button' | 'submit' | 'reset';
isDisabled?: boolean;
className?: string;
children: ReactNode; // TODO: make it i18nKey with optional params
children: ReactNode;
type?: 'primary' | 'secondary' | 'outline';
size?: 'small' | 'large';
onClick?: React.MouseEventHandler;

View file

@ -69,7 +69,6 @@ export const defaultCountryCode: CountryCode = 'CN';
export const defaultCountryCallingCode = getCountryCallingCode(defaultCountryCode);
const usePhoneNumber = () => {
// TODO: Get Default Country Code
const [phoneNumber, setPhoneNumber] = useState<PhoneNumberData>({
countryCallingCode: defaultCountryCallingCode,
nationalNumber: '',