Beispiel #1
0
    def addUser(self):
        firstName = self.request('f_name')
        lastName = self.request('l_name')
        email = self.request('email')
        password = self.request('password')
        userGroupId = util.try_f(int, self.request('role'))
        affiliation = self.request('affiliation')

        if (util.strNullOrEmpty(email) or not util.validate_email(email)):
            log.error("*** cms user submitted with invalid email")
            return False
        elif (util.strNullOrEmpty(password)):
            log.error("*** cms user submitted with no password")
            return False
        elif (not userGroupId):
            log.error("*** cms user submitted with no role")
            return False
        else:
            userId = mUser.createUser(self.db,
                                      email,
                                      password,
                                      firstName,
                                      lastName,
                                      affiliation=affiliation,
                                      isAdmin=(userGroupId == 1
                                               or userGroupId == 3))

            # do we want to attach ideas to cms users?
            mIdea.attachIdeasByEmail(self.db, email)

            mUser.assignUserToGroup(self.db, userId, userGroupId)

            return userId
Beispiel #2
0
    def addUser(self):
        firstName = self.request('f_name')
        lastName = self.request('l_name')
        email = self.request('email')
        password = self.request('password')
        userGroupId = util.try_f(int, self.request('role'))
        affiliation = self.request('affiliation')

        if (util.strNullOrEmpty(email)or not util.validate_email(email)):
            log.error("*** cms user submitted with invalid email")
            return False
        elif (util.strNullOrEmpty(password)):
            log.error("*** cms user submitted with no password")
            return False
        elif (not userGroupId):
            log.error("*** cms user submitted with no role")
            return False
        else:
            userId = mUser.createUser(self.db, email, password, firstName, lastName, affiliation = affiliation, isAdmin = (userGroupId == 1 or userGroupId == 3))

            # do we want to attach ideas to cms users?
            mIdea.attachIdeasByEmail(self.db, email)

            mUser.assignUserToGroup(self.db, userId, userGroupId)

            return userId
Beispiel #3
0
    def addLink(self):
        if (self.request('main_text')): return False

        projectId = self.request('project_id')
        title = self.request('title')
        url = util.makeUrlAbsolute(self.request('url')) if self.request('url') else None

        if (not projectId or util.strNullOrEmpty(title) or util.strNullOrEmpty(url)):
            log.error("*** link submitted w/o id, title, or url")
            return False
        else:
            return mProject.addLinkToProject(self.db, projectId, title, url)
Beispiel #4
0
    def addLink(self):
        if (self.request('main_text')): return False

        projectId = self.request('project_id')
        title = self.request('title')
        url = util.makeUrlAbsolute(
            self.request('url')) if self.request('url') else None

        if (not projectId or util.strNullOrEmpty(title)
                or util.strNullOrEmpty(url)):
            log.error("*** link submitted w/o id, title, or url")
            return False
        else:
            return mProject.addLinkToProject(self.db, projectId, title, url)
Beispiel #5
0
 def editUser(self):
     firstName = self.request('f_name')
     lastName = self.request('l_name')
     email = self.request('email')
     imageId = self.request('image_id')
     locationId = self.request('location_id')
      
     if (not util.strNullOrEmpty(firstName) and
         not util.strNullOrEmpty(lastName) and
         not util.strNullOrEmpty(email)):
         return self.user.updateInfo(self.user, email, firstName, lastName, imageId, locationId)
     else:
         log.info("*** not enough info to update user")
         return False
Beispiel #6
0
    def editUser(self):
        firstName = self.request('f_name')
        lastName = self.request('l_name')
        email = self.request('email')
        imageId = self.request('image_id')
        locationId = self.request('location_id')

        if (not util.strNullOrEmpty(firstName)
                and not util.strNullOrEmpty(lastName)
                and not util.strNullOrEmpty(email)):
            return self.user.updateInfo(self.user, email, firstName, lastName,
                                        imageId, locationId)
        else:
            log.info("*** not enough info to update user")
            return False
Beispiel #7
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
Beispiel #8
0
    def addMessage(self):
        """
        Add a message to the project discussion stream.

        POST Parameters:
        ---------------
        project_id -- The id of the project
        main_text -- The message contents
        attachment_id -- (optional) The file attachment on the message. If no
            file attachment is available, it should be an empty string or left
            off of the request entirely.

        """
        if (self.request('main_text')): return False

        projectId = self.request('project_id')
        message = self.request('message')

        # If the file_id is None or empty string, record it as None.
        attachmentId = self.request('attachment_id') or None

        if (not projectId):
            log.error("*** message add attempted w/o project id")
            return False
        elif (util.strNullOrEmpty(message)):
            log.error("*** message add attempted w/ no message")
            return False
        else:
            return mProject.addMessage(self.db,
                                       projectId,
                                       message,
                                       'member_comment',
                                       self.user.id,
                                       attachmentId=attachmentId)
Beispiel #9
0
    def addMessage(self):
        """
        Add a message to the project discussion stream.

        POST Parameters:
        ---------------
        project_id -- The id of the project
        main_text -- The message contents
        attachment_id -- (optional) The file attachment on the message. If no
            file attachment is available, it should be an empty string or left
            off of the request entirely.

        """
        if (self.request('main_text')): return False

        projectId = self.request('project_id')
        message = self.request('message')

        # If the file_id is None or empty string, record it as None.
        attachmentId = self.request('attachment_id') or None

        if (not projectId):
            log.error("*** message add attempted w/o project id")
            return False
        elif (util.strNullOrEmpty(message)):
            log.error("*** message add attempted w/ no message")
            return False
        else:
            return mProject.addMessage(self.db, projectId, message,
                                       'member_comment', self.user.id,
                                       attachmentId=attachmentId)
Beispiel #10
0
 def addHomepageQuestion(self):
     q = self.request('question')
 
     if (util.strNullOrEmpty(q)):
         log.error("*** attempt to add question with no question content")
         return False
     else:
         try:
             self.db.insert('homepage_question', question = q, created_datetime = None)
             return True
         except Exception, e:
             log.info("*** error inserting new question")
             log.error(e)
             return False
Beispiel #11
0
    def updateResourceKeywords(self):
        resourceId = util.try_f(int, self.request('resource_id'))

        if (not self.user or not self.user.isResourceOwner(resourceId)):
            log.error(
                "*** resource edit attempt without ownership, resource id %s" %
                resourceId)
            return False

        keywords = ' '.join([
            word.strip() for word in self.request('keywords').split(',')
        ]) if not util.strNullOrEmpty(self.request('keywords')) else None

        return mProjectResource.updateProjectResourceTextData(
            self.db, resourceId, 'keywords', keywords)
Beispiel #12
0
    def addHomepageQuestion(self):
        q = self.request('question')

        if (util.strNullOrEmpty(q)):
            log.error("*** attempt to add question with no question content")
            return False
        else:
            try:
                self.db.insert('homepage_question',
                               question=q,
                               created_datetime=None)
                return True
            except Exception, e:
                log.info("*** error inserting new question")
                log.error(e)
                return False
Beispiel #13
0
    def addResource(self):
        if (self.request('main_text')): return False

        title = self.request('title')
        description = self.request('description')
        physical_address = self.request('physical_address')
        location_id = util.try_f(int, self.request('location_id'), -1)
        url = util.makeUrlAbsolute(
            self.request('url')) if self.request('url') else None
        keywords = ' '.join([
            word.strip() for word in self.request('keywords').split(',')
        ]) if not util.strNullOrEmpty(self.request('keywords')) else None
        contact_name = self.request('contact_name')
        contact_email = self.request('contact_email')
        facebook_url = util.makeUrlAbsolute(self.request(
            'facebook_url')) if self.request('facebook_url') else None
        twitter_url = util.makeUrlAbsolute(self.request(
            'twitter_url')) if self.request('twitter_url') else None
        image_id = util.try_f(int, self.request('image'))

        # TODO this is a temp fix for a form issue
        if (contact_name == 'null'):
            contact_name = None

        try:
            projectResourceId = self.db.insert(
                'project_resource',
                title=title,
                description=description,
                physical_address=physical_address,
                location_id=location_id,
                url=url,
                facebook_url=facebook_url,
                twitter_url=twitter_url,
                keywords=keywords,
                contact_name=contact_name,
                contact_email=contact_email,
                created_datetime=None,
                image_id=image_id,
                is_hidden=1,
                contact_user_id=self.user.id)

            return True
        except Exception, e:
            log.info("*** couldn't add resource to system")
            log.error(e)
            return False
Beispiel #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
Beispiel #15
0
    def updateResourceKeywords(self):
        resourceId = util.try_f(int, self.request('resource_id'))

        if (not self.user or not self.user.isResourceOwner(resourceId)): 
            log.error("*** resource edit attempt without ownership, resource id %s" % resourceId)
            return False

        keywords = ' '.join([word.strip() for word in self.request('keywords').split(',')]) if not util.strNullOrEmpty(self.request('keywords')) else None
        
        return mProjectResource.updateProjectResourceTextData(self.db, resourceId, 'keywords', keywords)
Beispiel #16
0
    def addResource(self):
        if (self.request('main_text')): return False

        title = self.request('title')
        description = self.request('description')
        physical_address = self.request('physical_address')
        location_id = util.try_f(int, self.request('location_id'), -1)
        url = util.makeUrlAbsolute(self.request('url')) if self.request('url')  else None
        keywords = ' '.join([word.strip() for word in self.request('keywords').split(',')]) if not util.strNullOrEmpty(self.request('keywords')) else None
        contact_name = self.request('contact_name')
        contact_email = self.request('contact_email')
        facebook_url = util.makeUrlAbsolute(self.request('facebook_url')) if self.request('facebook_url') else None
        twitter_url = util.makeUrlAbsolute(self.request('twitter_url')) if self.request('twitter_url') else None
        image_id = util.try_f(int, self.request('image')) 
        
        # TODO this is a temp fix for a form issue
        if (contact_name == 'null'):
            contact_name = None
            
        try:
            projectResourceId = self.db.insert('project_resource', 
                                        title = title,
                                        description = description,
                                        physical_address = physical_address,
                                        location_id = location_id,
                                        url = url,
                                        facebook_url = facebook_url,
                                        twitter_url = twitter_url,
                                        keywords = keywords,
                                        contact_name = contact_name,
                                        contact_email = contact_email,
                                        created_datetime = None,
                                        image_id = image_id,
                                        is_hidden = 1,
                                        contact_user_id = self.user.id)
            
            return True
        except Exception,e:
            log.info("*** couldn't add resource to system")
            log.error(e)
            return False
Beispiel #17
0
 def test_strNullOrEmpty(self):
     self.assertFalse(util.strNullOrEmpty("hello world"))
     self.assertTrue(util.strNullOrEmpty(""))
     self.assertTrue(util.strNullOrEmpty(None))
     self.assertTrue(util.strNullOrEmpty("    "))
Beispiel #18
0
    def newProject(self):
        if (self.request('main_text')): return False

        supported_features = Config.get('features')

        if (self.user):
            owner_user_id = self.user.id
            title = self.request('title')
            description = self.request('text')
            organization = self.request('organization')
            locationId = util.try_f(int, self.request('location_id'), -1)
            imageId = self.request('image')
            keywords = [word.strip() for word in self.request('keywords').split(',')] if not util.strNullOrEmpty(self.request('keywords')) else []
            resourceIds = self.request('resources').split(',')
            isOfficial = self.user.isAdmin and supported_features.get('is_official_supported')

            projectId = mProject.createProject(self.db, owner_user_id, title, description, ' '.join(keywords), locationId, imageId, isOfficial, organization)

            for resourceId in resourceIds:
                log.info("*** insert resource id %s" % resourceId)
                mProject.addResourceToProject(self.db, projectId, resourceId)

            if (projectId):
                return projectId
            else:
                log.error("*** couldn't create project")
                return False
        else:
            log.error("*** only logged in users can create projects")
            return False