Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added PermissionsAdministration. #31

Merged
merged 3 commits into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
994 changes: 497 additions & 497 deletions src/js/actions/VoterActions.js

Large diffs are not rendered by default.

82 changes: 41 additions & 41 deletions src/js/actions/VoterSessionActions.js
Original file line number Diff line number Diff line change
@@ -1,41 +1,41 @@
import Dispatcher from '../common/dispatcher/Dispatcher';
// eslint-disable-next-line import/no-cycle
import AppObservableStore from '../stores/AppObservableStore';
import Cookies from '../common/utils/js-cookie/Cookies';
import stringContains from '../common/utils/stringContains';

export default {
voterSignOut (signOutAllDevices = false) {
AppObservableStore.setShowSignInModal(false);
AppObservableStore.unsetStoreSignInStartFullUrl();
Dispatcher.loadEndpoint('voterSignOut', { sign_out_all_devices: signOutAllDevices });
const names = [
'voter_device_id',
'ballot_has_been_visited',
'location_guess_closed',
'number_of_ballot_choices_made',
'number_of_topic_choices_made',
'show_full_navigation',
'sign_in_opened_from_issue_follow',
'sign_in_start_full_url',
];
for (let i = 0; i < names.length; i++) {
const name = names[i];
Cookies.remove(name);
Cookies.remove(name, { path: '/' });
Cookies.remove(name, { path: '/', domain: 'wevote.us' });
}
},

setVoterDeviceIdCookie (id) {
let { hostname } = window.location;
hostname = hostname || '';
console.log('VoterSessionActions setVoterDeviceIdCookie hostname:', hostname);
if (hostname && stringContains('wevote.us', hostname)) {
// If hanging off WeVote subdomain, store the cookie with top level domain
Cookies.set('voter_device_id', id, { expires: 10000, path: '/', domain: 'wevote.us' });
} else {
Cookies.set('voter_device_id', id, { expires: 10000, path: '/' });
}
},
};
// import Dispatcher from '../common/dispatcher/Dispatcher';
// // eslint-disable-next-line import/no-cycle
// import AppObservableStore from '../stores/AppObservableStore';
// import Cookies from '../common/utils/js-cookie/Cookies';
// import stringContains from '../common/utils/stringContains';
//
// export default {
// voterSignOut (signOutAllDevices = false) {
// AppObservableStore.setShowSignInModal(false);
// AppObservableStore.unsetStoreSignInStartFullUrl();
// Dispatcher.loadEndpoint('voterSignOut', { sign_out_all_devices: signOutAllDevices });
// const names = [
// 'voter_device_id',
// 'ballot_has_been_visited',
// 'location_guess_closed',
// 'number_of_ballot_choices_made',
// 'number_of_topic_choices_made',
// 'show_full_navigation',
// 'sign_in_opened_from_issue_follow',
// 'sign_in_start_full_url',
// ];
// for (let i = 0; i < names.length; i++) {
// const name = names[i];
// Cookies.remove(name);
// Cookies.remove(name, { path: '/' });
// Cookies.remove(name, { path: '/', domain: 'wevote.us' });
// }
// },
//
// setVoterDeviceIdCookie (id) {
// let { hostname } = window.location;
// hostname = hostname || '';
// console.log('VoterSessionActions setVoterDeviceIdCookie hostname:', hostname);
// if (hostname && stringContains('wevote.us', hostname)) {
// // If hanging off WeVote subdomain, store the cookie with top level domain
// Cookies.set('voter_device_id', id, { expires: 10000, path: '/', domain: 'wevote.us' });
// } else {
// Cookies.set('voter_device_id', id, { expires: 10000, path: '/' });
// }
// },
// };
5 changes: 3 additions & 2 deletions src/js/components/Navigation/HeaderBar.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import { hasIPhoneNotch } from '../../common/utils/cordovaUtils';
import { normalizedHrefPage } from '../../common/utils/hrefUtils';
import { renderLog } from '../../common/utils/logging';
import { useConnectAppContext } from '../../contexts/ConnectAppContext';
import { clearSignedInGlobals } from '../../contexts/contextFunctions';
import { useLogoutMutation } from '../../react-query/mutations';
import weConnectQueryFn, { METHOD } from '../../react-query/WeConnectQuery';
import { displayTopMenuShadow } from '../../utils/applicationUtils';
Expand All @@ -20,7 +21,7 @@ import HeaderBarLogo from './HeaderBarLogo';
const HeaderBar = ({ hideTabs }) => {
renderLog('HeaderBar');
const navigate = useNavigate();
const { setAppContextValue, getAppContextValue } = useConnectAppContext();
const { getAppContextValue, setAppContextValue } = useConnectAppContext();
const { mutate: mutateLogout } = useLogoutMutation();

const [scrolledDown] = useState(false);
Expand All @@ -39,7 +40,7 @@ const HeaderBar = ({ hideTabs }) => {
const logoutApi = async () => {
const data = await weConnectQueryFn('logout', {}, METHOD.POST);
console.log(`/logout response in HeaderBar -- status: '${'status'}', data: ${JSON.stringify(data)}`);
setAppContextValue('isAuthenticated', false);
clearSignedInGlobals(setAppContextValue);
navigate('/login');
mutateLogout();
};
Expand Down
11 changes: 3 additions & 8 deletions src/js/components/Person/AddPersonDrawerMainContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { getTeamMembersListByTeamId } from '../../models/TeamModel';
import makeRequestParams from '../../react-query/makeRequestParams';
import { useAddPersonToTeamMutation } from '../../react-query/mutations';
import { SpanWithLinkStyle } from '../Style/linkStyles';
import { SearchBarWrapper, MatchingPerson } from '../Style/sharedStyles';
import AddPersonForm from './AddPersonForm';


Expand Down Expand Up @@ -116,6 +117,7 @@ const AddPersonDrawerMainContent = () => {
};
mutate(makeRequestParams(plainParams, {}));
// Remove this person from the All People less Adds list (since they were added to the team)

const updatedRemainingPeopleToAdd = remainingPeopleToAdd.filter((person) => person.personId !== incomingPerson.personId);
setRemainingPeopleToAdd(updatedRemainingPeopleToAdd);
if (searchResultsList && searchResultsList.length >= 0) {
Expand Down Expand Up @@ -177,10 +179,7 @@ const AddPersonDrawerMainContentWrapper = styled('div')`
const AddPersonWrapper = styled('div')`
margin-top: 32px;
`;
const MatchingPerson = styled('div')`
margin: 10px 0 0 10px;
font-style: italic;
`;


// const PersonDirectoryWrapper = styled('div')`
// margin-top: 16px;
Expand All @@ -200,8 +199,4 @@ const PersonSearchResultsWrapper = styled('div')`
margin-top: 16px;
`;

const SearchBarWrapper = styled('div')`
margin-bottom: 16px;
`;

export default AddPersonDrawerMainContent;
2 changes: 0 additions & 2 deletions src/js/components/Person/EditPersonForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@ const EditPersonForm = ({ classes }) => {
// console.log('savePerson data:', JSON.stringify(activePerson));

const data = {};
// for (const key in activePerson) {
Object.keys(activePerson).forEach((key) => {
const initialValue = initialPerson[key] || '';
const activeValue = activePerson[key] || '';
Expand All @@ -55,7 +54,6 @@ const EditPersonForm = ({ classes }) => {
};

mutate(makeRequestParams(plainParams, data));
// personSave(makeRequestParams(plainParams, data));
setSaveButtonActive(false);
};

Expand Down
3 changes: 2 additions & 1 deletion src/js/components/PrivateRoute.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { METHOD, useFetchData } from '../react-query/WeConnectQuery';

const PrivateRoute = () => {
const location = useLocation();
const { getAppContextValue } = useConnectAppContext();
const { getAppContextValue, setAppContextValue } = useConnectAppContext();

const [isAuthenticated, setIsAuthenticated] = useState(null);

Expand All @@ -15,6 +15,7 @@ const PrivateRoute = () => {
if (isSuccessAuth) {
console.log('useFetchData in PrivateRoute useEffect dataAuth good:', dataAuth, isSuccessAuth);
setIsAuthenticated(dataAuth.isAuthenticated);
setAppContextValue('loggedInPersonIsAdmin', dataAuth.loggedInPersonIsAdmin);
authLog('========= PrivateRoute =========== INNER isAuthenticated: ', dataAuth.isAuthenticated);
}
}, [dataAuth, isSuccessAuth]);
Expand Down
11 changes: 11 additions & 0 deletions src/js/components/Style/sharedStyles.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import styled from 'styled-components';

export const SearchBarWrapper = styled('div')`
margin-bottom: 16px;
display: flex;
`;

export const MatchingPerson = styled('div')`
margin: 10px 0 0 10px;
font-style: italic;
`;
6 changes: 2 additions & 4 deletions src/js/components/Team/AddTeamDrawerMainContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@ import React, { useState } from 'react';
import styled from 'styled-components';
import SearchBar2024 from '../../common/components/Search/SearchBar2024';
import { renderLog } from '../../common/utils/logging';
import AddTeamForm from './AddTeamForm';
import { useConnectAppContext } from '../../contexts/ConnectAppContext';
import { SearchBarWrapper } from '../Style/sharedStyles';
import AddTeamForm from './AddTeamForm';


// eslint-disable-next-line no-unused-vars
Expand Down Expand Up @@ -82,9 +83,6 @@ const AddTeamWrapper = styled('div')`
margin-top: 32px;
`;

const SearchBarWrapper = styled('div')`
margin-bottom: 16px;
`;

const TeamItem = styled('div')`
`;
Expand Down
5 changes: 3 additions & 2 deletions src/js/contexts/ConnectAppContext.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,10 @@ export const ConnectAppContextProvider = ({ children }) => {
if (isSuccessAuth) {
console.log('useFetchData in ConnectAppContext useEffect dataAuth good:', dataAuth, isSuccessAuth, isFetchingAuth);
const { isAuthenticated } = dataAuth;
setAppContextValue('isAuthenticated', isAuthenticated);
setAppContextValue('authenticatedPersonId', dataAuth.personId);
setAppContextValue('authenticatedPerson', dataAuth.person);
setAppContextValue('authenticatedPersonId', dataAuth.personId);
setAppContextValue('isAuthenticated', isAuthenticated);
setAppContextValue('loggedInPersonIsAdmin', dataAuth.loggedInPersonIsAdmin);

console.log('=============== ConnectAppContextProvider ======= isAuthenticated: ', isAuthenticated, ' ===========');
}
Expand Down
8 changes: 8 additions & 0 deletions src/js/contexts/contextFunctions.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@

export const clearSignedInGlobals = (setAppContextValue) => {
setAppContextValue('authenticatedPerson', undefined);
setAppContextValue('authenticatedPersonId', -1);
setAppContextValue('isAuthenticated', false);
setAppContextValue('loggedInPersonIsAdmin', false);
setAppContextValue('personIsSignedIn', false);
};
38 changes: 20 additions & 18 deletions src/js/pages/Login.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { Button, TextField } from '@mui/material';
import { withStyles } from '@mui/styles';
import { useQueryClient } from '@tanstack/react-query';
import PropTypes from 'prop-types';
import React, { useEffect, useRef, useState } from 'react';
import { Helmet } from 'react-helmet-async';
Expand All @@ -12,18 +13,19 @@ import { PageContentContainer } from '../components/Style/pageLayoutStyles';
import VerifySecretCodeModal from '../components/VerifySecretCodeModal';
import webAppConfig from '../config';
import { useConnectAppContext } from '../contexts/ConnectAppContext';
import { clearSignedInGlobals } from '../contexts/contextFunctions';
import { getFullNamePreferredPerson } from '../models/PersonModel';
import { useGetAuthMutation, useLogoutMutation } from '../react-query/mutations';
import { useLogoutMutation } from '../react-query/mutations';
import weConnectQueryFn, { METHOD, useFetchData } from '../react-query/WeConnectQuery';
import ReactQuerySaveReadTest from '../test/ReactQuerySaveReadTest';


const Login = ({ classes }) => {
renderLog('Login'); // Set LOG_RENDER_EVENTS to log all renders
renderLog('Login');
const navigate = useNavigate();
const queryClient = useQueryClient();
const { setAppContextValue } = useConnectAppContext();
const { mutate: mutateLogout } = useLogoutMutation();
const { mutate: mutateAuth } = useGetAuthMutation();

const firstNameFldRef = useRef('');
const lastNameFldRef = useRef('');
Expand All @@ -35,30 +37,29 @@ const Login = ({ classes }) => {
const passwordFldRef = useRef('');
const confirmPasswordFldRef = useRef('');

const [showCreateStuff, setShowCreateStuff] = useState(false);
const [warningLine, setWarningLine] = useState('');
const [successLine, setSuccessLine] = useState('');
const [authPerson, setAuthPerson] = useState({});
// eslint-disable-next-line no-unused-vars
const [isAuth, setIsAuth] = useState(false);
const [openVerifyModalDialog, setOpenVerifyModalDialog] = useState(false);
const [returnFromLogin, setReturnFromLogin] = useState(false);
const [showCreateStuff, setShowCreateStuff] = useState(false);
const [successLine, setSuccessLine] = useState('');
const [warningLine, setWarningLine] = useState('');

const { data: dataAuth, isSuccess: isSuccessAuth, isFetching: isFetchingAuth } = useFetchData(['get-auth'], {}, METHOD.POST);
useEffect(() => {
if (isSuccessAuth) {
console.log('useFetchData in Login useEffect dataAuth good:', dataAuth, isSuccessAuth, isFetchingAuth);

const { isAuthenticated } = dataAuth;
setIsAuth(isAuthenticated);
const authenticatedPerson = dataAuth.person;
setAuthPerson(authenticatedPerson);
const success = isAuthenticated && authenticatedPerson ? `Signed in as ${getFullNamePreferredPerson(authenticatedPerson)}` : 'Please sign in';
setSuccessLine(success);
// if (isAuthenticated) {
// setTimeout(() => {
// navigate('/tasks');
// }, 2000);
// }
setAppContextValue('loggedInPersonIsAdmin', dataAuth.loggedInPersonIsAdmin);
if (isAuthenticated && returnFromLogin) {
setTimeout(() => {
navigate('/tasks');
}, 2000);
}
}
}, [dataAuth, isSuccessAuth]);

Expand All @@ -79,10 +80,11 @@ const Login = ({ classes }) => {
setSuccessLine(`Cheers person #${data.personId}! You are signed in!`);
setAppContextValue('isAuthenticated', true);
setAppContextValue('authenticatedPersonId', data.personId);
setReturnFromLogin(true);
if (!data.emailVerified) {
setOpenVerifyModalDialog(true);
}
mutateAuth(); // to propagate the invalidation to HeaderBar (might be a better way to do this)
await queryClient.invalidateQueries('get-auth');
} else {
setWarningLine(data.error.msg);
setSuccessLine('');
Expand Down Expand Up @@ -152,8 +154,8 @@ const Login = ({ classes }) => {
}
};

const signOutPressed = () => {
setAppContextValue('personIsSignedIn', false);
const useSignOutPressed = () => {
clearSignedInGlobals(setAppContextValue);
logoutApi().then();
};

Expand Down Expand Up @@ -303,7 +305,7 @@ const Login = ({ classes }) => {
classes={{ root: classes.buttonDesktop }}
color="primary"
variant="contained"
onClick={signOutPressed}
onClick={useSignOutPressed}
>
Sign Out
</Button>
Expand Down
Loading
Loading