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,93 @@
"""remove char limit for work status and work issue description

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! ###
with op.batch_alter_table('work_issue_updates', schema=None) as batch_op:
batch_op.alter_column('description',
existing_type=sa.VARCHAR(length=2000),
type_=sa.Text(),
existing_nullable=False)

with op.batch_alter_table('work_issue_updates_history', schema=None) as batch_op:
batch_op.alter_column('description',
existing_type=sa.VARCHAR(length=2000),
type_=sa.Text(),
existing_nullable=False,
autoincrement=False)

with op.batch_alter_table('work_statuses', schema=None) as batch_op:
batch_op.alter_column('description',
existing_type=sa.VARCHAR(length=2000),
type_=sa.Text(),
existing_nullable=False)

with op.batch_alter_table('work_statuses_history', schema=None) as batch_op:
batch_op.alter_column('description',
existing_type=sa.VARCHAR(length=2000),
type_=sa.Text(),
existing_nullable=False,
autoincrement=False)

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! ###
with op.batch_alter_table('work_statuses_history', schema=None) as batch_op:
batch_op.alter_column('description',
existing_type=sa.Text(),
type_=sa.VARCHAR(length=2000),
existing_nullable=False,
autoincrement=False)

with op.batch_alter_table('work_statuses', schema=None) as batch_op:
batch_op.alter_column('description',
existing_type=sa.Text(),
type_=sa.VARCHAR(length=2000),
existing_nullable=False)

with op.batch_alter_table('work_issue_updates_history', schema=None) as batch_op:
batch_op.alter_column('description',
existing_type=sa.Text(),
type_=sa.VARCHAR(length=2000),
existing_nullable=False,
autoincrement=False)

with op.batch_alter_table('work_issue_updates', schema=None) as batch_op:
batch_op.alter_column('description',
existing_type=sa.Text(),
type_=sa.VARCHAR(length=2000),
existing_nullable=False)
# ### end Alembic commands ###
4 changes: 2 additions & 2 deletions epictrack-api/src/api/models/work_issue_updates.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# limitations under the License.
"""Model to handle all operations related to Issues."""

from sqlalchemy import Boolean, Column, ForeignKey, Integer, String
from sqlalchemy import Boolean, Column, ForeignKey, Integer, String, Text
from sqlalchemy.orm import relationship

from .base_model import BaseModelVersioned
Expand All @@ -25,7 +25,7 @@ class WorkIssueUpdates(BaseModelVersioned):
__tablename__ = 'work_issue_updates'

id = Column(Integer, primary_key=True, autoincrement=True)
description = Column(String(2000), nullable=False)
description = Column(Text(), nullable=False)

is_approved = Column(Boolean(), default=False, nullable=True)
approved_by = Column(String(255), default=None, nullable=True)
Expand Down
6 changes: 3 additions & 3 deletions epictrack-api/src/api/models/work_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@
"""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 import Boolean, Column, DateTime, ForeignKey, Integer, String, Text, desc
from sqlalchemy.orm import relationship

from .base_model import BaseModelVersioned
Expand All @@ -28,7 +28,7 @@ class WorkStatus(BaseModelVersioned):
__tablename__ = 'work_statuses'

id = Column(Integer, primary_key=True, autoincrement=True)
description = Column(String(2000), nullable=False)
description = Column(Text(), nullable=False)
posted_date = Column(DateTime(timezone=True), nullable=False)
posted_by = Column(String(100), nullable=True)
work_id = Column(ForeignKey('works.id'), nullable=False)
Expand Down
8 changes: 7 additions & 1 deletion 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 @@ -92,6 +92,12 @@ class StaffBodyParameterSchema(RequestBodyParameterSchema):
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 Down
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
5 changes: 3 additions & 2 deletions epictrack-api/src/api/services/staff.py
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ def find_by_id(cls, _id):
@classmethod
def check_existence(cls, email, staff_id=None):
"""Checks if a staff exists with given email address"""
return Staff.check_existence(email, staff_id)
return Staff.check_existence(email.lower(), staff_id)

@classmethod
def find_by_email(cls, email):
"""Find staff by email address"""
return Staff.find_by_email(email)
return Staff.find_by_email(email.lower())
salabh-aot marked this conversation as resolved.
Show resolved Hide resolved

@classmethod
def import_staffs(cls, file: IO):
Expand All @@ -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