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

#1642 & #1559 #1647

Merged
merged 11 commits into from
Jan 17, 2024
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Convert staff emails to lower case

Revision ID: 097d41841ba4
Revises: 65cb91595d6a
Create Date: 2024-01-11 14:04:10.156478

"""
import sqlalchemy as sa
from alembic import op
from sqlalchemy.sql import column, table


# revision identifiers, used by Alembic.
revision = '097d41841ba4'
down_revision = '65cb91595d6a'
branch_labels = None
depends_on = None


def upgrade():
# ### commands auto generated by Alembic - please adjust! ###
conn = op.get_bind()
staff_table = table('staffs',
column('id', sa.Integer),
column('name', sa.String),
column('phone',sa.String),
column('email', sa.String),
column('is_active', sa.Boolean),
column('position_id', sa.Integer)
)

conn.execute(
staff_table.update()\
.values(email=sa.func.lower(staff_table.c.email))
)

# ### end Alembic commands ###


def downgrade():
# ### commands auto generated by Alembic - please adjust! ###
pass
# ### end Alembic commands ###
2 changes: 1 addition & 1 deletion epictrack-api/src/api/models/work_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
"""Model to handle all operations related to WorkStatus."""
from __future__ import annotations

from typing import List, Dict
from typing import Dict, List

from sqlalchemy import Boolean, Column, DateTime, ForeignKey, Integer, String, desc
from sqlalchemy.orm import relationship
Expand Down
25 changes: 22 additions & 3 deletions epictrack-api/src/api/schemas/request/staff_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
"""Staff resource's input validations"""
from marshmallow import fields, validate
from marshmallow import fields, pre_load, validate

from api.schemas.validators import Phone

Expand Down Expand Up @@ -47,6 +47,13 @@ class StaffExistanceQueryParamSchema(RequestQueryParameterSchema):
missing=None,
)

@pre_load
def convert_email_to_lower(self, data, **kwargs): # pylint: disable=unused-argument
"""Converts staff email into lower case string"""
data = dict(data)
data["email"] = data["email"].lower()
return data


class StaffByPositionsQueryParamSchema(BasicRequestQueryParameterSchema):
"""Staff by positions query parameter"""
Expand Down Expand Up @@ -88,10 +95,15 @@ class StaffBodyParameterSchema(RequestBodyParameterSchema):
)

is_active = fields.Boolean(
metadata={"description": "Active status of the staff"},
required=True
metadata={"description": "Active status of the staff"}, required=True
)

@pre_load
def convert_email_to_lower(self, data, **kwargs): # pylint: disable=unused-argument
"""Converts staff email into lower case string"""
data["email"] = data["email"].lower()
return data
salabh-aot marked this conversation as resolved.
Show resolved Hide resolved


class StaffEmailPathParameterSchema(RequestPathParameterSchema):
"""Staff email path parameter schema"""
Expand All @@ -101,3 +113,10 @@ class StaffEmailPathParameterSchema(RequestPathParameterSchema):
validate=validate.Email(),
required=True,
)

@pre_load
def convert_email_to_lower(self, data, **kwargs): # pylint: disable=unused-argument
"""Converts staff email into lower case string"""
data = dict(data)
data["email"] = data["email"].lower()
return data
3 changes: 1 addition & 2 deletions epictrack-api/src/api/schemas/request/task_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ class TaskBodyParameterSchema(RequestBodyParameterSchema):

tips = fields.Str(
metadata={"description": "Practical info on why/how to do the task"},
# validate=validate.Length(max=150),
required=True,
allow_none=True
)

number_of_days = fields.Int(
Expand Down
1 change: 0 additions & 1 deletion epictrack-api/src/api/schemas/request/work_request.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ class WorkStatusParameterSchema(RequestBodyParameterSchema):

description = fields.Str(
metadata={"description": "description of status"},
validate=validate.Length(max=500),
required=True,
salabh-aot marked this conversation as resolved.
Show resolved Hide resolved
)

Expand Down
1 change: 1 addition & 0 deletions epictrack-api/src/api/services/staff.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ def import_staffs(cls, file: IO):
username = TokenInfo.get_username()
data["created_by"] = username
data = data.to_dict("records")
data["email"] = data["email"].lower()
db.session.bulk_insert_mappings(Staff, data)
db.session.commit()
return "Inserted successfully"
Expand Down
3 changes: 3 additions & 0 deletions epictrack-api/src/api/services/task_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
"""Service to manage Task Templates."""
from typing import IO, List

import numpy as np
import pandas as pd
from flask import current_app
from sqlalchemy.sql import exists
Expand Down Expand Up @@ -47,6 +48,8 @@ def create_task_template(cls, data: dict, template_file: IO) -> TaskTemplate:
{"responsibility_id": res.id},
regex=True,
)
task_data = task_data.replace({np.nan: None})
task_data = task_data.replace({np.NaN: None})
tasks = task_data.to_dict("records")
cls.create_bulk_tasks(tasks)
TaskTemplate.commit()
Expand Down
16 changes: 6 additions & 10 deletions epictrack-web/src/components/workPlan/issues/IssuesForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@ import * as yup from "yup";
import { yupResolver } from "@hookform/resolvers/yup";
import { Box, FormControlLabel, Grid, Stack, Tooltip } from "@mui/material";
import ControlledTextField from "../../shared/controlledInputComponents/ControlledTextField";
import { ETFormLabelWithCharacterLimit, ETParagraph } from "../../shared";
import {
ETFormLabel,
ETFormLabelWithCharacterLimit,
ETParagraph,
} from "../../shared";
import ControlledSwitch from "../../shared/controlledInputComponents/ControlledSwitch";
import { IssuesContext } from "./IssuesContext";
import { IconProps } from "../../icons/type";
Expand Down Expand Up @@ -141,19 +145,11 @@ const IssuesForm = () => {
/>
</Grid>
<Grid item xs={12}>
<ETFormLabelWithCharacterLimit
characterCount={watchedDescription.length}
maxCharacterLength={descriptionCharacterLimit}
>
Description
</ETFormLabelWithCharacterLimit>
<ETFormLabel>Description</ETFormLabel>
salabh-aot marked this conversation as resolved.
Show resolved Hide resolved
<ControlledTextField
name="description"
fullWidth
size="small"
inputProps={{
maxLength: descriptionCharacterLimit,
}}
multiline
rows={4}
/>
Expand Down
12 changes: 1 addition & 11 deletions epictrack-web/src/components/workPlan/status/StatusForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ const schema = yup.object().shape({
posted_date: yup.string().required("Date is required"),
description: yup.string().required("Description is required"),
});
const CHARACTER_LIMIT = 500;

const StatusForm = () => {
const [description, setDescription] = React.useState<string>("");
Expand Down Expand Up @@ -93,22 +92,13 @@ const StatusForm = () => {
/>
</Grid>
<Grid item xs={12}>
<ETFormLabelWithCharacterLimit
characterCount={description.length}
maxCharacterLength={CHARACTER_LIMIT}
required
>
Description
</ETFormLabelWithCharacterLimit>
<ETFormLabel>Description</ETFormLabel>
salabh-aot marked this conversation as resolved.
Show resolved Hide resolved
<ControlledTextField
name="description"
multiline
rows={4}
onChange={handleDescriptionChange}
fullWidth
inputProps={{
maxLength: CHARACTER_LIMIT,
}}
/>
</Grid>
</Grid>
Expand Down
Loading