Permalink
Browse files

Merge remote-tracking branch 'upstream/master'

  • Loading branch information...
ericrasmussen committed Apr 24, 2012
2 parents 9473c79 + a16c81b commit 8b5f6b5fbacdd1b48ddd27dac4b87696afd995b2
Showing with 21 additions and 2 deletions.
  1. +14 −1 substanced/principal/__init__.py
  2. +7 −1 substanced/principal/views.py
@@ -28,6 +28,7 @@
IPrincipal,
IPrincipals,
IObjectAdded,
+ IObjectWillBeRemoved,
IPasswordResets,
IPasswordReset,
)
@@ -389,9 +390,21 @@ def reset_password(self, password):
raise ValueError('No user associated with this password reset')
user = sources[0]
user.set_password(password)
- # suicide
+ self.commit_suicide()
+
+ def commit_suicide(self):
del self.__parent__[self.__name__]
+@subscriber([IUser, IObjectWillBeRemoved])
+def user_will_be_removed(user, event):
+ """ Remove all password reset objects associated with a user when the user
+ is removed """
+ objectmap = find_service(event.object, 'objectmap')
+ if objectmap is not None:
+ resets = objectmap.targets(user, UserToPasswordReset)
+ for reset in resets:
+ reset.commit_suicide()
+
@subscriber([IPrincipal, IObjectAdded])
def principal_added(principal, event):
""" Prevent same-named users and groups from being added to the system.
@@ -20,11 +20,17 @@
GroupSchema,
)
+class AddUserSchema(UserSchema):
+ password = colander.SchemaNode(
+ colander.String(),
+ widget = deform.widget.CheckedPasswordWidget(),
+ )
+
@mgmt_view(context=IUsers, name='add_user', permission='sdi.add-user',
renderer='substanced.sdi:templates/form.pt', tab_condition=False)
class AddUserView(FormView):
title = 'Add User'
- schema = UserSchema()
+ schema = AddUserSchema()
buttons = ('add',)
def add_success(self, appstruct):

0 comments on commit 8b5f6b5

Please sign in to comment.