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

Update viewer group permissions #4925

Draft
wants to merge 3 commits into
base: develop
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ angular.module('SEED.controller.inventory_group_list', [])
'$state',
'$stateParams',
'$uibModal',
'$translate',
'Notification',
'modified_service',
'inventory_service',
Expand All @@ -17,28 +16,25 @@ angular.module('SEED.controller.inventory_group_list', [])
'access_level_tree',
'inventory_groups',
'current_inventory_group',
'organization_payload',
// eslint-disable-next-line func-names
function (
$scope,
$state,
$stateParams,
$uibModal,
$translate,
Notification,
modified_service,
inventory_service,
user_service,
urls,
access_level_tree,
inventory_groups,
current_inventory_group,
organization_payload
current_inventory_group
) {
$scope.inventory_type = $stateParams.inventory_type;
$scope.inventory_groups = inventory_groups;
$scope.currentInventoryGroup = current_inventory_group;
$scope.org_id = organization_payload;
$scope.org = user_service.get_organization();

$scope.edit_inventory_group = (group_id) => {
const selected_group = $scope.inventory_groups.find((g) => g.id === group_id);
Expand Down Expand Up @@ -79,7 +75,7 @@ angular.module('SEED.controller.inventory_group_list', [])
action: _.constant(action),
data: _.constant(data),
inventory_type: () => ($scope.inventory_type === 'properties' ? 'Property' : 'Tax Lot'),
org_id: () => user_service.get_organization().id
org_id: () => $scope.org.id
}
});

Expand Down
7 changes: 1 addition & 6 deletions seed/static/seed/js/seed.js
Original file line number Diff line number Diff line change
Expand Up @@ -1949,12 +1949,7 @@
const currentInventoryGroup = _.first(inventory_groups);
if (currentInventoryGroup) inventory_service.save_last_inventory_group(currentInventoryGroup.id, $stateParams.inventory_type);
return currentInventoryGroup;
}],
organization_payload: [
'user_service',
'organization_service',
(user_service, organization_service) => organization_service.get_organization(user_service.get_organization().id)
]
}]
}
})
.state({
Expand Down
2 changes: 1 addition & 1 deletion seed/static/seed/js/services/inventory_group_service.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ angular.module('SEED.service.inventory_group', []).factory('inventory_group_serv
inventory_type
}
}).then((response) => {
const groups = response.data.data.sort((a, b) => naturalSort(a.name, b.name));
const groups = response.data.sort((a, b) => naturalSort(a.name, b.name));
Copy link
Contributor Author

@perryr16 perryr16 Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new viewset permission changes structure of the response

return groups;
});

Expand Down
2 changes: 1 addition & 1 deletion seed/static/seed/partials/inventory_groups_list.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ <h1>{$:: (inventory_type === 'taxlots' ? 'Tax Lot Groups' : 'Property Groups') |
<h2><i class="fa fa-sitemap"></i> <span>{$:: (inventory_type === 'taxlots' ? 'Tax Lot Groups' : 'Property Groups') | translate $}</span></h2>
</div>
<div class="section_action_container right_40 section_action_btn pull-right">
<button class="btn btn-primary" ng-click="create_inventory_group()" translate>Create Group</button>
<button class="btn btn-primary" ng-if="org.user_role !== 'viewer'" ng-click="create_inventory_group()" translate>Create Group</button>
</div>
</div>
</div>
Expand Down
20 changes: 16 additions & 4 deletions seed/views/v3/inventory_groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from django.http import JsonResponse
from django.utils.decorators import method_decorator
from django.utils.timezone import make_aware
from drf_yasg.utils import swagger_auto_schema
from pint import Quantity
from pytz import timezone
from rest_framework import response, status
Expand All @@ -20,17 +21,18 @@
from seed.models import AccessLevelInstance, Cycle, InventoryGroup, Meter, MeterReading, Organization, PropertyView
from seed.serializers.inventory_groups import InventoryGroupSerializer
from seed.serializers.meters import MeterSerializer
from seed.utils.api_schema import swagger_auto_schema_org_query_param
from seed.utils.api import OrgMixin
from seed.utils.api_schema import AutoSchemaHelper, swagger_auto_schema_org_query_param
from seed.utils.meters import PropertyMeterReadingsExporter, update_meter_connection
from seed.utils.viewsets import SEEDOrgNoPatchOrOrgCreateModelViewSet
from seed.utils.viewsets import ModelViewSetWithoutPatch, SEEDOrgNoPatchOrOrgCreateModelViewSet

logger = logging.getLogger()


@method_decorator(name="list", decorator=[swagger_auto_schema_org_query_param, has_perm_class("requires_viewer")])
@method_decorator(name="create", decorator=[swagger_auto_schema_org_query_param, has_perm_class("requires_member")])
@method_decorator(name="update", decorator=[swagger_auto_schema_org_query_param, has_perm_class("requires_member")])
class InventoryGroupViewSet(SEEDOrgNoPatchOrOrgCreateModelViewSet):
class InventoryGroupViewSet(ModelViewSetWithoutPatch, OrgMixin):
serializer_class = InventoryGroupSerializer
model = InventoryGroup
filter_backends = (ColumnListProfileFilterBackend,)
Expand Down Expand Up @@ -66,6 +68,16 @@ def _get_property_groups(self, request):
status_code = status.HTTP_200_OK
return response.Response(results, status=status_code)

@swagger_auto_schema(
manual_parameters=[
AutoSchemaHelper.query_org_id_field(),
AutoSchemaHelper.query_string_field("inventory_type", required=True, description="property or tax_lot"),
],
request_body=AutoSchemaHelper.schema_factory(
{"selected": ["integer"]},
description="selected: optional list of inventory ids. [] returns all groups.",
),
)
@has_perm_class("requires_viewer")
@action(detail=False, methods=["POST"])
def filter(self, request):
Expand Down Expand Up @@ -222,7 +234,7 @@ def update_connection(self, request, inventory_group_pk, pk):
return JsonResponse({}, status=status.HTTP_200_OK)

@swagger_auto_schema_org_query_param
@has_perm_class("requires_viewer")
@has_perm_class("requires_member")
@has_hierarchy_access(inventory_group_id_kwarg="inventory_group_pk")
def create(self, request, inventory_group_pk):
meter_serializer = MeterSerializer(
Expand Down
Loading