Ticket #3030: no_space_names.patch

File no_space_names.patch, 11.5 kB (added by s0undt3ch, 4 months ago)

removed a print I left lying arround

  • tracforge/linker/auth.py

    old new  
    1313 
    1414class TracForgeLoginModule(LoginModule): 
    1515    """Replacement for LoginModule to slave to another environment.""" 
    16      
     16 
    1717    master_path = Option('tracforge', 'master_path', 
    1818                         doc='Path to master Trac') 
    1919 
    2020    master_env = property(lambda self: open_environment(self.master_path, use_cache=True)) 
    2121    master_href = property(lambda self: Href(self.master_env.base_url)) 
    22              
     22 
    2323    # INavigationContributor methods 
    2424    def get_active_navigation_item(self, req): 
    2525        return 'login' 
     
    3232        else: 
    3333            yield ('metanav', 'login', 
    3434                   html.A('Login', href=self.master_href.login())) 
    35                     
     35 
    3636    # IRequestHandler methods 
    3737    def process_request(self, req): 
    3838        if req.path_info.startswith('/login'): 
     
    4949        return LoginModule(self.master_env)._get_name_for_cookie(req, cookie) 
    5050 
    5151class TracForgeCookieMunger(Component): 
    52      
     52 
    5353    uri_root = Option('tracforge', 'uri_root', default='/', 
    5454                      doc='The smallest common URI for the whole TracForge setup') 
    55                        
     55 
    5656    implements(IRequestFilter) 
    5757 
    5858    def pre_process_request(self, req, handler): 
     
    7373                    if parts[2].startswith(self.uri_root) and (not parts[1] or parts[1] == req.server_name): 
    7474                        Request.redirect(req, referer) 
    7575 
    76                 old_redirect(req, *args, **kwords) 
    77              
     76                old_redirect(*args, **kwords) 
     77 
    7878            req.redirect = my_redirect 
    79              
     79 
    8080        return handler 
    81          
     81 
    8282    def post_process_request(self, req, template, content_type): 
    8383        return (template, content_type) 
    8484 
  • tracforge/admin/admin.py

    old new  
    11# Created by Noah Kantrowitz on 2008-02-19. 
    22# Copyright (c) 2008 Noah Kantrowitz. All rights reserved. 
     3import re 
    34import os 
    45import os.path 
    56 
     
    1920                           doc='Path to the tracforge-helper script, possibly' 
    2021                               'utilizing sudo or similar wrappers.') 
    2122 
    22     implements(IAdminPanelProvider)     
    23      
     23    implements(IAdminPanelProvider) 
     24 
    2425    # IAdminPageProvider methods 
    2526    def get_admin_panels(self, req): 
    2627        if req.perm.has_permission('TRACFORGE_ADMIN'): 
    2728            yield ('tracforge', 'TracForge', 'admin', 'Project Admin') 
    28              
     29 
    2930    def render_admin_panel(self, req, cat, page, path_info): 
    3031        if path_info: 
    3132            return self._render_project_view(req, cat, page, path_info) 
    32          
     33 
    3334        data = {} 
    34          
     35 
    3536        if req.method == 'POST': 
    3637            if 'create' in req.args.keys(): # Project creation 
    3738                name = req.args.get('shortname', '').strip() 
     39                if re.search(r'[^\w]', name): 
     40                    raise TracError('Invalid project short name "%s". Should ' 
     41                                    ' only contain chars in [a-zA-Z0-9_]' % \ 
     42                                    name) 
    3843                full_name = req.args.get('fullname', '').strip() 
    3944                proto_name = req.args.get('prototype', '').strip() 
    4045                if not (name and full_name and proto_name): 
    4146                    raise TracError('All arguments are required') 
    42                  
     47 
    4348                # Make the models 
    4449                proto = Prototype(self.env, proto_name) 
    4550                if not proto.exists: 
    4651                    raise TracError('Penguins on fire') 
    47                  
     52 
    4853                # Use $PATH on non-Win32 
    4954                if os.name == 'nt': 
    5055                    spawn = os.spawnv 
    5156                else: 
    5257                    spawn = os.spawnvp 
    53                  
     58 
    5459                # Spawn the helper script 
    5560                helper = self.helper_script.split() 
    5661                helper += [self.env.path, proto_name, name, full_name] 
    5762                helper.insert(1, os.path.basename(helper[0])) 
    5863                spawn(os.P_NOWAIT, helper.pop(0), helper) 
    59                  
     64 
    6065                # Redirect to the watcher page 
    6166                req.redirect(req.href.admin(cat, page, name)) 
    6267            elif 'delete' in req.args.keys(): # Project deleteion 
    6368                raise TracError, 'Not implemented yet. Sorry.' 
    64          
     69 
    6570        data['projects'] = sorted([Project(self.env, n) for n in Project.select(self.env)], key=lambda p: p.name) 
    6671        data['prototypes'] = Prototype.select(self.env) 
    6772        data['env_base_path'] = os.path.join(os.path.dirname(self.env.path), '') 
    68          
     73 
    6974        add_script(req, 'tracforge/js/typewatch1.1.js') 
    7075        return 'admin_tracforge_projects.html', data 
    7176 
     
    7580            'actions': [], 
    7681        } 
    7782        action_map = {} 
    78          
     83 
    7984        db = self.env.get_db_cnx() 
    8085        cursor = db.cursor() 
    81          
     86 
    8287        cursor.execute('SELECT action, step_direction, args, return FROM tracforge_project_log WHERE project=%s ORDER BY step', (data['project'],)) 
    8388        for action, step_direction, args, rv in cursor: 
    8489            d = { 
     
    9095            } 
    9196            data['actions'].append(d) 
    9297            action_map[action,step_direction] = d 
    93          
     98 
    9499        cursor.execute('SELECT ts, action, step_direction, stream, data FROM tracforge_project_output WHERE project=%s ORDER BY ts, stream DESC', (data['project'],)) 
    95100        for ts, action, step_direction, stream, msg in cursor: 
    96101            ts = float(ts) 
    97102            output = action_map[action, step_direction]['output'] 
    98103            if output and abs(output[-1][0] - ts) <= 1e-2 and output[-1][1] == stream: 
    99104                output[-1] = (output[-1][0], output[-1][1], output[-1][2]+msg) 
    100             else:  
     105            else: 
    101106                output.append((float(ts), stream, msg)) 
    102          
     107 
    103108        return 'admin_tracforge_project.html', data 
  • tracforge/admin/prototypes_admin.py

    old new  
    11# TracForge prototype admin panel 
     2import re 
    23import itertools 
    34 
    45from trac.core import * 
     
    1415    #setup_participants = ExtensionPoint(IProjectSetupParticipant) 
    1516 
    1617    implements(IAdminPanelProvider) 
    17      
     18 
    1819    def get_admin_panels(self, req): 
    1920        if 'TRACFORGE_ADMIN' in req.perm: 
    2021            yield 'tracforge', 'TracForge', 'prototypes', 'Project Prototypes' 
    2122            #yield 'tracforge', 'TracForge', 'configset', 'Configset Management' 
    22              
     23 
    2324    def render_admin_panel(self, req, cat, page, path_info): 
    2425        data = {} 
    25          
     26 
    2627        # General stuff 
    2728        add_stylesheet(req, 'tracforge/css/admin.css') 
    2829 
     
    3233                return self._show_prototype(req, path_info, action='new') 
    3334            else: 
    3435                return self._show_prototype(req, path_info, action='edit') 
    35          
     36 
    3637        data['prototypes'] = Prototype.select(self.env) 
    3738        return 'admin_tracforge_prototypes.html', data 
    38          
     39 
    3940    def process_configset_admin_request(self, req, cat, page, path_info): 
    4041        tags = ['*'] + list(ConfigSet.select(self.env)) 
    4142        configs = {} 
     
    5152                key = req.args.get('key') 
    5253                value = req.args.get('value') 
    5354                action = req.args.get('action') 
    54              
     55 
    5556                # Input validation 
    5657                if not (tag and section and key and action): 
    5758                    raise TracError('Not all values given') 
     
    5960                    raise TracError('Invalid action %s'%action) 
    6061                if '/' in tag or '/' in section or '/' in key: 
    6162                    raise TracError("You cannot use '/' in a tag, section, or key") 
    62              
     63 
    6364                config = ConfigSet(self.env, tag=tag, with_star=False) 
    6465                config.set(section, key, value, action) 
    6566                config.save() 
     
    7374                    for s,k in x: 
    7475                        config.remove(s,k) 
    7576                    config.save() 
    76              
     77 
    7778            req.redirect(req.href.admin(cat, page, path_info)) 
    7879 
    79         req.hdf['tracforge.tags'] = tags             
     80        req.hdf['tracforge.tags'] = tags 
    8081        #for t in tags: # Force ordering so * is first 
    8182        #    req.hdf['tracforge.tags.'+t] = configs[t] 
    8283        req.hdf['tracforge.configs'] = configs 
    8384 
    84         return 'admin_tracforge_configset.cs', None        
     85        return 'admin_tracforge_configset.cs', None 
    8586 
    8687    def _show_prototype(self, req, path_info, action): 
    8788        """Handler for creating a new prototype.""" 
     
    8990            'name': path_info, 
    9091            'action': action, 
    9192        } 
    92          
     93 
    9394        proto = None 
    9495        if req.method == 'POST': 
    9596            proto = Prototype(self.env, '') 
    96              
     97 
    9798            for i in itertools.count(): 
    9899                a = req.args.get('step-%s'%i) 
    99100                if a is not None: 
    100101                    proto.append((a, req.args['args-%s'%a])) 
    101102                else: 
    102103                    break 
    103              
     104 
    104105            if 'movedown' in req.args: 
    105106                i = int(req.args['movedown']) 
    106107                x = proto.pop(i) 
     
    118119                proto.tag = (action == 'new' and req.args['name'] or data['name']).strip() 
    119120                if not proto.tag or proto.tag == 'new': 
    120121                    raise TracError('Invalid prototype name "%s"', proto.tag) 
     122                elif re.search(r'[^\w]', proto.tag): 
     123                    raise TracError('Invalid prototype name "%s" should ' 
     124                                    ' only contain chars in [a-zA-Z0-9_]' % \ 
     125                                    proto.tag) 
    121126                proto.save() 
    122127                req.redirect(req.href.admin('tracforge/prototypes', proto.tag)) 
    123128            elif 'cancel' in req.args: 
     
    126131                proto.tag =  data['name'] 
    127132                proto.delete() 
    128133                req.redirect(req.href.admin('tracforge/prototypes')) 
    129              
     134 
    130135            # Try to figure out the name 
    131136            if action == 'new': 
    132137                proto.tag = req.args['name'] 
    133138            else: 
    134139                proto.tag = '(modified) %s'%data['name'] 
    135              
    136              
     140 
     141 
    137142        #steps = {} 
    138143        #for p in self.setup_participants: 
    139144        #    for a in p.get_setup_actions(): 
     
    142147        #            'description': p.get_setup_action_description(a), 
    143148        #        } 
    144149        data['steps'] = TracForgeAdminSystem(self.env).get_project_setup_participants() 
    145          
    146         if action == 'new': # For a new one, use the specified defaults  
     150 
     151        if action == 'new': # For a new one, use the specified defaults 
    147152            if proto is None: 
    148153                proto = Prototype.default(self.env) # XXX: This should really read from trac.ini somehow 
    149         elif action == 'edit':  
     154        elif action == 'edit': 
    150155            if proto is None: 
    151156                proto = Prototype(self.env, data['name']) 
    152157                if not proto.exists: 
     
    154159        else: 
    155160            raise TracError('Invalid action %s'%action) 
    156161        data['proto'] = proto 
    157          
     162 
    158163        add_stylesheet(req, 'tracforge/css/prototypes_new.css') 
    159164        #add_script(req, 'tracforge/js/interface/iutil.js') 
    160165        #add_script(req, 'tracforge/js/jquery.animatedswap.js')