Exemple #1
0
    def join(self):
        projectId = self.request('project_id')
        description = self.request('message')

        if (not self.user):
            log.error("*** join submitted w/o logged in user")
            return False
        elif (not projectId):
            log.error("*** join submitted w/o logged project id")
            return False
        elif (util.strNullOrEmpty(description)):
            log.error("*** join submitted w/o idea")
            return False
        else:
            isJoined = mProject.join(self.db, projectId, self.user.id)

            if (isJoined):
                project = mProject.Project(self.db, projectId)

                # create the user's "hello there" idea and add to project
                newIdeaId = mIdea.createIdea(self.db,
                                            description,
                                            project.data.location_id,
                                            'web',
                                            self.user.id,
                                            self.user.email)

                if (newIdeaId):
                    if (not mIdea.addIdeaToProject(self.db, newIdeaId, projectId)):
                        log.error("*** new idea not created for user %s on joining project %s" % (self.user.id, projectId))
                else:
                    log.error("*** new idea not created for user %s on joining project %s" % (self.user.id, projectId))

                # automatically insert any ideas attached to invites for this user and this project
                if (not mIdea.addInvitedIdeaToProject(self.db, projectId, self.user.id)):
                    log.error("*** couldn't add invited idea to project for user %s on joining project %s" % (self.user.id, projectId))

                # add a message to the queue about the join
                message = 'New Member! Your project now has %s total!' % project.data.num_members

                # email admin
                if (not mMessaging.emailProjectJoin(project.data.owner_email,
                                                    projectId,
                                                    project.data.title,
                                                    self.user.id,
                                                    mProject.userNameDisplay(self.user.firstName,
                                                                             self.user.lastName,
                                                                             self.user.affiliation,
                                                                             mProject.isFullLastName(self.user.groupMembershipBitmask)))):
                    log.error("*** couldn't email admin on user_id = %s joining project %s" % (self.user.id, projectId))

                if (not mProject.addMessage(self.db,
                                            projectId,
                                            message,
                                            'join',
                                            self.user.id,
                                            newIdeaId)):
                    log.error("*** new message not created for user %s on joining project %s" % (self.user.id, projectId))

        return isJoined
    def display_name(self):
        import framework.controller
        from giveaminute import project

        return project.userNameDisplay(
            self.first_name, self.last_name, self.affiliation,
            project.isFullLastName(self.group_membership_bitmask))
Exemple #3
0
def getAdminUsers(db, limit=10, offset=0):
    betterData = []

    try:
        sql = """select distinct
                    u.user_id
                    ,u.email
                    ,u.first_name
                    ,u.last_name
                    ,u.affiliation
                    ,u.group_membership_bitmask
                    ,u.is_oncall
                from user u
                where u.is_active = 1
                   and u.group_membership_bitmask > 1
                order by u.last_name
                limit $limit offset $offset"""
        data = list(db.query(sql, {'limit': limit, 'offset': offset}))

        for item in data:
            betterData.append({
                'user_id':
                item.user_id,
                'email':
                item.email,
                'first_name':
                item.first_name,
                'last_name':
                item.last_name,
                'affiliation':
                item.affiliation,
                'group_membership_bitmask':
                item.group_membership_bitmask,
                'full_display_name':
                mProject.userNameDisplay(
                    item.first_name, item.last_name, item.affiliation,
                    mProject.isFullLastName(item.group_membership_bitmask)),
                'is_admin':
                isAdminBitmask(item.group_membership_bitmask),
                'is_moderator':
                isModeratorBitmask(item.group_membership_bitmask),
                'is_leader':
                isLeaderBitmask(item.group_membership_bitmask),
                'is_oncall':
                item.is_oncall
            })
    except Exception, e:
        log.info("*** couldn't get admin users")
        log.error(e)
Exemple #4
0
    def getProfileActivityDictionary(self):
        user = mProject.smallUserDisplay(self.id,
                                         mProject.userNameDisplay(self.firstName,
                                                                  self.lastName,
                                                                  self.affiliation,
                                                                  mProject.isFullLastName(self.groupMembershipBitmask)),
                                         self.imageId)
        user['location_id'] = self.locationId
        user['location'] = self.location
        user['description'] = self.description
        user['is_leader'] = self.isLeader

        data = dict(projects = self.getProjects(),
                    ideas = self.getIdeas(),
                    endorsed_projects = self.getEndorsedProjects(),
                    user = user)

        return data
Exemple #5
0
    def getProfileActivityDictionary(self):
        user = mProject.smallUserDisplay(
            self.id,
            mProject.userNameDisplay(
                self.firstName, self.lastName, self.affiliation,
                mProject.isFullLastName(self.groupMembershipBitmask)),
            self.imageId)
        user['location_id'] = self.locationId
        user['location'] = self.location
        user['description'] = self.description
        user['is_leader'] = self.isLeader

        data = dict(projects=self.getProjects(),
                    ideas=self.getIdeas(),
                    endorsed_projects=self.getEndorsedProjects(),
                    user=user)

        return data
Exemple #6
0
    def getEndorsedProjects(self):
        betterData = []

        try:
            sql = """select p.project_id,
                        p.title,
                        p.description,
                        p.image_id,
                        p.location_id,
                        o.user_id as owner_user_id,
                        o.first_name as owner_first_name,
                        o.last_name as owner_last_name,
                        o.affiliation as owner_affiliation,
                        o.group_membership_bitmask as owner_group_membership_bitmask,
                        o.image_id as owner_image_id,
                    (select count(cpu.user_id) from project__user cpu where cpu.project_id = p.project_id) as num_members
                from project p
                inner join project_endorsement pe on pe.project_id = p.project_id and pe.user_id = $id
                inner join project__user pu on pu.project_id = p.project_id and pu.is_project_creator = 1
                inner join user o on o.user_id = pu.user_id
                 where p.is_active = 1"""
            data = list(self.db.query(sql, {'id': self.id}))

            for item in data:
                betterData.append(
                    dict(project_id=item.project_id,
                         title=item.title,
                         description=item.description,
                         image_id=item.image_id,
                         location_id=item.location_id,
                         owner=mProject.smallUserDisplay(
                             item.owner_user_id,
                             mProject.userNameDisplay(
                                 item.owner_first_name, item.owner_last_name,
                                 item.owner_affiliation,
                                 mProject.isFullLastName(
                                     item.owner_group_membership_bitmask)),
                             item.owner_image_id),
                         num_members=item.num_members))
        except Exception, e:
            log.info("*** couldn't get user endorsed projects")
            log.error(e)
Exemple #7
0
    def user_to_dict(self, user):
        """Convert a user instance in the context of being a need volunteer to
           a dictionary"""

        from giveaminute.project import userNameDisplay
        from giveaminute.project import isFullLastName

        user_dict = super(NeedModelRestController, self).instance_to_dict(user)

        # Add in some of that non-orm goodness
        user_dict['avatar_path'] = user.avatar_path
        user_dict['display_name'] = userNameDisplay(
            user.first_name, user.last_name, user.affiliation,
            isFullLastName(user.group_membership_bitmask))

        # Remove sensitive information
        del user_dict['password']
        del user_dict['salt']

        return user_dict
Exemple #8
0
    def user_to_dict(self, user):
        """Convert a user instance in the context of being a need volunteer to
           a dictionary"""

        from giveaminute.project import userNameDisplay
        from giveaminute.project import isFullLastName

        user_dict = super(EventModelRestController, self).instance_to_dict(user)

        # Add in some of that non-orm goodness
        user_dict['avatar_path'] = user.avatar_path
        user_dict['display_name'] = userNameDisplay(
            user.first_name, user.last_name, user.affiliation,
            isFullLastName(user.group_membership_bitmask))

        # Remove sensitive information
        del user_dict['password']
        del user_dict['salt']

        return user_dict
Exemple #9
0
def authGetUser(db, email, password):
    sql = "select user_id, first_name, last_name, affiliation, group_membership_bitmask, image_id, email, password, salt from user where email = $email and is_active = 1"
    data = db.query(sql, {'email':email})

    if (len(data) > 0):
        user = list(data)[0]
        hashed_password = makePassword(password, user.salt)

        if (hashed_password[0] == user.password):
            log.info("*** User authenticated")
            return mProject.smallUserDisplay(user.user_id,
                                             mProject.userNameDisplay(user.first_name,
                                                                      user.last_name,
                                                                      user.affiliation,
                                                                      mProject.isFullLastName(user.group_membership_bitmask)),
                                             user.image_id)
        else:
            log.warning("*** User not authenticated for email = %s" % email)
            return None
    else:
        log.warning("*** No record for email= %s" % email)
        return None
Exemple #10
0
    def join(self):
        projectId = self.request('project_id')

        if (not self.user):
            log.error("*** join submitted w/o logged in user")
            return False
        elif (not projectId):
            log.error("*** join submitted w/o logged project id")
            return False

        else:
            isJoined = mProject.join(self.db, projectId, self.user.id)

            if (isJoined):
                project = mProject.Project(self.db, projectId)

                # add a message to the queue about the join
                message = 'New Member! Your project now has %s total!' % project.data.num_members

                # email admin
                if (not mMessaging.emailProjectJoin(
                        project.data.owner_email, projectId,
                        project.data.title, self.user.id,
                        mProject.userNameDisplay(
                            self.user.firstName, self.user.lastName,
                            self.user.affiliation,
                            mProject.isFullLastName(
                                self.user.groupMembershipBitmask)))):
                    log.error(
                        "*** couldn't email admin on user_id = %s joining project %s"
                        % (self.user.id, projectId))

                if (not mProject.addMessage(self.db, projectId, message,
                                            'join', self.user.id)):
                    log.error(
                        "*** new message not created for user %s on joining project %s"
                        % (self.user.id, projectId))

        return isJoined
Exemple #11
0
def authGetUser(db, email, password):
    sql = "select user_id, first_name, last_name, affiliation, group_membership_bitmask, image_id, email, password, salt from user where email = $email and is_active = 1"
    data = db.query(sql, {'email': email})

    if (len(data) > 0):
        user = list(data)[0]
        hashed_password = makePassword(password, user.salt)

        if (hashed_password[0] == user.password):
            log.info("*** User authenticated")
            return mProject.smallUserDisplay(
                user.user_id,
                mProject.userNameDisplay(
                    user.first_name, user.last_name, user.affiliation,
                    mProject.isFullLastName(user.group_membership_bitmask)),
                user.image_id)
        else:
            log.warning("*** User not authenticated for email = %s" % email)
            return None
    else:
        log.warning("*** No record for email= %s" % email)
        return None
Exemple #12
0
    def join(self):
        projectId = self.request('project_id')

        if (not self.user):
            log.error("*** join submitted w/o logged in user")
            return False
        elif (not projectId):
            log.error("*** join submitted w/o logged project id")
            return False
        
        else:
            isJoined = mProject.join(self.db, projectId, self.user.id)

            if (isJoined):
                project = mProject.Project(self.db, projectId)
                
                # add a message to the queue about the join
                message = 'New Member! Your project now has %s total!' % project.data.num_members

                # email admin
                if (not mMessaging.emailProjectJoin(project.data.owner_email,
                                                    projectId,
                                                    project.data.title,
                                                    self.user.id,
                                                    mProject.userNameDisplay(self.user.firstName,
                                                                             self.user.lastName,
                                                                             self.user.affiliation,
                                                                             mProject.isFullLastName(self.user.groupMembershipBitmask)))):
                    log.error("*** couldn't email admin on user_id = %s joining project %s" % (self.user.id, projectId))

                if (not mProject.addMessage(self.db,
                                            projectId,
                                            message,
                                            'join',
                                            self.user.id)):
                    log.error("*** new message not created for user %s on joining project %s" % (self.user.id, projectId))

        return isJoined
Exemple #13
0
def getAdminUsers(db, limit = 10, offset = 0):
    betterData = []

    try:
        sql = """select distinct
                    u.user_id
                    ,u.email
                    ,u.first_name
                    ,u.last_name
                    ,u.affiliation
                    ,u.group_membership_bitmask
                    ,u.is_oncall
                from user u
                where u.is_active = 1
                   and u.group_membership_bitmask > 1
                order by u.last_name
                limit $limit offset $offset"""
        data = list(db.query(sql, {'limit':limit, 'offset':offset}))

        for item in data:
            betterData.append({'user_id' : item.user_id,
                               'email' : item.email,
                               'first_name' : item.first_name,
                               'last_name' : item.last_name,
                               'affiliation' : item.affiliation,
                               'group_membership_bitmask' : item.group_membership_bitmask,
                               'full_display_name' : mProject.userNameDisplay(item.first_name,
                                                                              item.last_name,
                                                                              item.affiliation,
                                                                              mProject.isFullLastName(item.group_membership_bitmask)),
                               'is_admin' : isAdminBitmask(item.group_membership_bitmask),
                               'is_moderator' : isModeratorBitmask(item.group_membership_bitmask),
                               'is_leader' : isLeaderBitmask(item.group_membership_bitmask),
                               'is_oncall' : item.is_oncall})
    except Exception, e:
        log.info("*** couldn't get admin users")
        log.error(e)
Exemple #14
0
    def join(self):
        projectId = self.request('project_id')
        description = self.request('message')

        if (not self.user):
            log.error("*** join submitted w/o logged in user")
            return False
        elif (not projectId):
            log.error("*** join submitted w/o logged project id")
            return False
        elif (util.strNullOrEmpty(description)):
            log.error("*** join submitted w/o idea")
            return False
        else:
            isJoined = mProject.join(self.db, projectId, self.user.id)

            if (isJoined):
                project = mProject.Project(self.db, projectId)

                # create the user's "hello there" idea and add to project
                newIdeaId = mIdea.createIdea(self.db, description,
                                             project.data.location_id, 'web',
                                             self.user.id, self.user.email)

                if (newIdeaId):
                    if (not mIdea.addIdeaToProject(self.db, newIdeaId,
                                                   projectId)):
                        log.error(
                            "*** new idea not created for user %s on joining project %s"
                            % (self.user.id, projectId))
                else:
                    log.error(
                        "*** new idea not created for user %s on joining project %s"
                        % (self.user.id, projectId))

                # automatically insert any ideas attached to invites for this user and this project
                if (not mIdea.addInvitedIdeaToProject(self.db, projectId,
                                                      self.user.id)):
                    log.error(
                        "*** couldn't add invited idea to project for user %s on joining project %s"
                        % (self.user.id, projectId))

                # add a message to the queue about the join
                message = 'New Member! Your project now has %s total!' % project.data.num_members

                # email admin
                if (not mMessaging.emailProjectJoin(
                        project.data.owner_email, projectId,
                        project.data.title, self.user.id,
                        mProject.userNameDisplay(
                            self.user.firstName, self.user.lastName,
                            self.user.affiliation,
                            mProject.isFullLastName(
                                self.user.groupMembershipBitmask)))):
                    log.error(
                        "*** couldn't email admin on user_id = %s joining project %s"
                        % (self.user.id, projectId))

                if (not mProject.addMessage(self.db, projectId, message,
                                            'join', self.user.id, newIdeaId)):
                    log.error(
                        "*** new message not created for user %s on joining project %s"
                        % (self.user.id, projectId))

        return isJoined
Exemple #15
0
    def getMessages(self, limit, offset):
        """
        Returns a list of messages for this user.  The results are paginated
        (i.e., this will return ``limit`` rows, starting at ``ofsset``-th row).

        """
        messages = []

        try:
            sql = """select
                        p.project_id,
                        p.title,
                        m.project_message_id,
                        m.message_type,
                        m.message,
                        m.created_datetime as created_datetime,
                        mu.user_id,
                        mu.first_name,
                        mu.last_name,
                        mu.affiliation,
                        mu.group_membership_bitmask,
                        mu.image_id,
                        i.idea_id,
                        i.description as idea_description,
                        i.submission_type as idea_submission_type,
                        i.created_datetime as idea_created_datetime
                    from project_message m
                    inner join project__user pu on pu.project_id = m.project_id and pu.user_id = $userId
                    inner join project p on p.project_id = pu.project_id and p.is_active = 1
                    inner join user mu on mu.user_id = m.user_id
                    left join idea i on i.idea_id = m.idea_id
                    where m.is_active = 1
                        union
                    select
                        p.project_id,
                        p.title,
                        null as project_message_id,
                        'invite' as message_type,
                        concat('You''ve been invited to the ',
                                ucase(p.title),
                                ' project!',
                                coalesce(concat('<br/><br/>"', inv.message, '"'), '')) as message,
                        inv.created_datetime as created_datetime,
                        iu.user_id,
                        iu.first_name,
                        iu.last_name,
                        iu.affiliation,
                        iu.group_membership_bitmask,
                        iu.image_id,
                        i.idea_id,
                        i.description as idea_description,
                        i.submission_type as idea_submission_type,
                        i.created_datetime as idea_created_datetime
                    from project_invite inv
                    inner join project p on p.project_id = inv.project_id and p.is_active = 1
                    inner join user iu on iu.user_id = inv.inviter_user_id
                    inner join idea i on i.idea_id = inv.invitee_idea_id and i.user_id =$userId
                    order by created_datetime desc
                    limit $limit offset $offset"""
            data = list(self.db.query(sql, {'userId':self.id, 'limit':limit, 'offset':offset}))

            for item in data:
                messages.append(mProject.message(id=item.project_message_id,
                                        type=item.message_type,
                                        message=item.message,
                                        createdDatetime=item.created_datetime,
                                        userId=item.user_id,
                                        name=mProject.userNameDisplay(item.first_name,
                                                                 item.last_name,
                                                                 item.affiliation,
                                                                 mProject.isFullLastName(item.group_membership_bitmask)),
                                        imageId=item.image_id,
                                        ideaId=item.idea_id,
                                        idea=item.idea_description,
                                        ideaSubType=item.idea_submission_type,
                                        ideaCreatedDatetime=item.idea_created_datetime,
                                        projectId=item.project_id,
                                        projectTitle=item.title))
        except Exception, e:
            log.info("*** couldn't get messages")
            log.error(e)
Exemple #16
0
    def getEndorsedProjects(self):
        betterData = []

        try:
            sql = """select p.project_id,
                        p.title,
                        p.description,
                        p.image_id,
                        p.location_id,
                        o.user_id as owner_user_id,
                        o.first_name as owner_first_name,
                        o.last_name as owner_last_name,
                        o.affiliation as owner_affiliation,
                        o.group_membership_bitmask as owner_group_membership_bitmask,
                        o.image_id as owner_image_id,
                    (select count(cpu.user_id) from project__user cpu where cpu.project_id = p.project_id) as num_members
                from project p
                inner join project_endorsement pe on pe.project_id = p.project_id and pe.user_id = $id
                inner join project__user pu on pu.project_id = p.project_id and pu.is_project_creator = 1
                inner join user o on o.user_id = pu.user_id
                 where p.is_active = 1"""
            data  = list(self.db.query(sql, { 'id': self.id }))

            for item in data:
                betterData.append(dict(project_id = item.project_id,
                                        title = item.title,
                                        description = item.description,
                                        image_id = item.image_id,
                                        location_id = item.location_id,
                                        owner = mProject.smallUserDisplay(item.owner_user_id,
                                                                          mProject.userNameDisplay(item.owner_first_name,
                                                                                                   item.owner_last_name,
                                                                                                   item.owner_affiliation,
                                                                                                   mProject.isFullLastName(item.owner_group_membership_bitmask)),
                                                                 item.owner_image_id),
                                        num_members = item.num_members))
        except Exception,e:
            log.info("*** couldn't get user endorsed projects")
            log.error(e)
Exemple #17
0
    def getMessages(self, limit, offset):
        """
        Returns a list of messages for this user.  The results are paginated
        (i.e., this will return ``limit`` rows, starting at ``ofsset``-th row).

        """
        messages = []

        try:
            sql = """select
                        p.project_id,
                        p.title,
                        m.project_message_id,
                        m.message_type,
                        m.message,
                        m.created_datetime as created_datetime,
                        mu.user_id,
                        mu.first_name,
                        mu.last_name,
                        mu.affiliation,
                        mu.group_membership_bitmask,
                        mu.image_id,
                        i.idea_id,
                        i.description as idea_description,
                        i.submission_type as idea_submission_type,
                        i.created_datetime as idea_created_datetime
                    from project_message m
                    inner join project__user pu on pu.project_id = m.project_id and pu.user_id = $userId
                    inner join project p on p.project_id = pu.project_id and p.is_active = 1
                    inner join user mu on mu.user_id = m.user_id
                    left join idea i on i.idea_id = m.idea_id
                    where m.is_active = 1
                        union
                    select
                        p.project_id,
                        p.title,
                        null as project_message_id,
                        'invite' as message_type,
                        concat('You''ve been invited to the ',
                                ucase(p.title),
                                ' project!',
                                coalesce(concat('<br/><br/>"', inv.message, '"'), '')) as message,
                        inv.created_datetime as created_datetime,
                        iu.user_id,
                        iu.first_name,
                        iu.last_name,
                        iu.affiliation,
                        iu.group_membership_bitmask,
                        iu.image_id,
                        i.idea_id,
                        i.description as idea_description,
                        i.submission_type as idea_submission_type,
                        i.created_datetime as idea_created_datetime
                    from project_invite inv
                    inner join project p on p.project_id = inv.project_id and p.is_active = 1
                    inner join user iu on iu.user_id = inv.inviter_user_id
                    inner join idea i on i.idea_id = inv.invitee_idea_id and i.user_id =$userId
                    order by created_datetime desc
                    limit $limit offset $offset"""
            data = list(
                self.db.query(sql, {
                    'userId': self.id,
                    'limit': limit,
                    'offset': offset
                }))

            for item in data:
                messages.append(
                    mProject.message(
                        id=item.project_message_id,
                        type=item.message_type,
                        message=item.message,
                        createdDatetime=item.created_datetime,
                        userId=item.user_id,
                        name=mProject.userNameDisplay(
                            item.first_name, item.last_name, item.affiliation,
                            mProject.isFullLastName(
                                item.group_membership_bitmask)),
                        imageId=item.image_id,
                        ideaId=item.idea_id,
                        idea=item.idea_description,
                        ideaSubType=item.idea_submission_type,
                        ideaCreatedDatetime=item.idea_created_datetime,
                        projectId=item.project_id,
                        projectTitle=item.title))
        except Exception, e:
            log.info("*** couldn't get messages")
            log.error(e)