Skip to content

Commit

Permalink
Merge pull request usnistgov#130 from usnistgov/4.3.2.dev
Browse files Browse the repository at this point in the history
4.3.2.dev
  • Loading branch information
rptmat57 authored Dec 16, 2022
2 parents 6512ff9 + 78df825 commit ba8ca5c
Show file tree
Hide file tree
Showing 9 changed files with 38 additions and 18 deletions.
18 changes: 18 additions & 0 deletions NEMO/migrations/0043_version_4_3_2.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 3.2.16 on 2022-12-12 21:18

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('NEMO', '0042_version_4_3_0'),
]

operations = [
migrations.AlterField(
model_name='physicalaccesslevel',
name='allow_staff_access',
field=models.BooleanField(default=False, help_text='Check this box to allow access to Staff and User Office members without explicitly granting them access'),
),
]
4 changes: 2 additions & 2 deletions NEMO/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ class Schedule(object):
schedule = models.IntegerField(choices=Schedule.Choices)
weekdays_start_time = models.TimeField(default=datetime.time(hour=7), null=True, blank=True, help_text="The weekday access start time")
weekdays_end_time = models.TimeField(default=datetime.time(hour=0), null=True, blank=True, help_text="The weekday access end time")
allow_staff_access = models.BooleanField(blank=False, null=False, default=False, help_text="Check this box to allow access to Staff users without explicitly granting them access")
allow_staff_access = models.BooleanField(blank=False, null=False, default=False, help_text="Check this box to allow access to Staff and User Office members without explicitly granting them access")
allow_user_request = models.BooleanField(blank=False, null=False, default=False, help_text="Check this box to allow users to request this access temporarily in \"Access requests\"")

def get_schedule_display_with_times(self):
Expand Down Expand Up @@ -616,7 +616,7 @@ def get_name(self):
return self.first_name + ' ' + self.last_name

def accessible_access_levels(self):
if not self.is_staff:
if not self.is_staff and not self.is_user_office:
return self.physical_access_levels.all()
else:
return PhysicalAccessLevel.objects.filter(Q(id__in=self.physical_access_levels.all()) | Q(allow_staff_access=True)).distinct()
Expand Down
2 changes: 1 addition & 1 deletion NEMO/templates/occupancy/occupancy_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{% if show_force_logout and user.is_staff or show_force_logout and user.is_user_office %}
<span class="glyphicon glyphicon-remove-circle grey pointer" onclick="force_user_out_of_the_area('{% url 'force_area_logout' o.customer_id %}')" title="Force {{ o.customer }} to log out of the {{ o.area }}"></span>
{% endif %}
<span {% if o.customer.is_staff %}class="success-highlight" {% elif o.customer.is_service_personnel %}class="warning-highlight" {% elif o.customer.is_logged_in_area_without_reservation %}class="danger-highlight" {% endif %}>{{ o.customer.first_name }} {{ o.customer.last_name }}</span>
<span {% if o.customer.is_any_part_of_staff %}class="success-highlight" {% elif o.customer.is_service_personnel %}class="warning-highlight" {% elif o.customer.is_logged_in_area_without_reservation %}class="danger-highlight" {% endif %}>{{ o.customer.first_name }} {{ o.customer.last_name }}</span>
</td>
<td style="white-space: nowrap;width:25%">{{ o.start|date:"l @ "}} {{ o.start|time }}</td>
<td><div style="width: 0; min-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">{{ o.project }}</div></td>
Expand Down
3 changes: 2 additions & 1 deletion NEMO/templates/training/training.html
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ <h1>Training</h1>
</tr>
</table>
<br>
{% button id="record_training_sessions" type="save" value="Record training sessions" %}
{# Note: onclick need to stay blank so it will trigger the onsumbit of this form #}
{% button id="record_training_sessions" type="save" value="Record training sessions" onclick="" %}
</form>

<script type="text/javascript">
Expand Down
2 changes: 1 addition & 1 deletion NEMO/templates/users/create_or_modify_user.html
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@
{% endif %}
{% for level in area_access_dict|get_item:node.id %}
<div class="checkbox" {% if not node.is_leaf_node %}style="display: inline-block;margin-left: -3px"{% endif %}>
<label><input name="physical_access_levels" type="checkbox" {% if form.instance.is_staff and level.allow_staff_access %}disabled title="This access is automatically granted to staff users"{% endif %} value="{{ level.id }}" {% if level in checked_access_levels %}checked{% endif %}>{% if node.category %}({{ node.category }}) {% endif %}{{ level }}</label>
<label><input name="physical_access_levels" type="checkbox" {% if form.instance.is_staff and level.allow_staff_access or form.instance.is_user_office and level.allow_staff_access %}disabled title="This access is automatically granted to staff users"{% endif %} value="{{ level.id }}" {% if level in checked_access_levels %}checked{% endif %}>{% if node.category %}({{ node.category }}) {% endif %}{{ level }}</label>
</div>
{% endfor %}
{% if not node.is_leaf_node %}
Expand Down
3 changes: 2 additions & 1 deletion NEMO/views/email.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,10 @@ def get_users_for_email(audience: str, selection: List, no_type: bool) -> QueryS
elif audience == "area":
access_levels = [access_level for area in Area.objects.filter(pk__in=selection) for access_level in area.get_physical_access_levels()]
user_filter = Q(physical_access_levels__in=access_levels)
# if one of the access levels allows staff, add all staff
# if one of the access levels allows staff, add all staff & user office
if any([access_level.allow_staff_access for access_level in access_levels]):
user_filter |= Q(is_staff=True)
user_filter |= Q(is_user_office=True)
users = User.objects.filter(user_filter).distinct()
elif audience == "project":
users = User.objects.filter(projects__id__in=selection).distinct()
Expand Down
4 changes: 2 additions & 2 deletions NEMO/views/policy.py
Original file line number Diff line number Diff line change
Expand Up @@ -560,8 +560,8 @@ def check_policy_to_enter_any_area(user: User):


def check_policy_to_enter_this_area(area: Area, user: User):
# If explicitly set on the Physical Access Level, staff may be exempt from being granted explicit access
if user.is_staff and any([access_level.accessible() for access_level in PhysicalAccessLevel.objects.filter(allow_staff_access=True, area=area)]):
# If explicitly set on the Physical Access Level, staff & user office may be exempt from being granted explicit access
if (user.is_staff or user.is_user_office) and any([access_level.accessible() for access_level in PhysicalAccessLevel.objects.filter(allow_staff_access=True, area=area)]):
pass
else:
# Check if the user normally has access to this area door at the current time (or access to any parent)
Expand Down
18 changes: 9 additions & 9 deletions NEMO/views/status_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -85,21 +85,21 @@ def get_staff_status(request, csv_export=False) -> Union[Dict, HttpResponse]:
user_can_check_past_status = (
not check_past_status
or check_past_status == "staffs"
and user.is_staff
and user.is_any_part_of_staff
or check_past_status == "managers"
and user.is_facility_manager
)
user_can_check_future_status = (
not check_future_status
or check_future_status == "staffs"
and user.is_staff
and user.is_any_part_of_staff
or check_future_status == "managers"
and user.is_facility_manager
)
# Check and set ability for users/staffs to look at the week/month view
user_view_options = StatusDashboardCustomization.get("dashboard_staff_status_user_view")
staff_view_options = StatusDashboardCustomization.get("dashboard_staff_status_staff_view")
user_view = user_view_options if not user.is_staff else staff_view_options if not user.is_facility_manager else ""
user_view = user_view_options if not user.is_any_part_of_staff else staff_view_options if not user.is_facility_manager else ""
# Take the default view from user preferences
view = request.GET.get("view", user.get_preferences().staff_status_view)
# If user_view is set to day only, then force day view
Expand Down Expand Up @@ -269,13 +269,13 @@ def show_staff_status(request):
if not settings.ALLOW_CONDITIONAL_URLS:
return False
dashboard_staff_status_staff_only = StatusDashboardCustomization.get("dashboard_staff_status_staff_only")
return StaffAvailability.objects.exists() and (not dashboard_staff_status_staff_only or request.user.is_staff)
return StaffAvailability.objects.exists() and (not dashboard_staff_status_staff_only or request.user.is_any_part_of_staff)


def process_area_access_record_with_parents(user: User):
show_not_qualified_areas = StatusDashboardCustomization.get("dashboard_display_not_qualified_areas")
records = AreaAccessRecord.objects.filter(end=None, staff_charge=None)
if not user.is_staff and show_not_qualified_areas != "enabled":
if not user.is_any_part_of_staff and show_not_qualified_areas != "enabled":
records = records.filter(area__in=user.accessible_areas())
records = records.prefetch_related("customer", "project", "area")
no_occupants = not records.exists()
Expand Down Expand Up @@ -385,12 +385,12 @@ def create_area_summary(area_tree: ModelTreeHelper = None, add_resources=True, a
occupants: List[AreaAccessRecord] = AreaAccessRecord.objects.filter(
end=None, staff_charge=None
).prefetch_related(
Prefetch("customer", queryset=User.objects.all().only("first_name", "last_name", "username", "is_staff"))
Prefetch("customer", queryset=User.objects.all().only("first_name", "last_name", "username", "is_staff", "is_accounting_officer", "is_user_office", "is_facility_manager", "is_superuser"))
)
for occupant in occupants:
# Get ids for area and all the parents (so we can add occupants info on parents)
area_ids = area_tree.get_area(occupant.area_id).ancestor_ids(include_self=True)
if occupant.customer.is_staff:
if occupant.customer.is_any_part_of_staff:
customer_display = f'<span class="success-highlight">{str(occupant.customer)}</span>'
elif occupant.customer.is_service_personnel:
customer_display = f'<span class="warning-highlight">{str(occupant.customer)}</span>'
Expand All @@ -401,11 +401,11 @@ def create_area_summary(area_tree: ModelTreeHelper = None, add_resources=True, a
for area_id in area_ids:
if area_id in result:
result[area_id]["occupancy"] += 1
if occupant.customer.is_staff:
if occupant.customer.is_any_part_of_staff:
result[area_id]["occupancy_staff"] += 1
if occupant.customer.is_service_personnel:
result[area_id]["occupancy_service_personnel"] += 1
if (not occupant.customer.is_staff or result[area_id]["count_staff_in_occupancy"]) and (
if (not occupant.customer.is_any_part_of_staff or result[area_id]["count_staff_in_occupancy"]) and (
not occupant.customer.is_service_personnel
or result[area_id]["count_service_personnel_in_occupancy"]
):
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name='NEMO',
version='4.3.1',
version='4.3.2',
python_requires='>=3.7',
packages=find_packages(exclude=['NEMO.tests','NEMO.tests.*']),
include_package_data=True,
Expand Down

0 comments on commit ba8ca5c

Please sign in to comment.