Skip to content

Commit

Permalink
[backend] rebase
Browse files Browse the repository at this point in the history
  • Loading branch information
savacano28 committed Jun 3, 2024
1 parent aa65403 commit 524b669
Show file tree
Hide file tree
Showing 13 changed files with 516 additions and 438 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private void synchronizeBox(Folder inbox, Boolean isSent) throws Exception {
Optional<Setting> state = settingRepository.findByKey(inboxKey);
Setting currentState = state.orElse(null);
if (currentState == null) {
currentState = settingRepository.save(new Setting(inboxKey, SectionEnum.CONFIGURATION, "0"));
currentState = settingRepository.save(new Setting(SectionEnum.CONFIGURATION, inboxKey, "0"));
}
int startMessageNumber = parseInt(currentState.getValue());
int messageCount = inbox.getMessageCount();
Expand Down

Large diffs are not rendered by default.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.openbas.rest.settings.response;

import com.fasterxml.jackson.annotation.JsonProperty;
import io.openbas.rest.settings.form.PolicyInput;
import io.openbas.rest.settings.form.ThemeInput;
import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down Expand Up @@ -101,5 +102,9 @@ public class PlatformSettings {
@JsonProperty("platform_dark_theme")
private ThemeInput themeDark;

// POLICIES

@JsonProperty("platform_policies")
private PolicyInput policies;

}

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions openbas-front/src/actions/Application.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@ import * as Constants from '../constants/ActionTypes';
import * as schema from './Schema';
import { getReferential, postReferential, putReferential, simpleCall } from '../utils/Action';

export const fetchPlatformParameters = () => (dispatch) => {
return getReferential(schema.platformParameters, '/api/settings')(dispatch);
};

export const updatePlatformParameters = (data) => (dispatch) => {
return putReferential(
schema.platformParameters,
Expand Down Expand Up @@ -35,10 +39,6 @@ export const updatePlatformWhitemarkParameters = (data) => (dispatch) => {
)(dispatch);
};

export const fetchPlatformParameters = () => (dispatch) => {
return getReferential(schema.platformParameters, '/api/settings')(dispatch);
};

export const updatePlatformLightParameters = (data) => (dispatch) => {
return putReferential(
schema.platformParameters,
Expand Down
1 change: 0 additions & 1 deletion openbas-front/src/actions/helper.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ export interface LoggedHelper {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
logged: () => any;
getMe: () => User;
getSettings: () => PlatformSettings;
getPlatformSettings: () => PlatformSettings;
}

Expand Down
22 changes: 19 additions & 3 deletions openbas-front/src/admin/components/settings/policies/Policies.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import { useFormatter } from '../../../../components/i18n';
import Breadcrumbs from '../../../../components/Breadcrumbs';
import SecurityMenu from '../SecurityMenu';
import PolicyForm from './PolicyForm';
import type { PolicyInput } from '../../../../utils/api-types';
import { updatePlatformPolicies } from '../../../../actions/Application';
import type { PlatformSettings, PolicyInput } from '../../../../utils/api-types';
import { fetchPlatformParameters, updatePlatformPolicies } from '../../../../actions/Application';
import { useAppDispatch } from '../../../../utils/hooks';
import { useHelper } from '../../../../store';
import type { LoggedHelper } from '../../../../actions/helper';
import useDataLoader from '../../../../utils/hooks/useDataLoader';

const useStyles = makeStyles(() => ({
container: {
Expand All @@ -22,10 +25,23 @@ const useStyles = makeStyles(() => ({
borderRadius: 6,
},
}));

const Policies: FunctionComponent = () => {
const classes = useStyles();
const dispatch = useAppDispatch();
const { t } = useFormatter();
const { settings }: { settings: PlatformSettings } = useHelper((helper: LoggedHelper) => ({
settings: helper.getPlatformSettings(),
}));
useDataLoader(() => {
dispatch(fetchPlatformParameters());
});

const initialValues = {
platform_login_message: settings.platform_policies?.platform_login_message || '',
platform_consent_message: settings.platform_policies?.platform_consent_message || '',
platform_consent_confirm_text: settings.platform_policies?.platform_consent_confirm_text || '',
};

const onUpdate = (data: PolicyInput) => {
dispatch(updatePlatformPolicies(data));
Expand All @@ -44,7 +60,7 @@ const Policies: FunctionComponent = () => {
{t('Login messages')}
</Typography>
<Paper classes={{ root: classes.paper }} variant="outlined">
<PolicyForm onSubmit={onUpdate}></PolicyForm>
<PolicyForm onSubmit={onUpdate} initialValues={initialValues}></PolicyForm>
</Paper>
</Grid>
</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,7 @@ import { useForm, FormProvider, SubmitHandler } from 'react-hook-form';
import { Button } from '@mui/material';
import MarkDownField from '../../../../components/fields/MarkDownField';
import { useFormatter } from '../../../../components/i18n';

interface PolicyInput {
platform_login_message: string;
platform_consent_message: string;
platform_consent_confirm_text: string;
}
import type { PolicyInput } from '../../../../utils/api-types';

interface Props {
onSubmit: SubmitHandler<PolicyInput>;
Expand Down
2 changes: 2 additions & 0 deletions openbas-front/src/components/fields/MarkDownField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const MarkDownField: React.FC<Props> = ({
defaultValue: '',
});
const [isEdit, setIsEdit] = useState(true);

// Commands
const buttonStyle = {
border: '1px solid',
borderRadius: 4,
Expand Down
130 changes: 96 additions & 34 deletions openbas-front/src/public/components/login/Login.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import React, { useEffect, useState } from 'react';
import * as PropTypes from 'prop-types';
import { connect } from 'react-redux';
import { withStyles, useTheme } from '@mui/styles';
import { Paper, Box } from '@mui/material';
import { useTheme, withStyles } from '@mui/styles';
import { Box, Checkbox, Paper } from '@mui/material';
import * as R from 'ramda';
import Markdown from 'react-markdown';
import logoDark from '../../../static/images/logo_text_dark.png';
import logoLight from '../../../static/images/logo_text_light.png';
import byFiligranDark from '../../../static/images/by_filigran_dark.png';
Expand All @@ -16,6 +17,7 @@ import Reset from './Reset';
import LoginError from './LoginError';
import LoginSSOButton from './LoginSSOButton';
import { fileUri } from '../../../utils/Environment';
import { isNotEmptyField } from '../../../utils/utils';

const styles = () => ({
container: {
Expand All @@ -41,6 +43,12 @@ const styles = () => ({
width: 100,
margin: '-10px 0 0 295px',
},
paper: {
margin: '0 auto',
marginBottom: 20,
textAlign: 'center',
maxWidth: 500,
},
});

const Login = (props) => {
Expand All @@ -60,7 +68,9 @@ const Login = (props) => {
width: window.innerWidth,
height: window.innerHeight,
});
const updateWindowDimensions = () => setDimension({ width: window.innerWidth, height: window.innerHeight });
const updateWindowDimensions = () => setDimension(
{ width: window.innerWidth, height: window.innerHeight },
);
useEffect(() => {
window.addEventListener('resize', updateWindowDimensions);
return () => window.removeEventListener('resize', updateWindowDimensions);
Expand All @@ -81,51 +91,103 @@ const Login = (props) => {
? parameters?.platform_dark_theme?.logo_login_url
: parameters?.platform_light_theme?.logo_login_url;

const isWhitemarkEnable = parameters.platform_whitemark === 'true' && parameters.platform_enterprise_edition === 'true';
const isWhitemarkEnable = parameters.platform_whitemark === 'true'
&& parameters.platform_enterprise_edition === 'true';

// POLICIES (Copy from opencti)
const loginMessage = parameters.platform_policies.platform_login_message;
const consentMessage = parameters.platform_policies.platform_consent_message;
const consentConfirmText = parameters.platform_policies.platform_consent_confirm_text
? parameters.platform_policies.platform_consent_confirm_text
: t('I have read and comply with the above statement');
const isLoginMessage = isNotEmptyField(loginMessage);
const isConsentMessage = isNotEmptyField(consentMessage);
const [checked, setChecked] = useState(false);
const handleChange = () => {
setChecked(!checked);
// Auto scroll to bottom of unhidden/re-hidden login options.
window.setTimeout(() => {
const scrollingElement = document.scrollingElement ?? document.body;
scrollingElement.scrollTop = scrollingElement.scrollHeight;
}, 1);
};

return (
<div data-testid="login-page" className={classes.container} style={{ marginTop }}>
<div data-testid="login-page" className={classes.container}
style={{ marginTop }}
>
<img
src={loginLogo && loginLogo.length > 0 ? loginLogo : fileUri(theme.palette.mode === 'dark' ? logoDark : logoLight)} alt="logo"
src={loginLogo && loginLogo.length > 0 ? loginLogo : fileUri(
theme.palette.mode === 'dark' ? logoDark : logoLight,
)}
alt="logo"
className={classes.logo}
style={{ marginBottom: isWhitemarkEnable ? 20 : 0 }}
/>
{!isWhitemarkEnable && (
<div className={classes.byFiligran} style={{ marginBottom: 20 }}>
<img
src={fileUri(theme.palette.mode === 'dark' ? byFiligranDark : byFiligranLight)}
src={fileUri(theme.palette.mode === 'dark' ? byFiligranDark
: byFiligranLight)}
className={classes.byFiligranLogo}
/>
</div>
)}
{isLocal && !reset && (
<Paper variant="outlined" classes={{ root: classes.login }}>
<LoginForm onSubmit={onSubmit} />
<div style={{ marginBottom: 10, cursor: 'pointer' }}>
<a onClick={() => setReset(true)}>{t('I forgot my password')}</a>
</div>
{isLoginMessage && (
<Paper classes={{ root: classes.paper }} variant="outlined">
<Markdown>{loginMessage}</Markdown>
</Paper>
)}
{isLocal && reset && <Reset onCancel={() => setReset(false)} />}
<Box
sx={{
marginTop: 2.5,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: 2.5,
}}
>
{(isOpenId || isSaml2) && [...(openidProviders ?? []), ...(saml2Providers ?? [])].map(
(provider) => (
<LoginSSOButton
key={provider.provider_name}
providerName={provider.provider_login}
providerUri={provider.provider_uri}
/>
),
)}
<LoginError />
</Box>
{isConsentMessage && (
<Paper classes={{ root: classes.paper }} variant="outlined">
<Markdown>{consentMessage}</Markdown>
<Box display="flex" justifyContent="center" alignItems="center">
<Markdown>{consentConfirmText}</Markdown>
<Checkbox
name="consent"
edge="start"
onChange={handleChange}
style={{ margin: 0 }}
></Checkbox>
</Box>
</Paper>
)}
{(!isConsentMessage || (isConsentMessage && checked)) && (
<>
{isLocal && !reset && (
<Paper variant="outlined" classes={{ root: classes.login }}>
<LoginForm onSubmit={onSubmit}/>
<div style={{ marginBottom: 10, cursor: 'pointer' }}>
<a onClick={() => setReset(true)}>{t(
'I forgot my password',
)}</a>
</div>
</Paper>
)}
{isLocal && reset && <Reset onCancel={() => setReset(false)}/>}
<Box
sx={{
marginTop: 2.5,
display: 'flex',
flexDirection: 'column',
alignItems: 'center',
gap: 2.5,
}}
>
{(isOpenId || isSaml2) && [...(openidProviders ?? []),
...(saml2Providers ?? [])].map(
(provider) => (
<LoginSSOButton
key={provider.provider_name}
providerName={provider.provider_login}
providerUri={provider.provider_uri}
/>
),
)}
<LoginError/>
</Box>
</>
)}
</div>
);
};
Expand Down
13 changes: 7 additions & 6 deletions openbas-front/src/utils/api-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2001,6 +2001,7 @@ export interface PlatformSettings {
platform_light_theme?: ThemeInput;
platform_name?: string;
platform_openid_providers?: OAuthProvider[];
platform_policies?: PolicyInput;
platform_theme?: string;
platform_version?: string;
platform_whitemark?: string;
Expand Down Expand Up @@ -2038,6 +2039,12 @@ export interface PlayerInput {
user_teams?: string[];
}

export interface PolicyInput {
platform_consent_confirm_text?: string;
platform_consent_message?: string;
platform_login_message?: string;
}

export interface PropertySchemaDTO {
schema_property_name: string;
schema_property_type_array?: boolean;
Expand Down Expand Up @@ -2299,12 +2306,6 @@ export interface ScenarioRecurrenceInput {
scenario_recurrence_start?: string;
}

export interface PolicyInput {
platform_login_message?: string;
platform_consent_message?: string;
platform_consent_confirm_text?: string;
}

export interface ScenarioSimple {
scenario_id?: string;
scenario_name?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public class Setting implements Base {
@JsonProperty("setting_value")
private String value;

public Setting(String key, SectionEnum section, String value) {
this.key = key;
public Setting(SectionEnum section, String key, String value) {
this.section = section;
this.key = key;
this.value = value;
}

Expand Down

0 comments on commit 524b669

Please sign in to comment.