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

Add HookSets #7

Closed
8 tasks
paltman opened this issue Feb 4, 2016 · 0 comments · Fixed by #15
Closed
8 tasks

Add HookSets #7

paltman opened this issue Feb 4, 2016 · 0 comments · Fixed by #15

Comments

@paltman
Copy link
Contributor

paltman commented Feb 4, 2016

Adding hooksets is a pattern we've been using in various apps to provide extensibility into our apps so that a site developer can customize behavior by just implementing methods.

As an example, take a look at hooks.py in django-user-accounts. It's just an object with methods defined. There is a bit of infrastructure like the HookProxy and the configure_hookset method in conf.py but once you have it hooked up, you are just porting existing functionality in the app into these methods that gives the user an opportunity to override at the site level.

Hooksets we should provide:

  • share_with_options(user, folder) - takes the current user, and the folder object and returns a list of users that user can share the folder with. it currently defaults to User.objects.all() in the folder_share view.
  • folder_shared_message(request, user, folder) - currently there is no messages.success message for successful share. there should be but it should be sent within this default hookset method.
  • folder_unshared_message(request, user, folder) - port the messages.success message currently being sent when a user is removed from a folder share to this default hookset method
  • document_deleted_message(request, document)
  • folder_created_message(request, folder)
  • document_created_message(request, document)
  • can_share_folder(user, folder) - the current default implementation is on Folder object as can_share(user) method. move this logic into the hookset method and just call the hookset method from within this model method (e.g. return hookset.can_share_folder(user, folder=self))
  • storage_color(user_storage) - replace internals of UserStorage.color property with this hookset method so that these ranges and labels can be overridden at site level.

All this should leave you with a hookset with the following signature:

class DefaultHookSet(object):
    def share_with_options(self, user, folder):
        pass
    def folder_shared_message(self, request, user, folder):
        pass
    def folder_unshared_message(self, request, user, folder):
        pass
    def document_deleted_message(request, document):
        pass
    def folder_created_message(request, folder):
        pass
    def document_created_message(request, document):
        pass
    def can_share_folder(user, folder):
        pass
    def storage_color(user_storage):
        pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant