Ejemplo n.º 1
0
    def test_add_userProfile_1(self):
        """Add new userProfile """

        newUserProfile = UserProfile()
        newUserProfile.id = _testUserProfiles[0].get('_user')
        newUserProfile.name = _testUserProfiles[0].get('_name')
        newUserProfile.email = _testUserProfiles[0].get('_email')
        newUserProfile.picture_href = _testUserProfiles[0].get('_picture_href')
        newUserProfile.bio = _testUserProfiles[0].get('_bio')
        newUserProfile.role = _testUserProfiles[0].get('_role')

        self.userProfilesSystem.add_userProfile(newUserProfile)

        db = self.env.get_db_cnx()
        cursor = db.cursor()
        cursor.execute(
            'SELECT name, value FROM session_attribute WHERE sid=%s',
            (_testUserProfiles[0].get('_user'), ))

        _result = {}
        for name, value in cursor:
            _result[name] = value

        self.assertEqual(_result['enabled'], "1")
        self.assertEqual(_result['name'], _testUserProfiles[0].get('_name'))
        self.assertEqual(_result['email'], _testUserProfiles[0].get('_email'))
        self.assertEqual(_result['picture_href'],
                         _testUserProfiles[0].get('_picture_href'))
        self.assertEqual(_result['bio'], _testUserProfiles[0].get('_bio'))
        self.assertEqual(_result['role'], _testUserProfiles[0].get('_role'))
Ejemplo n.º 2
0
    def test_get_searchUserProfiles(self):
        """Search userProfiles """

        self._loadData()

        searchResult = list(
            self.userProfilesSystem.search_userProfile(
                UserProfile(name="John%", role="%Dev%")))

        self.assertEqual(len(searchResult), 2)

        self.assertEqual(searchResult[0].name,
                         _testUserProfiles[0].get('_name'))
        self.assertEqual(searchResult[0].email,
                         _testUserProfiles[0].get('_email'))
        self.assertEqual(searchResult[0].picture_href,
                         _testUserProfiles[0].get('_picture_href'))
        self.assertEqual(searchResult[0].bio, _testUserProfiles[0].get('_bio'))
        self.assertEqual(searchResult[0].role,
                         _testUserProfiles[0].get('_role'))

        self.assertEqual(searchResult[1].name,
                         _testUserProfiles[1].get('_name'))
        self.assertEqual(searchResult[1].email,
                         _testUserProfiles[1].get('_email'))
        self.assertEqual(searchResult[1].picture_href,
                         _testUserProfiles[1].get('_picture_href'))
        self.assertEqual(searchResult[1].bio, _testUserProfiles[1].get('_bio'))
        self.assertEqual(searchResult[1].role,
                         _testUserProfiles[1].get('_role'))
Ejemplo n.º 3
0
 def _do_searchUserProfile(self, req, userProfilesSystem, teamRosterData):
     """ 
     @bug: SQL Injection !
     @todo: Fix it! ... later
     """
     userProfileTemplate = UserProfile(name='%'+req.args.get('tr_search_name')+'%')
     userProfiles = userProfilesSystem.search_userProfile(userProfileTemplate)
     teamRosterData['search_result'] = userProfiles
Ejemplo n.º 4
0
 def test_add_userProfile_1(self):
     """Add new userProfile """
     
     newUserProfile = UserProfile()
     newUserProfile.id = _testUserProfiles[0].get('_user')
     newUserProfile.name = _testUserProfiles[0].get('_name')
     newUserProfile.email =_testUserProfiles[0].get('_email')
     newUserProfile.picture_href = _testUserProfiles[0].get('_picture_href')
     newUserProfile.bio = _testUserProfiles[0].get('_bio')
     newUserProfile.role = _testUserProfiles[0].get('_role')
     
     self.userProfilesSystem.add_userProfile(newUserProfile)
     
     db=self.env.get_db_cnx()
     cursor = db.cursor()
     cursor.execute('SELECT name, value FROM session_attribute WHERE sid=%s',(_testUserProfiles[0].get('_user'),))
     
     _result = {}
     for name,value in cursor:
         _result[name]=value
     
     self.assertEqual(_result['enabled'], "1")
     self.assertEqual(_result['name'], _testUserProfiles[0].get('_name'))
     self.assertEqual(_result['email'], _testUserProfiles[0].get('_email'))
     self.assertEqual(_result['picture_href'], _testUserProfiles[0].get('_picture_href'))
     self.assertEqual(_result['bio'], _testUserProfiles[0].get('_bio'))
     self.assertEqual(_result['role'], _testUserProfiles[0].get('_role'))
Ejemplo n.º 5
0
    def render_admin_panel( self, req, cat, page, path_info):
        #req.perm.assert_permission('TRAC_ADMIN')
        userProfile_id = path_info
        teamRosterData={}
        userProfilesSystem = UserProfilesSystem(self.env)
        
        if req.args.has_key('tr_cancel'):
            req.redirect(req.href.admin(cat, page))
        
        if userProfile_id:
            userProfile = userProfilesSystem.get_userProfile(userProfile_id)
            if userProfile.exists:
                if self._do_updateUserProfile(req, userProfile, teamRosterData):
                    req.redirect(req.href.admin(cat, page))
                
                teamRosterData['userProfile']=userProfile
                add_stylesheet(req, 'tracteamroster/css/teamroster.css')    
                
                # wiki toolbar
                add_script(req, 'common/js/wikitoolbar.js')
                add_stylesheet(req, 'common/css/wiki.css')

                return 'admin_teamroster_userProfile.html', {'teamRoster':teamRosterData}
            else:
                req.redirect(req.href.admin(cat, page))
        teamRosterData['lastUpdatedProfile']= UserProfile()
        
        # manage team
        if req.method=="POST":
            if req.args.has_key("tr_userProfile_update"):
                userProfile = userProfilesSystem.get_userProfile(req.args.get('tr_userProfile_id'))
                if userProfile.exists:
                    self._do_updateUserProfile(req, userProfile, teamRosterData)
                    teamRosterData['lastUpdatedProfile']=userProfile
                
            if req.args.has_key("tr_userProfile_search"):
                self._do_searchUserProfile(req, userProfilesSystem, teamRosterData)
            
            if req.args.has_key("tr_userProfile_add"):
                self._do_addUserProfile(req, userProfilesSystem, teamRosterData)
            
            if req.args.has_key("tr_userProfile_create"):
                self._do_createUserProfile(req, userProfilesSystem, teamRosterData)
            
            if req.args.has_key("tr_userProfile_remove"):
                self._do_removeUserProfile(req, userProfilesSystem, teamRosterData)
                
        self._do_listActiveProfiles(req, userProfilesSystem, cat, page, teamRosterData)
        
        add_script(req, 'tracteamroster/js/teamroster.js')
        add_stylesheet(req, 'tracteamroster/css/teamroster.css')    
        
        # wiki toolbar
        add_script(req, 'common/js/wikitoolbar.js')
        add_stylesheet(req, 'common/css/wiki.css')
        
        return 'admin_teamroster_team.html', {'teamRoster':teamRosterData}
Ejemplo n.º 6
0
 def _do_createUserProfile(self, req, userProfilesSystem, teamRosterData):
     """ """    
     newUserProfile = UserProfile(id=req.args.get('tr_newprofile_id'),
                                  name=req.args.get('tr_newprofile_name'),
                                  email=req.args.get('tr_newprofile_email'),
                                  bio=req.args.get('tr_newprofile_bio'),
                                  role=req.args.get('tr_newprofile_role')
                                  )
     userProfilesSystem.add_userProfile(newUserProfile)
Ejemplo n.º 7
0
    def get_userProfile(self, userProfile_id):
        """ Returns userProfile from store.
        
        @param userProfile_id: str
        @return: tracteamroster.api.UserProfile
        """
        
        db = self.env.get_db_cnx()
        cursor = db.cursor()
        cursor.execute("SELECT sid, name, value FROM session_attribute "
                        "WHERE sid=%s and authenticated=1 ORDER BY sid", (userProfile_id,))
        _newUserProfile=UserProfile(userProfile_id, self)

        for sid, name, value in cursor:
            _newUserProfile[name] = value
            _newUserProfile.id = sid
            _newUserProfile.exists = True
        
        _newUserProfile.store = self
        
        return _newUserProfile
Ejemplo n.º 8
0
    def get_userProfile(self, userProfile_id):
        """ Returns userProfile from store.
        
        @param userProfile_id: str
        @return: tracteamroster.api.UserProfile
        """

        db = self.env.get_db_cnx()
        cursor = db.cursor()
        cursor.execute(
            "SELECT sid, name, value FROM session_attribute "
            "WHERE sid=%s and authenticated=1 ORDER BY sid",
            (userProfile_id, ))
        _newUserProfile = UserProfile(userProfile_id, self)

        for sid, name, value in cursor:
            _newUserProfile[name] = value
            _newUserProfile.id = sid
            _newUserProfile.exists = True

        _newUserProfile.store = self

        return _newUserProfile
Ejemplo n.º 9
0
 def _do_addUserProfile(self, req, userProfilesSystem, teamRosterData):
     """ """    
     uniq_ids = req.args.getlist('tr_search_result_userProfile')
     userProfilesTemplates = []
     
     if uniq_ids is None:
             return False
         
     for uniq_id in uniq_ids:
         storeClassName, userProfile_id = uniq_id.split("/")[0:2]
         userProfilesTemplates.append(UserProfile(str(userProfile_id), str(storeClassName)))
         
     for userProfile in userProfilesSystem.search_userProfile(userProfilesTemplates):
         userProfilesSystem.add_userProfile(userProfile)
Ejemplo n.º 10
0
    def _loadData(self):
        self.userProfilesSystem.add_userProfile(
            UserProfile(id=_testUserProfiles[0].get('_user'),
                        name=_testUserProfiles[0].get('_name'),
                        email=_testUserProfiles[0].get('_email'),
                        picture_href=_testUserProfiles[0].get('_picture_href'),
                        bio=_testUserProfiles[0].get('_bio'),
                        role=_testUserProfiles[0].get('_role')))

        self.userProfilesSystem.add_userProfile(
            UserProfile(id=_testUserProfiles[1].get('_user'),
                        name=_testUserProfiles[1].get('_name'),
                        email=_testUserProfiles[1].get('_email'),
                        picture_href=_testUserProfiles[1].get('_picture_href'),
                        bio=_testUserProfiles[1].get('_bio'),
                        role=_testUserProfiles[1].get('_role')))

        self.userProfilesSystem.add_userProfile(
            UserProfile(id=_testUserProfiles[2].get('_user'),
                        name=_testUserProfiles[2].get('_name'),
                        email=_testUserProfiles[2].get('_email'),
                        picture_href=_testUserProfiles[2].get('_picture_href'),
                        bio=_testUserProfiles[2].get('_bio'),
                        role=_testUserProfiles[2].get('_role')))
Ejemplo n.º 11
0
 def getTeamRoster(self, req, listUserProfilesTemplate=[]):
     """Returns project's team roster.
     
     Usage:
         {{{ teamroster.getTeamRoster() # without arguments returns current active user profiles (with enabled='1') }}}
         {{{ teamroster.getTeamRoster([{role='developer', enabled='1'}]) # Returns all userProfiles with role='developer' and enabled='1' }}}
         {{{ teamroster.getTeamRoster([{name='%someName%'}]) # Returns all userProfiles with name like 'someName' }}}
     """
     if isinstance(listUserProfilesTemplate, list) and len(listUserProfilesTemplate)>0:    
         userProfileTemplates = []
         for listItem in listUserProfilesTemplate:
             if isinstance(listItem, dict):
                 userProfileTemplates.append(UserProfile(**listItem))
         
         userProfiles = UserProfilesSystem(self.env).search_userProfile(userProfileTemplates)
         return [dict(listItem) for listItem in userProfiles]
     else:
         return [dict(listItem) for listItem in UserProfilesSystem(self.env).get_active_userProfiles()]
Ejemplo n.º 12
0
class SafeUserProfilesStore(Component):

    implements(IUserProfilesStore)

    # IUserProfilesStore methods
    def get_userProfile(self, userProfile_id, grabAllFieldsFromDB=False):
        """
        @param userProfile_id: str
        @return: tracteamroster.api.UserProfile
        """
        try:
            _result = list(
                self._get_userProfiles([userProfile_id], grabAllFieldsFromDB))
            if len(_result) > 0:
                return _result[0]
        except Exception, e:
            out = StringIO()
            traceback.print_exc(file=out)
            self.log.error('%s: %s\n%s' %
                           (self.__class__.__name__, str(e), out.getvalue()))

        return UserProfile(-1, self)
Ejemplo n.º 13
0
 def _get_userProfiles(self, userProfile_ids, grabAllFieldsFromDB=False):
     """This method returns the profiles defined by id 
     in userProfile_ids.
     
     How it works:
     
      1. Selecting only userProfile_ids
         userProfile_id      name    value
         jdoe                name    John Doe
         jdoe                email   [email protected]
         jdoe                role    Technical Arhitect
         jsmith              name    Joe Smith
         jsmith              email   [email protected]
         jsmith              role    Senior Developer
     
     2. marching through result set 
         
         _blankProfile=UserProfile(-1)
         for sid, name, value in thisExampleData:
             if _blankProfile.id!=sid:
                 if not firstLoop:
                     #loaded _blankProfile
                     yield _blankProfile
                 _blankProfile.id==sid
             _blankProfile[name]=value
         
     # Last item from loop (in thisExampleData it's about jsmith profile ).
     # We could avoid this by adding another loop / blank line
     yield _blankProfile
      
     @todo: Cache userProfiles
     
     @param userProfile_ids: list
     @return: list
     """
     
     db = self.env.get_db_cnx()
     cursor = db.cursor()
     if grabAllFieldsFromDB:
         cursor.execute("SELECT sid, name, value FROM session_attribute "
                        "WHERE sid in ('%s') ORDER BY sid"%("','".join(userProfile_ids)))
     else:
         cursor.execute("SELECT sid, name, value FROM session_attribute "
                        "WHERE sid in ('%s') and name in ('%s') ORDER BY sid"%("','".join(userProfile_ids), "','".join(UserProfile())))
     _newUserProfile=UserProfile(-1, self)
     _fieldsFromDb=[]
     for sid, name, value in cursor:
         if _newUserProfile.id!=sid:
             if _newUserProfile.id!=-1:
                 _newUserProfile.store=self
                 _newUserProfile.exists=True 
                 object.__setattr__(_newUserProfile, '_fieldsFromDb', _fieldsFromDb)
                 yield _newUserProfile
                 _newUserProfile=UserProfile(0, self)
                 _fieldsFromDb=[]
             _newUserProfile.id=sid
         _newUserProfile[name]=value
         _fieldsFromDb.append(name)
     
     # last _newUserProfile 
     if _newUserProfile.id!=-1:
         _newUserProfile.store=self
         _newUserProfile.exists=True
         object.__setattr__(_newUserProfile, '_fieldsFromDb', _fieldsFromDb)
         yield _newUserProfile
Ejemplo n.º 14
0
    def expand_macro(self, formatter, name, content):

        teamRosterData = dict(userProfiles=[])
        rendered_result = ""
        contentArgs = {}
        layoutArgs = {}
        userProfileTemplates = []

        # collecting arguments
        if content:
            for i, macroArgs in enumerate(content.split('|')):
                if i == 0:
                    contentArgs = MacroArguments(macroArgs)
                    self.log.error(contentArgs)
                    continue
                if i == 1:
                    layoutArgs = MacroArguments(macroArgs)
                    break

            # extracting userProfile attrs
            if len(contentArgs) > 0:
                userProfileTemplates.append(UserProfile(**contentArgs))

            if len(contentArgs.getListArgs()) > 0:
                for listItem in contentArgs.getListArgs():
                    userProfileTemplates.append(
                        UserProfile(**MacroArguments(listItem[1:len(listItem) -
                                                              1])))

        # _fixes
        def _fixes(userProfile):
            userProfile.bio_html = wiki_to_html(userProfile.bio, self.env,
                                                formatter.req) or "[blank]"
            return userProfile

        # grabbing userProfiles
        if len(userProfileTemplates) > 0:
            teamRosterData['userProfiles'] = map(
                _fixes,
                UserProfilesSystem(
                    self.env).search_userProfile(userProfileTemplates))
        else:
            teamRosterData['userProfiles'] = map(
                _fixes,
                UserProfilesSystem(self.env).get_active_userProfiles())

        # add stylesheet&script
        add_stylesheet(formatter.req, 'tracteamroster/css/teamroster.css')
        add_script(formatter.req, 'tracteamroster/js/teamroster.js')

        # render template
        rendered_result = Chrome(self.env).render_template(
            formatter.req,
            'macro_teamroster_team.html', {'teamRoster': teamRosterData},
            fragment=True)

        # wrap everything
        if len(layoutArgs) > 0:
            rendered_result = html.div(rendered_result, **layoutArgs)

        return rendered_result
Ejemplo n.º 15
0
    def _get_userProfiles(self, userProfile_ids, grabAllFieldsFromDB=False):
        """This method returns the profiles defined by id 
        in userProfile_ids.
        
        How it works:
        
         1. Selecting only userProfile_ids
            userProfile_id      name    value
            jdoe                name    John Doe
            jdoe                email   [email protected]
            jdoe                role    Technical Arhitect
            jsmith              name    Joe Smith
            jsmith              email   [email protected]
            jsmith              role    Senior Developer
        
        2. marching through result set 
            
            _blankProfile=UserProfile(-1)
            for sid, name, value in thisExampleData:
                if _blankProfile.id!=sid:
                    if not firstLoop:
                        #loaded _blankProfile
                        yield _blankProfile
                    _blankProfile.id==sid
                _blankProfile[name]=value
            
        # Last item from loop (in thisExampleData it's about jsmith profile ).
        # We could avoid this by adding another loop / blank line
        yield _blankProfile
         
        @todo: Cache userProfiles
        
        @param userProfile_ids: list
        @return: list
        """

        db = self.env.get_db_cnx()
        cursor = db.cursor()
        if grabAllFieldsFromDB:
            cursor.execute("SELECT sid, name, value FROM session_attribute "
                           "WHERE sid in ('%s') ORDER BY sid" %
                           ("','".join(userProfile_ids)))
        else:
            cursor.execute(
                "SELECT sid, name, value FROM session_attribute "
                "WHERE sid in ('%s') and name in ('%s') ORDER BY sid" %
                ("','".join(userProfile_ids), "','".join(UserProfile())))
        _newUserProfile = UserProfile(-1, self)
        _fieldsFromDb = []
        for sid, name, value in cursor:
            if _newUserProfile.id != sid:
                if _newUserProfile.id != -1:
                    _newUserProfile.store = self
                    _newUserProfile.exists = True
                    object.__setattr__(_newUserProfile, '_fieldsFromDb',
                                       _fieldsFromDb)
                    yield _newUserProfile
                    _newUserProfile = UserProfile(0, self)
                    _fieldsFromDb = []
                _newUserProfile.id = sid
            _newUserProfile[name] = value
            _fieldsFromDb.append(name)

        # last _newUserProfile
        if _newUserProfile.id != -1:
            _newUserProfile.store = self
            _newUserProfile.exists = True
            object.__setattr__(_newUserProfile, '_fieldsFromDb', _fieldsFromDb)
            yield _newUserProfile