Example #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) )
Example #2
0
    def get( self, group_id ):
        ur = UserRepository()
        gr = GroupRepository()
        dr = DeadlineRepository()

        # TODO: 404 if the user is not a member of the group.
        user = self.get_current_user()
        # TODO: 404 if the page doesn not exist in the DB.
        group = gr.get_user_group_tree(user.id, long(group_id))
        gr.get_group_maintainer_rec(group)
        supergroup_list = gr.get_supergroup_list(group_id)

        group_is_public = group.maintainerId == None
        user_is_maintainer = group.maintainerId == user.id
        member_list = ur.get_members_of_group(group_id)

        deadline_list = dr.deadlines_for_user_for_group(user.id, group.id)
        print "Deadline List: ", deadline_list
        for deadline in deadline_list:
            deadline.group = group

        self.render( self.get_url(),
            user = user,
            group = group,
            supergroups = supergroup_list,
            subgroups = group.subgroups,
            group_is_public = group_is_public,
            user_is_maintainer = user_is_maintainer,
            members = member_list,
            deadlines = deadline_list,
        )