Skip to content

Commit

Permalink
Merge pull request #1096 from cityofaustin/13274-track-the-mug
Browse files Browse the repository at this point in the history
Adds MUG tracking to user profiles
  • Loading branch information
johnclary authored Aug 16, 2023
2 parents bf4612d + 042ce80 commit 81431dc
Show file tree
Hide file tree
Showing 11 changed files with 143 additions and 43 deletions.
2 changes: 2 additions & 0 deletions moped-api/users/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ def generate_user_profile(cognito_id: str, json_data: dict) -> dict:
"title": json_data.get("title", None),
"workgroup_id": json_data.get("workgroup_id", None),
"roles": json_data.get("roles", None),
"is_user_group_member": json_data.get("is_user_group_member", False),
"note": json_data.get("note", None),
}


Expand Down
10 changes: 10 additions & 0 deletions moped-api/users/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,16 @@
"minlength": 1,
"maxlength": 3,
},
"is_user_group_member": {
"type": "boolean",
"nullable": True,
"required": False,
},
"note": {
"type": "string",
"nullable": True,
"required": False,
},
}

PASSWORD_VALIDATION_SCHEMA = {
Expand Down
82 changes: 46 additions & 36 deletions moped-database/metadata/tables.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4443,88 +4443,98 @@
permission:
check: {}
columns:
- is_coa_staff
- cognito_user_id
- date_added
- email
- user_id
- workgroup_id
- roles
- first_name
- is_coa_staff
- is_deleted
- is_user_group_member
- last_name
- note
- picture
- roles
- title
- date_added
- cognito_user_id
- is_deleted
- user_id
- workgroup_id
select_permissions:
- role: moped-admin
permission:
columns:
- is_coa_staff
- cognito_user_id
- date_added
- email
- user_id
- workgroup_id
- roles
- first_name
- is_coa_staff
- is_deleted
- is_user_group_member
- last_name
- note
- picture
- roles
- title
- date_added
- cognito_user_id
- is_deleted
- user_id
- workgroup_id
filter: {}
allow_aggregations: true
- role: moped-editor
permission:
columns:
- is_coa_staff
- cognito_user_id
- date_added
- email
- user_id
- workgroup_id
- roles
- first_name
- is_coa_staff
- is_deleted
- is_user_group_member
- last_name
- note
- picture
- roles
- title
- date_added
- cognito_user_id
- is_deleted
- user_id
- workgroup_id
filter: {}
allow_aggregations: true
- role: moped-viewer
permission:
columns:
- is_coa_staff
- cognito_user_id
- date_added
- email
- user_id
- workgroup_id
- roles
- first_name
- is_coa_staff
- is_deleted
- is_user_group_member
- last_name
- note
- picture
- roles
- title
- date_added
- cognito_user_id
- is_deleted
- user_id
- workgroup_id
filter: {}
allow_aggregations: true
update_permissions:
- role: moped-admin
permission:
columns:
- cognito_user_id
- date_added
- email
- first_name
- is_coa_staff
- is_deleted
- is_user_group_member
- last_name
- note
- picture
- roles
- title
- user_id
- workgroup_id
- cognito_user_id
- date_added
- is_coa_staff
- email
- roles
- picture
- is_deleted
filter: {}
check: null
check: {}
- role: moped-editor
permission:
columns:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE moped_users
DROP COLUMN is_user_group_member,
DROP COLUMN note;
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ALTER TABLE moped_users
ADD COLUMN is_user_group_member boolean NOT NULL DEFAULT FALSE,
ADD COLUMN note text;

COMMENT ON COLUMN moped_users.is_user_group_member IS 'Tracks if the user is a member of the Moped User Group, aka the MUG.';

COMMENT ON COLUMN moped_users.note IS 'A place to add any notes about this user, e.g. why they were deactivated.';
6 changes: 3 additions & 3 deletions moped-database/seeds/1602292389297_initial_seed_staging.sql
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,9 @@ INSERT INTO public.feature_street_segments (id, component_id, ctn_segment_id, fr
-- Data for Name: moped_users; Type: TABLE DATA; Schema: public; Owner: moped
--

INSERT INTO public.moped_users (first_name, last_name, title, user_id, workgroup_id, cognito_user_id, date_added, is_coa_staff, email, roles, picture, is_deleted) VALUES ('JD', 'Maccombs', 'Software Developer', 1, 18, NULL, '2021-03-09 17:08:14+00', true, '[email protected]', '["moped-admin"]', NULL, false);
INSERT INTO public.moped_users (first_name, last_name, title, user_id, workgroup_id, cognito_user_id, date_added, is_coa_staff, email, roles, picture, is_deleted) VALUES ('Michael', 'Chernus', 'Engineer', 3, 1, NULL, '2020-10-09 13:44:02.15918+00', false, '[email protected]', '["moped-editor"]', NULL, false);
INSERT INTO public.moped_users (first_name, last_name, title, user_id, workgroup_id, cognito_user_id, date_added, is_coa_staff, email, roles, picture, is_deleted) VALUES ('Patricia', 'Arquette', 'Engineer', 2, 1, NULL, '2020-10-09 13:44:02.159184+00', false, '[email protected]', '["moped-editor"]', NULL, false);
INSERT INTO public.moped_users (first_name, last_name, title, user_id, workgroup_id, cognito_user_id, date_added, is_coa_staff, email, roles, picture, is_deleted, is_user_group_member, note) VALUES ('JD', 'Maccombs', 'Software Developer', 1, 18, NULL, '2021-03-09 17:08:14+00', true, '[email protected]', '["moped-admin"]', NULL, false, false, 'JD was contracted to assist with the initial Moped research and build out.');
INSERT INTO public.moped_users (first_name, last_name, title, user_id, workgroup_id, cognito_user_id, date_added, is_coa_staff, email, roles, picture, is_deleted, is_user_group_member, note) VALUES ('Michael', 'Chernus', 'Engineer', 3, 1, NULL, '2020-10-09 13:44:02.15918+00', false, '[email protected]', '["moped-editor"]', NULL, false, false, NULL);
INSERT INTO public.moped_users (first_name, last_name, title, user_id, workgroup_id, cognito_user_id, date_added, is_coa_staff, email, roles, picture, is_deleted, is_user_group_member, note) VALUES ('Patricia', 'Arquette', 'Engineer', 2, 1, NULL, '2020-10-09 13:44:02.159184+00', false, '[email protected]', '["non-login-user"]', NULL, false, true, NULL);



Expand Down
8 changes: 8 additions & 0 deletions moped-editor/src/queries/staff.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ export const GET_ALL_USERS = gql`
workgroup_id
workgroup_name
}
is_user_group_member
note
}
}
`;
Expand All @@ -32,6 +34,8 @@ export const GET_USER = gql`
email
roles
is_deleted
is_user_group_member
note
}
}
`;
Expand All @@ -54,6 +58,8 @@ export const ADD_NON_MOPED_USER = gql`
email
roles
is_deleted
is_user_group_member
note
}
}
`;
Expand All @@ -73,6 +79,8 @@ export const UPDATE_NON_MOPED_USER = gql`
email
roles
is_deleted
is_user_group_member
note
}
}
`;
3 changes: 3 additions & 0 deletions moped-editor/src/views/staff/NewStaffView.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ export const initialFormValues = {
password: "",
workgroup_id: null,
roles: ["moped-editor"],
is_user_group_member: false,
note: "",
};

const newUserRoleOptions = [
Expand Down Expand Up @@ -71,6 +73,7 @@ const NewStaffView = () => {

const isNonLoginUser = isUserNonLoginUser(data.roles);

console.log("Submitted data is: ", data);
if (isNonLoginUser) {
// Remove the password for the non-login user create mutation
const { password, ...restOfData } = data;
Expand Down
52 changes: 51 additions & 1 deletion moped-editor/src/views/staff/StaffForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,8 @@ const StaffForm = ({
</FormControl>
)}
</Grid>
<Grid item xs={12} md={6}>

<Grid item xs={12} md={3}>
<FormControl variant="standard" component="fieldset">
<FormLabel id="roles-label">Role</FormLabel>
<Controller
Expand All @@ -324,6 +325,55 @@ const StaffForm = ({
/>
</FormControl>
</Grid>
<Grid item xs={12} md={3}>
<FormControl variant="standard" component="fieldset">
<FormLabel id="roles-label">
Moped User Group (MUG) Member
</FormLabel>
<Controller
name="is_user_group_member"
control={control}
render={({ field: { name, value, onChange } }) => (
<RadioGroup
aria-label="roles"
name={name}
value={value ? "true" : "false"}
onChange={(e) => {
const newValue = e.target.value === "true";
return onChange(newValue);
}}
>
<FormControlLabel
value="true"
control={<Radio />}
label="Yes"
disabled={!isUserActive}
/>
<FormControlLabel
value="false"
control={<Radio />}
label="No"
disabled={!isUserActive}
/>
</RadioGroup>
)}
/>
</FormControl>
</Grid>
<Grid item xs={12} md={6}>
<TextField
fullWidth
multiline
rows={4}
id="note"
label="Note"
InputLabelProps={{
shrink: true,
}}
variant="outlined"
{...register("note")}
/>
</Grid>
<Grid item xs={12} md={6}>
&nbsp;
</Grid>
Expand Down
9 changes: 7 additions & 2 deletions moped-editor/src/views/staff/StaffListView.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const staffColumns = [
{
headerName: "E-mail",
field: "email",
width: 325,
width: 200,
},
{
headerName: "Title",
Expand All @@ -67,10 +67,15 @@ const staffColumns = [
if (!props.value || !props.value[0]) {
return "N/A";
}

const role = props.value[0].replace("moped-", "");
return role.charAt(0).toUpperCase() + role.slice(1);
},
width: 125
},
{
headerName: "MUG Member",
field: "is_user_group_member",
valueGetter: (props) => (props.value ? "Yes" : "No"),
},
{
headerName: "Active",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
roleLooksGood,
passwordLooksGood,
fieldParsers,
transformFormDataIntoDatabaseTypes,
} from "../helpers";
import { useButtonStyles } from "./StaffFormButtons";

Expand Down Expand Up @@ -59,7 +60,8 @@ const NonLoginUserActivationButtons = ({
};

const handleUpdateNonLoginUser = async () => {
const { password, __typename, ...restOfFormValues } = formValues;
const { password, __typename, ...restOfFormValues } =
transformFormDataIntoDatabaseTypes(formValues);
updateNonMopedUser({
variables: {
userId: userId,
Expand Down

0 comments on commit 81431dc

Please sign in to comment.