def delete(self, group_id=None): # lookup user's auth info user_info = User.get_by_id(long(self.user_id)) # find the the entry group = Group.get_by_id(long(group_id)) # this member's membership membership = GroupMembers.get_by_userid_groupid( user_info.key, group.key) # list of users that have the group enabled members = GroupMembers.get_group_users(group.key) # remove this user's membership membership.key.delete() # if this user is not the group owner, we simply notify we are done if not group or group.owner != user_info.key: # use the channel to tell the browser we are done and reload self.add_message('Group was removed from account.', 'success') channel_token = self.request.get('channel_token') channel.send_message(channel_token, 'reload') return # was there more than just this member? if len(members) > 1: # find the next user by date and assign them as owner entry = GroupMembers.get_new_owner(user_info.key, group.key) print "new owner is %s" % entry.member new_owner = entry.member group.owner = new_owner group.put() # find member's appliances that match this group and remove appliances = Appliance.get_by_user_group(user_info.key, group.key) for appliance in appliances: appliance.group = None # public group appliance.put() else: # no more members, so delete the group group.key.delete() self.add_message('Group successfully deleted!', 'success') # remove group from any and all appliances (heavy handed) appliances = Appliance.get_by_group(group.key) for appliance in appliances: appliance.group = None # public group appliance.put() # hangout for a second time.sleep(1) # use the channel to tell the browser we are done and reload channel_token = self.request.get('channel_token') channel.send_message(channel_token, 'reload') return
def delete(self, group_id = None): # lookup user's auth info user_info = User.get_by_id(long(self.user_id)) # find the the entry group = Group.get_by_id(long(group_id)) # this member's membership membership = GroupMembers.get_by_userid_groupid(user_info.key, group.key) # list of users that have the group enabled members = GroupMembers.get_group_users(group.key) # remove this user's membership membership.key.delete() # if this user is not the group owner, we simply notify we are done if not group or group.owner != user_info.key: # use the channel to tell the browser we are done and reload self.add_message('Group was removed from account.', 'success') channel_token = self.request.get('channel_token') channel.send_message(channel_token, 'reload') return # was there more than just this member? if len(members) > 1: # find the next user by date and assign them as owner entry = GroupMembers.get_new_owner(user_info.key, group.key) print "new owner is %s" % entry.member new_owner = entry.member group.owner = new_owner group.put() # find member's appliances that match this group and remove appliances = Appliance.get_by_user_group(user_info.key, group.key) for appliance in appliances: appliance.group = None # public group appliance.put() else: # no more members, so delete the group group.key.delete() self.add_message('Group successfully deleted!', 'success') # remove group from any and all appliances (heavy handed) appliances = Appliance.get_by_group(group.key) for appliance in appliances: appliance.group = None # public group appliance.put() # hangout for a second time.sleep(1) # use the channel to tell the browser we are done and reload channel_token = self.request.get('channel_token') channel.send_message(channel_token, 'reload') return
def delete(self, group_id=None, member_id=None): # lookup user's auth info user_info = User.get_by_id(long(self.user_id)) # get the group in question group = Group.get_by_id(long(group_id)) member = User.get_by_id(long(member_id)) # get this user's admin rights is_admin = False if group.owner == user_info.key: is_admin = True # bail if group doesn't exist or user is not admin if not group or not is_admin: # log to alert self.add_message("You may not remove this user from group.", "error") else: # look up the other user's group membership membership = GroupMembers.get_by_userid_groupid( member.key, group.key) # kill the membership membership.key.delete() # find member's appliances that match that group and remove appliances = Appliance.get_by_user_group(member.key, group.key) for appliance in appliances: appliance.group = None # public group appliance.put() # log to alert self.add_message("User removed from group!", "success") # use the channel to tell the browser we are done and reload channel_token = self.request.get('channel_token') channel.send_message(channel_token, 'reload') return
def delete(self, group_id = None, member_id = None): # lookup user's auth info user_info = User.get_by_id(long(self.user_id)) # get the group in question group = Group.get_by_id(long(group_id)) member = User.get_by_id(long(member_id)) # get this user's admin rights is_admin = False if group.owner == user_info.key: is_admin = True # bail if group doesn't exist or user is not admin if not group or not is_admin: # log to alert self.add_message("You may not remove this user from group.", "error") else: # look up the other user's group membership membership = GroupMembers.get_by_userid_groupid(member.key, group.key) # kill the membership membership.key.delete() # find member's appliances that match that group and remove appliances = Appliance.get_by_user_group(member.key, group.key) for appliance in appliances: appliance.group = None # public group appliance.put() # log to alert self.add_message("User removed from group!", "success") # use the channel to tell the browser we are done and reload channel_token = self.request.get('channel_token') channel.send_message(channel_token, 'reload') return