Skip to content

Commit

Permalink
Rename 'subperiod' to 'phase', hide 'Request specific reviews' option…
Browse files Browse the repository at this point in the history
… when not in entry phase
  • Loading branch information
chazkii committed Apr 8, 2020
1 parent 54f0c23 commit dadefc9
Show file tree
Hide file tree
Showing 24 changed files with 244 additions and 234 deletions.
8 changes: 4 additions & 4 deletions README.md
Expand Up @@ -65,10 +65,10 @@ The following steps were run on a minimal install of Ubuntu LTS 18.04.4
6. Use the following commands to change phases.

```
python3 tests/scripts/configure_db.py --config host_example.ini --subperiod enrolment adjust
python3 tests/scripts/configure_db.py --config host_example.ini --subperiod entry adjust
python3 tests/scripts/configure_db.py --config host_example.ini --subperiod approval adjust
python3 tests/scripts/configure_db.py --config host_example.ini --subperiod review adjust
python3 tests/scripts/configure_db.py --config host_example.ini --phase enrolment adjust
python3 tests/scripts/configure_db.py --config host_example.ini --phase entry adjust
python3 tests/scripts/configure_db.py --config host_example.ini --phase approval adjust
python3 tests/scripts/configure_db.py --config host_example.ini --phase review adjust
```

7. For a more comprehensive guide, please see the [user guide](/docs/user-guide.pdf)
Expand Down
4 changes: 2 additions & 2 deletions adaero/forms.py
Expand Up @@ -42,10 +42,10 @@ def build_feedback_payload(context, request, is_summary):
)
if is_summary:
end_date_utc = current_period.approval_end_utc
read_only = not current_period.subperiod(location) == Period.APPROVAL_SUBPERIOD
read_only = not current_period.phase(location) == Period.APPROVAL_PHASE
else:
end_date_utc = current_period.approval_start_utc
read_only = not current_period.subperiod(location) == Period.ENTRY_SUBPERIOD
read_only = not current_period.phase(location) == Period.ENTRY_PHASE
end_date = datetimeformat(end_date_utc, enrollee.user)

if form:
Expand Down
2 changes: 1 addition & 1 deletion adaero/history.py
Expand Up @@ -51,7 +51,7 @@ def fetch_feedback_history(dbsession, username, settings, fetch_full=False):

feedbacks = []
for period, summary_form, enrollee in history:
if period.subperiod(location) != Period.REVIEW_SUBPERIOD:
if period.phase(location) != Period.REVIEW_PHASE:
feedbacks.append(
{
"periodDescription": "%s pending" % period.name,
Expand Down
8 changes: 4 additions & 4 deletions adaero/models/__init__.py
Expand Up @@ -273,14 +273,14 @@ def includeme(config):
)


def generate_period_dates(subperiod, days_away_func, days_in=1):
def generate_period_dates(phase, days_away_func, days_in=1):
if days_in not in [0, 1]:
raise ValueError("days_in must be 0 or 1")
if subperiod not in OFFSETS.keys():
if phase not in OFFSETS.keys():
raise ValueError(
"Invalid subperiod %s, please refer to Period model" % subperiod
"Invalid phase %s, please refer to Period model" % phase
)
offset = OFFSETS[subperiod]
offset = OFFSETS[phase]
return {
"enrolment_start_utc": days_away_func(0 - offset - days_in),
"entry_start_utc": days_away_func(2 - offset - days_in),
Expand Down
50 changes: 25 additions & 25 deletions adaero/models/period.py
Expand Up @@ -64,15 +64,15 @@ class Period(Base, Checkable, Serializable):
),
)

INACTIVE_SUBPERIOD = "inactive_subperiod"
ENROLMENT_SUBPERIOD = "enrolment_subperiod"
ENTRY_SUBPERIOD = "entry_subperiod"
APPROVAL_SUBPERIOD = "approval_subperiod"
REVIEW_SUBPERIOD = "review_subperiod"
INACTIVE_PHASE = "inactive_phase"
ENROLMENT_PHASE = "enrolment_phase"
ENTRY_PHASE = "entry_phase"
APPROVAL_PHASE = "approval_phase"
REVIEW_PHASE = "review_phase"

# This is only really used by emailing - a user can always view
# previous summarised feedback
REVIEW_SUBPERIOD_LEN_DAYS = 30
REVIEW_PHASE_LEN_DAYS = 30
PERIOD_LOOKAHEAD_DAYS = 120

def __repr__(self):
Expand Down Expand Up @@ -177,36 +177,36 @@ def get_email_flag_by_code(self, code):
elif code == "ust07":
return self.review_reminder_last_sent

def subperiod(self, location):
def phase(self, location):
utcnow = datetime.utcnow()
converted_dt = partial(adjust_dt_for_location, location=location)
if converted_dt(self.approval_end_utc) <= utcnow:
return self.REVIEW_SUBPERIOD
return self.REVIEW_PHASE
elif converted_dt(self.approval_start_utc) <= utcnow:
return self.APPROVAL_SUBPERIOD
return self.APPROVAL_PHASE
elif converted_dt(self.entry_start_utc) <= utcnow:
return self.ENTRY_SUBPERIOD
return self.ENTRY_PHASE
elif converted_dt(self.enrolment_start_utc) <= utcnow:
return self.ENROLMENT_SUBPERIOD
return self.ENROLMENT_PHASE
else:
return self.INACTIVE_SUBPERIOD
return self.INACTIVE_PHASE

SUBPERIOD_TO_TEMPLATE = {
REVIEW_SUBPERIOD: constants.EMAIL_TEMPLATE_MAP[constants.REVIEW_START],
APPROVAL_SUBPERIOD: constants.EMAIL_TEMPLATE_MAP[constants.APPROVE_START],
ENTRY_SUBPERIOD: constants.EMAIL_TEMPLATE_MAP[constants.ENTRY_START],
ENROLMENT_SUBPERIOD: constants.EMAIL_TEMPLATE_MAP[constants.ENROL_START],
PHASE_TO_TEMPLATE = {
REVIEW_PHASE: constants.EMAIL_TEMPLATE_MAP[constants.REVIEW_START],
APPROVAL_PHASE: constants.EMAIL_TEMPLATE_MAP[constants.APPROVE_START],
ENTRY_PHASE: constants.EMAIL_TEMPLATE_MAP[constants.ENTRY_START],
ENROLMENT_PHASE: constants.EMAIL_TEMPLATE_MAP[constants.ENROL_START],
}

def current_email_template(self, location):
try:
result = self.SUBPERIOD_TO_TEMPLATE[self.subperiod(location)]
result = self.PHASE_TO_TEMPLATE[self.phase(location)]
except KeyError:
result = None
return result

@classmethod
def get_current_period(cls, dbsession, options=None):
def get_current_period(cls, dbsession, options=None) -> "Period":
utcnow = datetime.utcnow()
query = dbsession.query(Period)
if options:
Expand All @@ -227,7 +227,7 @@ def get_current_period(cls, dbsession, options=None):
elif (
len(periods_by_date_desc) >= 2
and (utcnow - periods_by_date_desc[1].enrolment_start_utc).days
<= cls.REVIEW_SUBPERIOD_LEN_DAYS
<= cls.REVIEW_PHASE_LEN_DAYS
):
current_period = periods_by_date_desc[1]
else:
Expand All @@ -236,9 +236,9 @@ def get_current_period(cls, dbsession, options=None):


OFFSETS = {
Period.INACTIVE_SUBPERIOD: -2,
Period.ENROLMENT_SUBPERIOD: 0,
Period.ENTRY_SUBPERIOD: 2,
Period.APPROVAL_SUBPERIOD: 4,
Period.REVIEW_SUBPERIOD: 6,
Period.INACTIVE_PHASE: -2,
Period.ENROLMENT_PHASE: 0,
Period.ENTRY_PHASE: 2,
Period.APPROVAL_PHASE: 4,
Period.REVIEW_PHASE: 6,
}
26 changes: 13 additions & 13 deletions adaero/scripts/configure_db.py
Expand Up @@ -30,28 +30,28 @@
log = get_logger(__name__)


SUBPERIOD_CHOICES = {
"inactive": Period.INACTIVE_SUBPERIOD,
"enrolment": Period.ENROLMENT_SUBPERIOD,
"entry": Period.ENTRY_SUBPERIOD,
"approval": Period.APPROVAL_SUBPERIOD,
"review": Period.REVIEW_SUBPERIOD,
PHASE_CHOICES = {
"inactive": Period.INACTIVE_PHASE,
"enrolment": Period.ENROLMENT_PHASE,
"entry": Period.ENTRY_PHASE,
"approval": Period.APPROVAL_PHASE,
"review": Period.REVIEW_PHASE,
}
SUBPERIOD_KEY = "SUBPERIOD"
PHASE_KEY = "PHASE"
SETTINGS_KEY = "SETTINGS"
ENGINE_KEY = "ENGINE"


@click.group()
@click.option("--config", type=click.STRING)
@click.option("--subperiod", type=click.Choice(SUBPERIOD_CHOICES.keys()))
@click.option("--phase", type=click.Choice(PHASE_CHOICES.keys()))
@click.pass_context
def cli(ctx, config, subperiod):
def cli(ctx, config, phase):
"""This script makes manipulating the db easy"""
ctx.obj = {}
if not config.endswith(".ini"):
raise ValueError("config file %s must end in .ini" % config)
ctx.obj[SUBPERIOD_KEY] = subperiod
ctx.obj[PHASE_KEY] = phase
ctx.obj[ENGINE_KEY], ctx.obj[SETTINGS_KEY] = get_engine_from_config_filename(config)


Expand Down Expand Up @@ -186,13 +186,13 @@ def enrol_everyone(ctx):
@cli.command()
@click.pass_context
def adjust(ctx):
subperiod = SUBPERIOD_CHOICES[ctx.obj[SUBPERIOD_KEY]]
phase = PHASE_CHOICES[ctx.obj[PHASE_KEY]]
engine = ctx.obj[ENGINE_KEY]
session_factory = get_session_factory(engine)
dbsession = get_tm_session(session_factory, transaction.manager)

dates_dict = generate_period_dates(
subperiod, lambda days: datetime.utcnow() + timedelta(days=days)
phase, lambda days: datetime.utcnow() + timedelta(days=days)
)

with transaction.manager:
Expand All @@ -214,7 +214,7 @@ def generate_periods(ctx):
with transaction.manager:
for i in range(1, 3):
dates_dict = generate_period_dates(
Period.INACTIVE_SUBPERIOD,
Period.INACTIVE_PHASE,
lambda days: (
datetime.utcnow() - timedelta(days=i * 30) + timedelta(days=days)
),
Expand Down
8 changes: 4 additions & 4 deletions adaero/stats.py
Expand Up @@ -178,7 +178,7 @@ def generate_stats_payload_from_dataframe(df, dbsession, settings):
)
asc_period_names = [p[0] for p in asc_periods_by_date]
current_period_name = current_period.name
current_subperiod = current_period.subperiod(location)
current_phase = current_period.phase(location)

stats_dict = defaultdict(list)
for (
Expand Down Expand Up @@ -209,9 +209,9 @@ def generate_stats_payload_from_dataframe(df, dbsession, settings):
"enable": True,
"hasExistingSummary": False,
}
if current_subperiod not in [
Period.APPROVAL_SUBPERIOD,
Period.REVIEW_SUBPERIOD,
if current_phase not in [
Period.APPROVAL_PHASE,
Period.REVIEW_PHASE,
]:
button["buttonText"] = "Not in approval or review period"
button["enable"] = False
Expand Down
13 changes: 10 additions & 3 deletions adaero/views/auth.py
@@ -1,4 +1,4 @@
from __future__ import unicode_literals
import transaction

from pyramid.httpexceptions import HTTPUnauthorized, HTTPOk
from pyramid.security import (
Expand All @@ -12,9 +12,10 @@
from logging import getLogger as get_logger
from rest_toolkit import resource

from adaero.constants import ALLOW_PASSWORDLESS_ACCESS_KEY, BUSINESS_UNIT_KEY
from adaero.constants import ALLOW_PASSWORDLESS_ACCESS_KEY, BUSINESS_UNIT_KEY, HOMEBASE_LOCATION_KEY
from adaero.config import get_config_value
from adaero.security import ldapauth, ANGULAR_2_XSRF_TOKEN_COOKIE_NAME
from adaero.models.period import Period
from adaero.security import ANGULAR_2_XSRF_TOKEN_COOKIE_NAME
from adaero.views import Root


Expand All @@ -27,13 +28,19 @@ def _build_user_data_response(request, username):
ANGULAR_2_XSRF_TOKEN_COOKIE_NAME, request.session.get_csrf_token()
)
unit_name = get_config_value(request.registry.settings, BUSINESS_UNIT_KEY)
location = get_config_value(
request.registry.settings, HOMEBASE_LOCATION_KEY
)
with transaction.manager:
current_period = Period.get_current_period(request.dbsession)
return {
"success": True,
"data": {
"displayName": request.user.display_name,
"title": request.user.position,
"principals": request.effective_principals,
"businessUnit": unit_name,
"currentPhase": current_period.phase(location),
},
}

Expand Down
8 changes: 4 additions & 4 deletions adaero/views/enrol.py
Expand Up @@ -39,12 +39,12 @@ def get_enrollees(request):
if not current_period:
return interpolate_template(FEEDBACK_ENDED_TEMPLATE)

if current_period.subperiod(location) == Period.ENROLMENT_SUBPERIOD:
if current_period.phase(location) == Period.ENROLMENT_PHASE:
return interpolate_template(
ENTRY_PENDING_TEMPLATE, period_name=current_period.name
)

if current_period.subperiod(location) != Period.ENTRY_SUBPERIOD:
if current_period.phase(location) != Period.ENTRY_PHASE:
return interpolate_template(
ENTRY_ENDED_TEMPLATE, period_name=current_period.name
)
Expand Down Expand Up @@ -212,7 +212,7 @@ def get_request_status(request):
else:
is_enrolled = False

if current_period.subperiod(location) != Period.ENROLMENT_SUBPERIOD:
if current_period.phase(location) != Period.ENROLMENT_PHASE:
return interpolate_template(
ENROLMENT_INACTIVE_TEMPLATE,
period_name=current_period.name,
Expand Down Expand Up @@ -253,7 +253,7 @@ def self_enrol(request):
"the meantime. Please contact your "
"manager for more details."
)
elif current_period.subperiod(location) != Period.ENROLMENT_SUBPERIOD:
elif current_period.phase(location) != Period.ENROLMENT_PHASE:
display_end_date = current_period.entry_start_utc.strftime(
constants.DEFAULT_DISPLAY_DATETIME_FORMAT
)
Expand Down
2 changes: 1 addition & 1 deletion adaero/views/feedback.py
Expand Up @@ -39,7 +39,7 @@ def __init__(self, request): # pylint disable=unused-argument
.filter(Enrollee.period == self.current_period)
)

if self.current_period.subperiod(location) != Period.ENTRY_SUBPERIOD:
if self.current_period.phase(location) != Period.ENTRY_PHASE:
raise HTTPNotFound(explanation="Currently not in the entry " "period.")

self.to_username = request.matchdict["username"]
Expand Down
8 changes: 4 additions & 4 deletions adaero/views/manager.py
Expand Up @@ -77,9 +77,9 @@ def __init__(self, request): # pylint disable=unused-argument
location = get_config_value(
request.registry.settings, constants.HOMEBASE_LOCATION_KEY
)
if self.current_period.subperiod(location) not in [
Period.APPROVAL_SUBPERIOD,
Period.REVIEW_SUBPERIOD,
if self.current_period.phase(location) not in [
Period.APPROVAL_PHASE,
Period.REVIEW_PHASE,
]:
raise HTTPNotFound(
explanation="Currently not in the approval or " "review period."
Expand Down Expand Up @@ -174,7 +174,7 @@ def put_summary(context, request):
request.registry.settings, constants.HOMEBASE_LOCATION_KEY
)

if current_period.subperiod(location) != Period.APPROVAL_SUBPERIOD:
if current_period.phase(location) != Period.APPROVAL_PHASE:
raise HTTPNotFound(explanation="Currently not in the approval " "period.")

return update_feedback_form(context, request, True)
Expand Down
10 changes: 5 additions & 5 deletions adaero/views/request.py
Expand Up @@ -68,12 +68,12 @@ def get_request_status(request):
request.registry.settings, constants.HOMEBASE_LOCATION_KEY
)
current_period = Period.get_current_period(request.dbsession)
if current_period.subperiod(location) in [
Period.APPROVAL_SUBPERIOD,
Period.REVIEW_SUBPERIOD,
if current_period.phase(location) in [
Period.APPROVAL_PHASE,
Period.REVIEW_PHASE,
]:
return interpolate_template(ENTRY_ENDED_TEMPLATE)
elif current_period.subperiod(location) in [Period.ENROLMENT_SUBPERIOD]:
elif current_period.phase(location) in [Period.ENROLMENT_PHASE]:
dt = date.datetimeformat(current_period.entry_start_utc, request.user)
return interpolate_template(PRIOR_ENTRY_TEMPLATE, entry_start=dt)

Expand Down Expand Up @@ -145,7 +145,7 @@ def post_request(request):
settings, constants.SUPPORT_EMAIL_KEY, "your IT support for this tool"
)
with transaction.manager:
if current_period.subperiod(location) != Period.ENTRY_SUBPERIOD:
if current_period.phase(location) != Period.ENTRY_PHASE:
raise HTTPBadRequest(
explanation="Can only send invite during " 'the "Give feedback" period.'
)
Expand Down
Expand Up @@ -26,7 +26,9 @@ <h5>{{ user.displayName }}</h5>
<a routerLink="/enrol" routerLinkActive="active" class="nav-link">Enrol for feedback</a>
<a routerLink="/feedback" routerLinkActive="active" class="nav-link">Give feedback</a>
<a routerLink="/feedback-about-me" routerLinkActive="active" class="nav-link">Review my feedback</a>
<a routerLink="/invite-outside-reviewers" routerLinkActive="active" class="nav-link">Request specific reviewers</a>
<div *ngIf="user.currentPhase === 'entry_phase'">
<a routerLink="/invite-outside-reviewers" routerLinkActive="active" class="nav-link">Request specific reviewers</a>
</div>
</div>
<div *ngIf="user.principals.indexOf('role:manager') >= 0">
<a routerLink="/team-feedback" routerLinkActive="active" class="nav-link">My team stats</a>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/app/services/api.service.ts
Expand Up @@ -15,6 +15,7 @@ export class UserData {
title: string; // e.g. Software Developer
principals: [string];
businessUnit: string;
currentPhase: string; // refer to adaero/models/period.py
}

export class LoginSuccessPayload {
Expand Down

0 comments on commit dadefc9

Please sign in to comment.