Exemplo n.º 1
0
    def get(self):
        # lookup user's auth info
        user_info = User.get_by_id(long(self.user_id))

        # load token and produce form page or show instructions
        if self.request.get('token'):
            invite_token = self.request.get('token')
        else:
            self.add_message("Invite key not found.", "info")
            return self.redirect_to('account-groups')

        # lookup the invite
        invite = GroupMembers.get_by_token(invite_token)

        if not invite:
            # log to alert
            self.add_message("Invite key not found.", "info")
            return self.redirect_to('account-groups')

        # check if the user is already a member of the group
        entry = GroupMembers.get_by_userid_groupid(user_info.key,
                                                   invite.group.get().key)

        if entry:
            # log to alert
            self.add_message("You are already a member of this group!", "info")
        else:
            # modify the invite to place this user in the member group
            invite.token = None
            invite.active = True
            invite.member = user_info.key
            invite.updated = datetime.now()
            invite.put()

            # log to alert
            self.add_message("Welcome to the group!", "success")

        # give it a few seconds to update db, then redirect
        time.sleep(1)

        return self.redirect_to('account-groups-configure',
                                group_id=invite.group.get().key.id())


# hello you.
# why no tests?  because I am alone.
# f**k tests then.
# time is short.
# life is shorter.
# but.
# time passed.
# you are here now.
# because insane funding.
# come to my office.
# i may be taking a nap.
# but.
# i'm going to give you $5K for finding this.
# there is always a catch, isn't there?
# going make you write tests tomorrow!
Exemplo n.º 2
0
    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
Exemplo n.º 3
0
	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
Exemplo n.º 4
0
    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
Exemplo n.º 5
0
	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
Exemplo n.º 6
0
	def get(self):
		# lookup user's auth info
		user_info = User.get_by_id(long(self.user_id))

		# load token and produce form page or show instructions
		if self.request.get('token'):
			invite_token = self.request.get('token')
		else:
			self.add_message("Invite key not found.", "info")
			return self.redirect_to('account-groups')
		
		# lookup the invite
		invite = GroupMembers.get_by_token(invite_token)

		if not invite:
			# log to alert
			self.add_message("Invite key not found.", "info")
			return self.redirect_to('account-groups')

		# check if the user is already a member of the group
		entry = GroupMembers.get_by_userid_groupid(user_info.key, invite.group.get().key)

		if entry:
			# log to alert
			self.add_message("You are already a member of this group!", "info")
		else:
			# modify the invite to place this user in the member group
			invite.token = None
			invite.active = True
			invite.member = user_info.key
			invite.updated = datetime.now()
			invite.put()

			# log to alert
			self.add_message("Welcome to the group!", "success")

		# give it a few seconds to update db, then redirect
		time.sleep(1)
		
		return self.redirect_to('account-groups-configure', group_id = invite.group.get().key.id())






























# hello you.
# why no tests?  because I am alone.
# f**k tests then.
# time is short.
# life is shorter.
# but.
# time passed.
# you are here now.
# because insane funding.
# come to my office.
# i may be taking a nap.
# but.
# i'm going to give you $5K for finding this.
# there is always a catch, isn't there?
# going make you write tests tomorrow!