Ejemplo n.º 1
0
    def _valid_request(self, user, prefix, group_id):
        group_repo = GroupRepository()
        group = group_repo.fetch(group_id)
        group_repo.close()

        if not group:
            print "Group doesn't exist."
            return False

        user_repo = UserRepository()
        member_list = user_repo.get_members_of_group(group_id)
        user_repo.close()

        if not any(member.id == user.id for member in member_list):
            print "User is not a member of the associated group."
            return False

        group_repo = GroupRepository()
        parent_group = group_repo.get_supergroup_of_group(group_id)
        group_repo.close()
        if not group_repo:
            print "Attempting to add membrer to the root."
            return False

        user_repo = UserRepository()
        parent_member_list = user_repo.get_members_of_group(parent_group.id)
        user_repo.close()
        if not any(member.id == user.id for member in parent_member_list):
            print "New user is not a member of the supergroup."
            return False

        return True
Ejemplo n.º 2
0
    def _valid_request(self, user, attr, deadline_id, value):
        # User parameters must be defined
        if not user or not attr or not value or not deadline_id:
            print "Invalid Request. Parameters Missing"
            return False

        notes = value[0].decode("utf-8")

        # The deadline associated with the deadline_id must exist
        deadline_repo = DeadlineRepository()
        dead = deadline_repo.deadline_for_user(user.id, deadline_id)
        deadline_repo.close()

        if not dead or not dead.meta or not dead.group_id:
            print "Something is wrong with the deadline object."
            return False

        group_repo = GroupRepository()
        group = group_repo.fetch(dead.group_id)
        group_repo.close()

        if not group:
            print "Associated group doesn't exist."
            return False

        if not (dead.type == "PER" or
                (group.maintainerId == dead.group_id and dead.type == "END")):
            print "User cannot modify this deadline"
            return False

        return True
Ejemplo n.º 3
0
    def get_root_group(self):
        # TODO(roh7): this is a hack
        uiuc_name = "University of Illinois at Urbana-Champaign"
        ir = InstitutionRepository()
        institutions = ir.fetch_all()
        uiuc = None
        for inst in institutions:
            if inst.name == uiuc_name:
                uiuc = inst
                break
        ir.close()

        assert uiuc is not None, 'institution for UIUC group not found...'
        # with the UIUC group, find the term. we currently want UIUC Spring 2014.
        tr = TermRepository()
        gr = GroupRepository()
        term = tr.fetch_term_by_year_index(uiuc, 2014, 0)
        assert term is not None, 'Spring 2014 not found...'

        if term.group:
            root = gr.fetch(term.group)
        else:
            # create UIUC group
            root = Group()
            root.name = "UIUC " + term.name
            root.description = uiuc_name
            root.type = 0
            # make sure bidirectional references work
            root.academic_entity_id = term.id
            root = gr.persist(root)
            term.group = root.id
            tr.persist(term)
        tr.close()
        gr.close()
        return root
Ejemplo n.º 4
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.º 5
0
    def _perform_request(self, user, prefix, group_id):
        group_repo = GroupRepository()
        group = group_repo.fetch(group_id)
        group_repo.close()

        deadline_repo = DeadlineRepository()
        deadline_list = deadline_repo.find_deadlines_with_name_prefix(group_id, prefix)
        deadline_repo.close()

        formatted_names = [{"value": deadline.name} for deadline in deadline_list]

        return json.dumps(formatted_names)
Ejemplo n.º 6
0
    def _user_exists(self, user_id):
        # User must exist
        user_repo = GroupRepository()
        user = user_repo.fetch(user_id)
        user_repo.close()

        if not user:
            print "User (" + str(user_id) + ") doesn't exist."
            return False 

        return True


        pass
Ejemplo n.º 7
0
    def _perform_request(self, user, name, values):
        print "Performing request"
        deadline_id = values["deadline_id"]
        curr_user = self.get_current_user()

        dr = DeadlineRepository()
        gr = GroupRepository()

        deadline = dr.deadline_for_user(curr_user.id, deadline_id)
        group = gr.fetch(deadline.group_id)
        if(group.maintainerId == curr_user.id or group.type == 'PER'):
            dr.delete(deadline.id)
        else:
            dr.drop_metadata(deadline)
Ejemplo n.º 8
0
    def _group_exists(self, group_id):
        # Group id is invalid
        if not group_id:
            print "Group ID (" + group_id + ") is invalid."
            return False

        group_repo = GroupRepository()
        group = group_repo.fetch(group_id)
        group_repo.close()

        if not group:
            print "Group (" + str(group_id) + ") doesn't exist."
            return False 

        return True
Ejemplo n.º 9
0
    def get( self ):
        gr = GroupRepository()
        dr = DeadlineRepository()

        root_group = self.get_root_group()
        user = self.get_current_user()
        root_group_tree = gr.get_user_group_tree(user.id, root_group.id)
        gr.get_group_maintainer_rec(root_group_tree)

        deadline_list = dr.deadlines_for_user(user.id)
        for deadline in deadline_list:
            deadline.group = gr.fetch(deadline.group_id)

        self.render( self.get_url(),
            user = user,
            deadlines = deadline_list,
            groups = [ root_group_tree ]
        )
Ejemplo n.º 10
0
    def _valid_request(self, user, prefix, group_id):
        group_repo = GroupRepository()
        group = group_repo.fetch(group_id)
        group_repo.close()

        if not group:
            print "Group doesn't exist."
            return False

        user_repo = UserRepository()
        member_list = user_repo.get_members_of_group(group_id)
        user_repo.close()

        if not any(member.id == user.id for member in member_list):
            print "User is not a member of the associated group."
            return False

        return True
Ejemplo n.º 11
0
 def _perform_request(self, user, name, values):
     gr = GroupRepository()
     group = gr.fetch(values['group'])
     gr.close()
     if group is None or group.academic_entity_type != 'term':
         print "Invalid group id."
         return
     tr = TermRepository()
     term = tr.fetch(group.academic_entity_id)
     tr.close()
     if term is None:
         print "Requested term not found."
         return
     cr = ClassRepository()
     classes = cr.find_classes_with_name_prefix(term, values['query'])
     cr.close()
     self.write(json.dumps([{"value":klass.name, "class_id":klass.id}
                           for klass in classes]))
Ejemplo n.º 12
0
    def _perform_request(self, user, name, values):
        class_id = values[u"class_id"]

        # get the appropriate class
        cr = ClassRepository()
        klass = cr.fetch(class_id)
        cr.close()

        if not klass:
            print "Invalid class id"
            return

        root_group = self.get_root_group()
        gr = GroupRepository()
        if not klass.group:
            # create the group
            group = Group()
            group.name = klass.name
            group.type = 0
            group.academic_entity_id = class_id
            group = gr.persist(group)
            gr.add_group_as_subgroup(root_group.id, group.id)
            klass.group = group.id
            # associate with the class
            cr = ClassRepository()
            cr.persist(klass)
            cr.close()
        else:
            group = gr.fetch(klass.group)
        gr.close()

        # assign the user as a member of the subgroup
        user.groups = user.groups + [group.id]
        self._persist_user(user)

        result = {}

        result['id'] = group.id
        result['name'] = group.name
        result['maintainer'] = ""

        self.write(json.dumps(result))
Ejemplo n.º 13
0
    def _perform_request(self, user, name, values):
        meeting_time  = values[u"meeting_time"]
        meeting_message = values[u"meeting_message"]
        group_id = values[u"group_id"]
        curr_user = self.get_current_user()

        ur = UserRepository()
        users = ur.get_members_of_group(group_id)        
        ur.close()

        gr = GroupRepository()
        group = gr.fetch(group_id)
        gr.close()

        cm = CukeMail()
        cm.subject(group.name + " meeting @ " + meeting_time)
        cm.message(meeting_message)
        cm.send([user.email for user in users])

        self._persist_user(curr_user)
Ejemplo n.º 14
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
Ejemplo n.º 15
0
    def _valid_request(self, user, attr, deadline_id, value):
        # User parameters must be defined
        if not user or not attr or not value or not deadline_id:
            print "Invalid Request. Parameters Missing"
            return False

        new_time = value[0].decode("utf-8")

        # Strip the 0000- year off the time.
        new_time = datetime.strptime(new_time[5:], "%m-%d %H:%M")
        # Add the correct year
        new_time = new_time + (date(datetime.now().year, 1, 1) - date(new_time.year, 1, 1))
        if new_time < datetime.now():
            print "Invalid time"
            return False

        # The deadline associated with the deadline_id must exist
        deadline_repo = DeadlineRepository()
        dead = deadline_repo.deadline_for_user(user.id, deadline_id)
        deadline_repo.close()

        if not dead or not dead.name or not dead.group_id:
            print "Something is wrong with the deadline object."
            return False

        group_repo = GroupRepository()
        group = group_repo.fetch(dead.group_id)
        group_repo.close()
        if not group:
            print "Associated group doesn't exist."
            return False

        if not (dead.type == "PER" or
                (group.maintainerId == dead.group_id and dead.type == "END")):
            print "User cannot modify this deadline"
            return False

        return True
Ejemplo n.º 16
0
    def _perform_request(self, user, name, values):
        group_id = values[u"group_id"]
        new_user_email = values[u"user_email"]

        group_repo = GroupRepository()
        group = group_repo.fetch(group_id)
        group_repo.close()

        new_user_repo = UserRepository()
        new_user = new_user_repo.get_user_by_email(new_user_email)
        new_user_repo.add_user_to_group(new_user, group)
        new_user_repo.close()

        self._persist_user(new_user)

        result = {}

        result['name'] = new_user.name
        result['email'] = new_user.email
        result['iconURL'] = new_user.iconSmallURL
 
        self.write(json.dumps(result))
        self.flush
        self.finish
Ejemplo n.º 17
0
    def _valid_request(self, curr_user, name, values):
        # Malformed request
        if u"group_id" not in values or u"user_email" not in values:
            print "Malformed request detected."
            return False

        # Malformed request
        group_id = values[u"group_id"]
        new_user_email = values[u"user_email"]
        if not group_id or not new_user_email:
            print "Required data is missing."
            return False

        user_repo = UserRepository()
        member_list = user_repo.get_members_of_group(group_id)
        user_repo.close()
        if not any(member.id == curr_user.id for member in member_list):
            print "User is not a member of the associated group."
            return False

        group_repo = GroupRepository()
        parent_group = group_repo.get_supergroup_of_group(group_id)
        group_repo.close()
        if not group_repo:
            print "Cannot add member to the root group."
            return False

        user_repo = UserRepository()
        parent_member_list = user_repo.get_members_of_group(parent_group.id)
        user_repo.close()
        if not any(member.id == curr_user.id for member in parent_member_list):
            print "New user is not a member of the supergroup."
            return False

        # New user is already a member of the group
        new_user_repo = UserRepository()
        new_user = new_user_repo.get_user_by_email(new_user_email)
        new_user_repo.close()
        if not new_user:
            print "New user doesn't exist."
            return False

        if not new_user.groups:
            print "New user isn't a member of any groups."
            return False

        if group_id in new_user.groups:
            print "New user is already already a member of the group."
            return False

        group_repo = GroupRepository()
        group = group_repo.fetch(group_id)
        group_repo.close()
        if not group:
            print "Group doesn't exist"
            return False

        # 1 => Public
        if group.type == 1:
            print "Cannot add members to public groups"
            return False

        return True