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

Do not remove inactive services from profiles and templates #2637

Merged
merged 15 commits into from
Nov 19, 2024

Conversation

xispa
Copy link
Member

@xispa xispa commented Nov 2, 2024

Description of the issue/feature this PR addresses

This Pull Request achieves the functionality suggested at #2623 (comment) for both AnalysisProfile and SampleTemplate:

  • no need to update/recatalog other objects via subscriber on service deactivation
  • service can be deactivated/reactivated and user won't need to manually reassign services to profiles later

Current behavior before PR

Deactivated services do not come-up automatically on profiles when reactivated

Desired behavior after PR is merged

Deactivated services come-up automatically on profiles when reactivated

--
I confirm I have tested this PR thoroughly and coded it according to PEP8
and Plone's Python styleguide standards.

@xispa xispa requested a review from ramonski November 2, 2024 18:07
@xispa xispa added Cleanup 🧹 Code cleanup and refactoring Performance labels Nov 2, 2024
Copy link
Contributor

@ramonski ramonski left a comment

Choose a reason for hiding this comment

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

Thanks for bringing the idea to life, I really like it!
I added some comments that might improve understanding (at least for me)...

continue
obj = api.get_object_by_uid(uid)
if not api.is_active(obj):
records.append(record)
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't understand why this code block is necessary. Why can't we just set the records from above? IMO this makes it impossible to remove a deactivated service.

Copy link
Contributor

Choose a reason for hiding this comment

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

Edit:
I understand now why this is needed and suggest the same changes as mentioned below. Also I would add the self.getServiceUIDs to avoid the record handling in the loop

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed with df4bf14

obj = api.get_object(uid)
if not active_only or api.is_active(obj):
services.append(obj)
return services
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we refactor this code for better understanding as follows?

services = map(api.get_object, self.getServiceUIDs())
if active_only:
    # filter out inactive services
    services = filter(api.is_active, services)
return list(services)

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed with df4bf14

continue
obj = api.get_object_by_uid(uid)
if not api.is_active(obj):
records.append(record)
Copy link
Contributor

@ramonski ramonski Nov 4, 2024

Choose a reason for hiding this comment

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

I would suggest to refactor this code to allow to flush inactive services:

def setServices(self, value, keep_inactive=True):
    ...
    uids = [record.get("uid") for record in records]
    if keep_inactive:
        to_check = filter(lambda uid: uid not in uids, self.getServiceUIDs())
        inactive = filter(lambda uid: not api.is_active, to_check)
        uids.extend(inactive)
    ...

Copy link
Member Author

Choose a reason for hiding this comment

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

Addressed with f12121e

mutator = self.mutator("services")
mutator(self, records)

# BBB: AT schema field property
Service = Services = property(getServices, setServices)

@security.protected(permissions.View)
def getServiceUIDs(self):
def getServicesUIDs(self):
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we stick here to the naming getServiceUIDs instead of getServicesUIDs?

Reasoning (according to ChatGPT;))

  1. Clarity: The phrase "Service UIDs" is clear and suggests that it refers to the unique identifiers associated with each "Service." Using Service in the singular keeps the focus on the type of UIDs being retrieved rather than suggesting that there are "Services" with "UIDs."

  2. Consistency: This aligns with common naming conventions where the subject of the method (e.g., Service) is singular, while the return type (e.g., UIDs) indicates a collection.

  3. Parallel to Standard Naming Conventions: Naming methods like getUserIDs (rather than getUsersIDs) or getItemNames (instead of getItemsNames) is common and widely understood.

Summary

getServiceUIDs is concise, clear, and consistent with common naming practices, making it the better choice.

Copy link
Member Author

Choose a reason for hiding this comment

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

jeje, ok.... my ChatGPT confirm yours... ;)

----8<-------------------------

The best accessor name would be getServiceUIDs.

Explanation:

  • Consistency: "ServiceUIDs" suggests you are returning multiple UIDs for the "Service" objects, and using the singular form "Service" keeps it cleaner and more intuitive.

  • Clarity: Even though "Services" is plural, using "ServiceUIDs" makes it clear that you are getting a list of UIDs related to the service objects as a whole, without the repetition of plurals.

So, getServiceUIDs is clearer and more concise.

----8<-------------------------

Oh man, this AI is teaching us already

Copy link
Member Author

Choose a reason for hiding this comment

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

Reverted with d465041

@xispa xispa marked this pull request as draft November 6, 2024 10:12
@xispa xispa marked this pull request as ready for review November 6, 2024 10:49
Copy link
Contributor

@ramonski ramonski left a comment

Choose a reason for hiding this comment

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

Thanks!

@ramonski ramonski merged commit 375d4d0 into 2.x Nov 19, 2024
2 checks passed
@ramonski ramonski deleted the del-subscriber-profile branch November 19, 2024 19:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cleanup 🧹 Code cleanup and refactoring Performance
Development

Successfully merging this pull request may close these issues.

2 participants