Ejemplo n.º 1
0
    def post( self, group_id ):
        ur = UserRepository()
        gr = GroupRepository()

        user = self.get_current_user()
        group = gr.fetch(group_id)
        gr.get_group_maintainer(group)

        user_group_ids = [ g.id for g in gr.get_groups_of_user(user.id) ]
        supergroups = gr.get_supergroup_list(group_id)

        # TODO: Add logic to prevent user from leaving if they're in a subgroup
        # of the current group.
        group_root = gr.get_user_group_tree(user.id, long(group_id))

        # The group must be a non-root group to consider removal.  Also, the user
        # cannot be in any of the subgroups.
        if len(supergroups) != 0 and len(group_root.subgroups) == 0:
            supergroup = supergroups[-1]

            # Case 1: User requested group deletion (user is maintainer + empty).
            if group.maintainerId == user.id and gr.get_group_size(group.id) == 1:
                gr.remove(group)
                self.redirect( "/group/" + str(supergroup.id) )
                return
            # Case 2: User requested to leave the group (user is in group).
            if group.id in user_group_ids:
                user.groups = [ gid for gid in user_group_ids if gid != group.id ]
                ur.persist(user)
                self.redirect( "/group/" + str(supergroup.id) )
                return

        self.redirect( "/group/" + str(group_id) )
Ejemplo n.º 2
0
    def _perform_request(self, user, name, values):
        group_id = values[u"group_id"]
        name = values[u"name"]
        deadline = values[u"deadline"]
        notes = values[u"notes"]
        curr_user = self.get_current_user()

        dr = DeadlineRepository()
        gr = GroupRepository()
        group = gr.fetch(group_id)
        gr.get_group_maintainer(group)

        new_deadline = Deadline()
        new_deadline.meta = DeadlineMetadata()

        new_deadline.name = name
        new_deadline.group_id = group_id
        new_deadline.deadline = datetime.strptime(deadline, u'%m/%d/%Y %I:%M %p') # private group
        if(group.maintainer and group.maintainer.id == user.id):
            new_deadline.type = 'END'
        else:
            new_deadline.type = 'PER'
        new_deadline.meta.user_id = user.id
        new_deadline.meta.notes = notes
        new_deadline = dr.persist(new_deadline)

        dr.close()

        result = {}

        result['id'] = new_deadline.id
        result['name'] = new_deadline.name
        result['group'] = new_deadline.group
        result['type'] = new_deadline.type
        result['time'] = new_deadline.deadline.strftime(u'%A %b %d, %H:%M')
        result['notes'] = new_deadline.meta.notes
        result['can_edit'] = (new_deadline.type == "PER" or (group.maintainerId == user.id and new_deadline.type == "END"))

        self.write(json.dumps(result))
        self.flush
        self.finish