diff --git a/CHANGELOG.md b/CHANGELOG.md index 3a8deb03f..4abff61ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -26,6 +26,7 @@ Release adds support for private components and integrations with third party se * Only Component owner can edit user permissions. * Display the control framework along side of controls in component control listing page. * Remove icons from project listing. +* Add Component search filter to filter results to components owned by user. **Developer changes** diff --git a/api/siteapp/serializers/projects.py b/api/siteapp/serializers/projects.py index 8acd6c6e1..15b3097d3 100644 --- a/api/siteapp/serializers/projects.py +++ b/api/siteapp/serializers/projects.py @@ -21,12 +21,12 @@ class DetailedProjectsSerializer(SimpleProjectsSerializer): organization = DetailedOrganizationSerializer() portfolio = SimplePortfolioSerializer() tags = SimpleTagSerializer(many=True) - system = SimpleSystemSerializer() + # system = SimpleSystemSerializer() root_task = TaskSerializer() class Meta: model = Project - fields = SimpleProjectsSerializer.Meta.fields + ['organization', 'portfolio', 'system', 'tags', 'root_task'] + fields = SimpleProjectsSerializer.Meta.fields + ['organization', 'portfolio', 'tags', 'root_task'] class SimpleProjectMembershipSerializer(ReadOnlySerializer): diff --git a/controls/views.py b/controls/views.py index 298b1956a..eca1b9be1 100644 --- a/controls/views.py +++ b/controls/views.py @@ -452,11 +452,25 @@ def get_context_data(self, **kwargs): @login_required def component_library(request): """Display the library of components""" + owned_elements_id = [] + for element in Element.objects.all().exclude(element_type='system').distinct(): + if element.is_owner(request.user): + owned_elements_id.append(element.id) + + owned_elements_list = Element.objects.filter(id__in=owned_elements_id) + query = request.GET.get('search') + # Setting a breakpoint in the code. if query: try: - element_list = Element.objects.filter(Q(name__icontains=query) | Q(tags__label__icontains=query)).exclude(element_type='system').distinct() + if request.GET.get('owner'): + # Search by owner + element_list = Element.objects.filter(id__in=owned_elements_id) + element_list = element_list.filter(Q(name__icontains=query) | Q(tags__label__icontains=query)).exclude(element_type='system').distinct() + else: + element_list = Element.objects.filter(Q(name__icontains=query) | Q(tags__label__icontains=query)).exclude(element_type='system').distinct() + except: logger.info(f"Ah, you are not using Postgres for your Database!") element_list = Element.objects.filter(Q(name__icontains=query) | Q(tags__label__icontains=query)).exclude(element_type='system').distinct() @@ -471,17 +485,23 @@ def component_library(request): # Pagination ele_paginator = Paginator(element_list_private_removed, 15) + owned_ele_paginator = Paginator(owned_elements_list, 15) page_number = request.GET.get('page') try: page_obj = ele_paginator.page(page_number) + owned_page_obj = owned_ele_paginator.page(page_number) except PageNotAnInteger: page_obj = ele_paginator.page(1) + owned_page_obj = owned_ele_paginator.page(1) except EmptyPage: page_obj = ele_paginator.page(ele_paginator.num_pages) - + owned_page_obj = owned_ele_paginator.page(owned_ele_paginator.num_pages) + context = { "page_obj": page_obj, + "owned_page_obj": owned_page_obj, + "start": False, "import_form": ImportOSCALComponentForm(), "total_comps": Element.objects.exclude(element_type='system').count(), } @@ -1183,8 +1203,6 @@ def system_element(request, system_id, element_id): hasSentRequest = True except Proposal.DoesNotExist: proposal = None - - # Retrieve control ids catalog_controls = Catalog.GetInstance(catalog_key=catalog_key).get_controls_all() diff --git a/frontend/src/components/cmpt_parties/cmpt_parties.js b/frontend/src/components/cmpt_parties/cmpt_parties.js index 33e13a53b..0e40c6d4b 100644 --- a/frontend/src/components/cmpt_parties/cmpt_parties.js +++ b/frontend/src/components/cmpt_parties/cmpt_parties.js @@ -863,16 +863,20 @@ export const ComponentParties = ({ elementId, poc_users, isOwner }) => {