Skip to content

Commit

Permalink
v1.179.0
Browse files Browse the repository at this point in the history
  • Loading branch information
daneryl committed Aug 12, 2024
2 parents 8764270 + 1c558c4 commit c2fb6e8
Show file tree
Hide file tree
Showing 25 changed files with 614 additions and 533 deletions.
8 changes: 4 additions & 4 deletions app/api/suggestions/extractorsRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export const extractorsRoutes = (app: Application) => {
app.post(
'/api/ixextractors',
serviceMiddleware,
needsAuthorization(['admin']),
needsAuthorization(['admin', 'editor']),
validateAndCoerceRequest({
type: 'object',
properties: {
Expand All @@ -36,7 +36,7 @@ export const extractorsRoutes = (app: Application) => {
app.put(
'/api/ixextractors',
serviceMiddleware,
needsAuthorization(['admin']),
needsAuthorization(['admin', 'editor']),
validateAndCoerceRequest({
type: 'object',
properties: {
Expand Down Expand Up @@ -67,7 +67,7 @@ export const extractorsRoutes = (app: Application) => {
app.delete(
'/api/ixextractors',
serviceMiddleware,
needsAuthorization(['admin']),
needsAuthorization(['admin', 'editor']),
parseQuery,
validateAndCoerceRequest({
type: 'object',
Expand All @@ -90,7 +90,7 @@ export const extractorsRoutes = (app: Application) => {
app.get(
'/api/ixextractors',
serviceMiddleware,
needsAuthorization(['admin']),
needsAuthorization(['admin', 'editor']),
validateAndCoerceRequest({
type: 'object',
properties: {
Expand Down
12 changes: 6 additions & 6 deletions app/api/suggestions/routes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const suggestionsRoutes = (app: Application) => {
app.get(
'/api/suggestions/',
serviceMiddleware,
needsAuthorization(['admin']),
needsAuthorization(['admin', 'editor']),
parseQuery,
validateAndCoerceRequest({
type: 'object',
Expand Down Expand Up @@ -101,7 +101,7 @@ export const suggestionsRoutes = (app: Application) => {
app.get(
'/api/suggestions/aggregation',
serviceMiddleware,
needsAuthorization(['admin']),
needsAuthorization(['admin', 'editor']),
parseQuery,
validateAndCoerceRequest({
type: 'object',
Expand Down Expand Up @@ -132,7 +132,7 @@ export const suggestionsRoutes = (app: Application) => {
app.post(
'/api/suggestions/stop',
serviceMiddleware,
needsAuthorization(['admin']),
needsAuthorization(['admin', 'editor']),
extractorIdRequestValidation('body'),
async (req, res, _next) => {
await processTrainFunction(IX.stopModel, req, res);
Expand All @@ -142,7 +142,7 @@ export const suggestionsRoutes = (app: Application) => {
app.post(
'/api/suggestions/train',
serviceMiddleware,
needsAuthorization(['admin']),
needsAuthorization(['admin', 'editor']),
extractorIdRequestValidation('body'),
async (req, res, _next) => {
await processTrainFunction(IX.trainModel, req, res);
Expand All @@ -152,7 +152,7 @@ export const suggestionsRoutes = (app: Application) => {
app.post(
'/api/suggestions/status',
serviceMiddleware,
needsAuthorization(['admin']),
needsAuthorization(['admin', 'editor']),
extractorIdRequestValidation('body'),
async (req, res, _next) => {
await processTrainFunction(IX.status, req, res);
Expand All @@ -162,7 +162,7 @@ export const suggestionsRoutes = (app: Application) => {
app.post(
'/api/suggestions/accept',
serviceMiddleware,
needsAuthorization(['admin']),
needsAuthorization(['admin', 'editor']),
validateAndCoerceRequest({
type: 'object',
properties: {
Expand Down
52 changes: 0 additions & 52 deletions app/api/suggestions/specs/routes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
shared2esId,
shared6enId,
stateFilterFixtures,
suggestionSharedId6Enemy,
suggestionSharedId6Title,
} from 'api/suggestions/specs/fixtures';
import { suggestionsRoutes } from 'api/suggestions/routes';
Expand Down Expand Up @@ -317,14 +316,6 @@ describe('suggestions routes', () => {
expect(response.status).toBe(400);
});
});

describe('authentication', () => {
it('should reject with unauthorized when the user does not have the admin role', async () => {
user = { username: 'user 1', role: 'editor' };
const response = await request(app).get('/api/suggestions/').query({}).expect(401);
expect(response.unauthorized).toBe(true);
});
});
});

describe('POST /api/suggestions/status', () => {
Expand All @@ -338,14 +329,6 @@ describe('suggestions routes', () => {

expect(response.body).toMatchObject({ status: 'ready' });
});
it('should reject with unauthorized when user has not admin role', async () => {
user = { username: 'user 1', role: 'editor' };
const response = await request(app)
.post('/api/suggestions/status')
.send({ extractorId: factory.id('super_powers_extractor').toString() })
.expect(401);
expect(response.unauthorized).toBe(true);
});
});

describe('POST /api/suggestions/train', () => {
Expand All @@ -357,14 +340,6 @@ describe('suggestions routes', () => {

expect(response.body).toMatchObject({ status: 'processing' });
});
it('should reject with unauthorized when user has not admin role', async () => {
user = { username: 'user 1', role: 'editor' };
const response = await request(app)
.post('/api/suggestions/train')
.send({ extractorId: factory.id('super_powers_extractor').toString() })
.expect(401);
expect(response.unauthorized).toBe(true);
});
});

describe('POST /api/suggestions/accept', () => {
Expand Down Expand Up @@ -397,22 +372,6 @@ describe('suggestions routes', () => {
expect(search.indexEntities).toHaveBeenCalledWith({ sharedId: 'shared6' }, '+fullText');
});

it('should reject with unauthorized when user has not admin role', async () => {
user = { username: 'user 1', role: 'editor' };
const response = await request(app)
.post('/api/suggestions/accept')
.send({
allLanguages: true,
suggestion: {
_id: suggestionSharedId6Enemy,
sharedId: 'shared6',
entityId: shared6enId,
},
})
.expect(401);
expect(response.unauthorized).toBe(true);
});

it('should handle partial acceptance parameters for multiselects', async () => {
await request(app)
.post('/api/suggestions/accept')
Expand Down Expand Up @@ -461,17 +420,6 @@ describe('aggregation routes', () => {
});
});

describe('authentication', () => {
it('should reject with unauthorized when the user does not have the admin role', async () => {
user = { username: 'user 1', role: 'editor' };
const response = await request(app)
.get('/api/suggestions/aggregation')
.query({})
.expect(401);
expect(response.unauthorized).toBe(true);
});
});

it('should return the aggregation of suggestions', async () => {
const response = await request(app)
.get('/api/suggestions/aggregation')
Expand Down
4 changes: 4 additions & 0 deletions app/react/App/scss/modules/_markdown.scss
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@
h4 {
margin-top: 15px;
}

.Map {
height: 400px;
}
}

.panel-body {
Expand Down
30 changes: 25 additions & 5 deletions app/react/App/styles/globals.css
Original file line number Diff line number Diff line change
Expand Up @@ -1733,11 +1733,6 @@ input[type="range"]::-ms-fill-lower {
margin-right: 0.25rem;
}

.mx-2 {
margin-left: 0.5rem;
margin-right: 0.5rem;
}

.mx-4 {
margin-left: 1rem;
margin-right: 1rem;
Expand All @@ -1758,6 +1753,11 @@ input[type="range"]::-ms-fill-lower {
margin-bottom: 1rem;
}

.mx-2 {
margin-left: 0.5rem;
margin-right: 0.5rem;
}

.-ml-0 {
margin-left: -0px;
}
Expand Down Expand Up @@ -2984,6 +2984,11 @@ input[type="range"]::-ms-fill-lower {
background-color: rgb(253 246 178 / var(--tw-bg-opacity));
}

.bg-success-50 {
--tw-bg-opacity: 1;
background-color: rgb(240 253 244 / var(--tw-bg-opacity));
}

.bg-opacity-50 {
--tw-bg-opacity: 0.5;
}
Expand Down Expand Up @@ -3555,6 +3560,11 @@ input[type="range"]::-ms-fill-lower {
color: rgb(114 59 19 / var(--tw-text-opacity));
}

.text-orange-800 {
--tw-text-opacity: 1;
color: rgb(138 44 13 / var(--tw-text-opacity));
}

.underline {
text-decoration-line: underline;
}
Expand Down Expand Up @@ -3779,6 +3789,11 @@ input[type="range"]::-ms-fill-lower {
border-color: rgb(165 180 252 / var(--tw-border-opacity));
}

.hover\:border-primary-800:hover {
--tw-border-opacity: 1;
border-color: rgb(55 48 163 / var(--tw-border-opacity));
}

.hover\:border-success-700:hover {
--tw-border-opacity: 1;
border-color: rgb(21 128 61 / var(--tw-border-opacity));
Expand Down Expand Up @@ -3829,6 +3844,11 @@ input[type="range"]::-ms-fill-lower {
background-color: rgb(205 219 254 / var(--tw-bg-opacity));
}

.hover\:bg-primary-50:hover {
--tw-bg-opacity: 1;
background-color: rgb(238 242 255 / var(--tw-bg-opacity));
}

.hover\:bg-primary-800:hover {
--tw-bg-opacity: 1;
background-color: rgb(55 48 163 / var(--tw-bg-opacity));
Expand Down
15 changes: 7 additions & 8 deletions app/react/ProtectedRoute.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
import React, { ReactElement } from 'react';
import { Navigate, Outlet } from 'react-router-dom';
import { store } from 'app/store';
import { UserRole } from 'shared/types/userSchema';
import { ClientSettings } from 'app/apiResponseTypes';

const ProtectedRoute = ({
children,
onlyAdmin,
allowedRoles,
}: {
children: ReactElement;
onlyAdmin?: boolean;
allowedRoles?: string[];
}) => {
const userId = store?.getState().user.get('_id');

if (onlyAdmin && store?.getState().user.get('role') === UserRole.ADMIN) {
const userRole = store?.getState().user.get('role') || '';
if (allowedRoles && allowedRoles.includes(userRole)) {
return children || <Outlet />;
}

if (!onlyAdmin && userId) {
if (!allowedRoles && userId) {
return children || <Outlet />;
}

return <Navigate to="/login" replace />;
};

const adminsOnlyRoute = (element: ReactElement) => (
<ProtectedRoute onlyAdmin>{element}</ProtectedRoute>
<ProtectedRoute allowedRoles={['admin']}>{element}</ProtectedRoute>
);

const privateRoute = (element: ReactElement, settings: ClientSettings | undefined) =>
!settings?.private ? element : <ProtectedRoute>{element}</ProtectedRoute>;

const loggedInUsersRoute = (element: ReactElement) => <ProtectedRoute>{element}</ProtectedRoute>;
export { loggedInUsersRoute, adminsOnlyRoute, privateRoute };
export { loggedInUsersRoute, adminsOnlyRoute, privateRoute, ProtectedRoute };
19 changes: 16 additions & 3 deletions app/react/Routes.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,12 @@ import { ActivityLog, activityLogLoader } from 'V2/Routes/Settings/ActivityLog';
import { CustomUploads, customUploadsLoader } from 'V2/Routes/Settings/CustomUploads/CustomUploads';
import { FiltersTable, filtersLoader } from 'V2/Routes/Settings/Filters';
import { RouteErrorBoundary, GeneralError } from 'V2/Components/ErrorHandling';
import { loggedInUsersRoute, adminsOnlyRoute, privateRoute } from './ProtectedRoute';
import {
loggedInUsersRoute,
adminsOnlyRoute,
privateRoute,
ProtectedRoute,
} from './ProtectedRoute';
import { getIndexElement } from './getIndexElement';
import { PageView } from './Pages/PageView';
import ResetPassword from './Users/ResetPassword';
Expand Down Expand Up @@ -116,13 +121,21 @@ const getRoutesLayout = (
<Route path="metadata_extraction">
<Route
index
element={adminsOnlyRoute(<IXDashboard />)}
element={
<ProtectedRoute allowedRoles={['admin', 'editor']}>
<IXDashboard />
</ProtectedRoute>
}
loader={IXdashboardLoader(headers)}
/>
<Route
path="suggestions/:extractorId"
loader={IXSuggestionsLoader(headers)}
element={adminsOnlyRoute(<IXSuggestions />)}
element={
<ProtectedRoute allowedRoles={['admin', 'editor']}>
<IXSuggestions />
</ProtectedRoute>
}
/>
</Route>
<Route path="relationship-types">
Expand Down
2 changes: 1 addition & 1 deletion app/react/Settings/components/SettingsNavigation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const SettingsNavigationComponent = ({ allowcustomJS }: { allowcustomJS: boolean
</I18NLink>
</NeedAuthorization>
<FeatureToggle feature="metadataExtraction.url">
<NeedAuthorization roles={['admin']}>
<NeedAuthorization roles={['admin', 'editor']}>
<I18NLink
to="settings/metadata_extraction"
activeclassname="active"
Expand Down
Loading

0 comments on commit c2fb6e8

Please sign in to comment.