Example #1
0
File: site.py Project: jness/dmirr
    def assign_project(self, site_id, *a, **kw):
        errors = _h.get_validation_errors()
        s = DBSession.query(Site).filter_by(id=site_id).first()
        p = DBSession.query(Project).filter_by(id=kw.get('project_id', None))\
            .first()
        all_p = DBSession.query(Project).all()
        
        _h.protect_obj(s)
        _h.protect_obj(p)

        if not s:
            raise HTTPNotFound
        if not p:
            raise HTTPNotFound    
        
        all_projects = [x for x in all_p if x not in s.projects]
        
        if errors:
            transaction.doom()
            return dict(errors=errors, site=s, all_projects=all_projects)

        _s_label = s.label
        s.projects.append(p)

        if kw.get('sync_path', None):
            self._add_site_sync_path(s.id, p.id, kw['sync_path'])
        else:
            transaction.doom()
            flash(_('Site sync path required for each project.'), 'warning')
            redirect(url("/site/%s/edit#mirrored_projects" % _s_label))

        transaction.commit()    
        redirect(url("/site/%s/edit#projects" % _s_label))
Example #2
0
 def post(self, *a, **kw):
     errors = _h.get_validation_errors()
     group = _h.get_group_by_name(kw.get('group_name', None))
     protocol = _h.get_protocol_by_name(kw.get('sync_protocol', None))
     all_protocols = DBSession.query(SyncProtocol).all()
     
     if not group:
         errors['group'] = 'Group does not exist!'
     if not protocol:
         errors['sync_protocol'] = 'Sync Protocol does not exist!'
         
     p = Project()
     p.label = unicode(re.sub(' ', '_', kw['label']).lower())
     _label = p.label
     p.display_name = unicode(kw.get('display_name', None))
     p.desc = kw.get('desc', None)
     p.url = unicode(kw.get('url', None))
     p.user = request.identity['user']
     p.sync_base_path = unicode(kw.get('sync_base_path', None))
     p.sync_flags = unicode(kw.get('sync_flags', None))
     p.group = group
     p.sync_protocol = protocol
     
     if len(errors) > 0:
         transaction.doom()
         return dict(page="project", errors=errors, project=p,
                     all_protocols=all_protocols)
     DBSession.add(p)
     transaction.commit()
     flash(_("%s created successfully!" % kw['display_name']), 'info')
     redirect(url('/project/%s/edit' % _label))
Example #3
0
File: site.py Project: jness/dmirr
 def put(self, site_label=None, *a, **kw):
     errors = _h.get_validation_errors()
     s = DBSession.query(Site).filter_by(label=site_label).first()
     group = _h.get_group_by_name(kw.get('group_name', None))
     all_p = DBSession.query(Project).all()
     _h.protect_obj(s)
     
     if not s:
         raise HTTPNotFound         
     if not group:
         errors['group'] = 'Group does not exist!'
         
     s.label = unicode(re.sub(' ', '_', kw['label']).lower())
     s.display_name = unicode(kw.get('display_name', None))
     s.desc = kw.get('desc', None)
     s.url = unicode(kw.get('url', None))
     s.contact_name = unicode(kw.get('contact_name', None))
     s.contact_email = unicode(kw.get('contact_email', None))
     s.sync_base_path = unicode(kw.get('sync_base_path', None))
     s.user = request.identity['user']
     s.group = group
 
     if len(errors) > 0:
         all_projects = [x for x in all_p if x not in s.projects]
         all_hosts = [x for x in request.identity['user'].hosts \
                         if x not in s.hosts]
         transaction.doom()
         return dict(page='site', errors=errors, site=s,
                     all_projects=all_projects, all_hosts=all_hosts)
         
     transaction.commit()
     flash(_("%s updated successfully!" % kw['display_name']), 'info')
     redirect(url('/site/%s/edit' % kw['label']))
Example #4
0
 def post(self, *a, **kw):
     errors = _h.get_validation_errors()
     project = _h.get_project_by_name(kw.get('project_label', None))
     if not project:
         errors['project'] = "Project does not exist"
     
     _h.protect_obj_modify(project)
         
     _existing_p = _h.get_product_by_name(kw.get('label', None))
     if _existing_p:
         errors['label'] = "%s already exists!" % kw.get('label', None)
         
     p = Product()
     p.label = unicode(re.sub(' ', '_', kw['label']).lower())
     p.display_name = unicode(kw.get('display_name', None))
     p.desc = kw.get('desc', None)
     
     if len(errors) > 0:
         return dict(errors=errors, project=project, product=p)
         
     p.project = project
     
     DBSession.add(p)
     transaction.commit()
     flash(_("%s created successfully!" % kw['display_name']), 'info')
     redirect(url('/product/new?project=%s' % kw['project_label']))
Example #5
0
    def put(self, project_id=None, *a, **kw):
        errors = _h.get_validation_errors()
        p = DBSession.query(Project).filter_by(id=project_id).first()
        if not p:
            raise HTTPNotFound
        if kw['label'] != p.label:
            other_p = DBSession.query(Project).filter_by(label=kw['label'])\
                      .first()
            if other_p:
                errors['label'] = "%s already exists, use another label." % \
                    other_p.label
        group = _h.get_group_by_name(kw.get('group_name', None))
        protocol = _h.get_protocol_by_name(kw.get('sync_protocol', None))
        all_protocols = DBSession.query(SyncProtocol).all()

        _h.protect_obj_modify(p)
        
        p.display_name = unicode(kw['display_name'])
        p.desc = kw['desc']
        p.url = unicode(kw['url'])
        p.sync_base_path = unicode(kw.get('sync_base_path', None))
        p.sync_flags = unicode(kw.get('sync_flags', None))
        p.sync_protocol = protocol
        p.group = group
        
        if len(errors) > 0:
            transaction.doom()
            return dict(errors=errors, project=p, all_protocols=all_protocols)

        p.label = unicode(re.sub(' ', '_', kw['label']).lower())
        _label = p.label
        transaction.commit()
        flash(_("%s updated successfully!" % kw['display_name']), 'info')
        redirect(url('/project/%s/edit' % _label))
Example #6
0
    def put(self, product_label=None, *a, **kw):
        p = DBSession.query(Product).filter_by(label=product_label).first()
        project = p.project
        _project_label = project.label    
        
        if not p:
            raise HTTPNotFound
        if not project:
            raise HTTPNotFound
        
        _h.protect_obj_modify(project)
        _h.protect_obj_modify(p.project)
        
        errors = _h.get_validation_errors()
        
        if kw.get('label', None) != p.label:
            _existing_p = _h.get_product_by_name(kw.get('label', None))
            if _existing_p:
                errors['label'] = "%s already exists!" % kw.get('label', None)
            
        p.label = unicode(re.sub(' ', '_', kw['label']).lower())
        p.display_name = unicode(kw['display_name'])
        p.desc = kw['desc']
        p.project = project
                    
        if errors:
            transaction.doom()
            return dict(project=p.project, errors=errors, product=p)

        transaction.commit()
        flash(_("%s updated successfully!" % kw['display_name']), 'info')
        redirect(url("/project/%s/edit#products" % _project_label))
Example #7
0
File: host.py Project: jness/dmirr
    def put(self, host_id=None, *a, **kw):
        h = DBSession.query(Host).filter_by(id=host_id).first()
        if not h:
            raise HTTPNotFound
            
        errors  = _h.get_validation_errors()
        h.user  = request.identity['user']
        h.group = _h.get_group_by_name(kw.get('group_name', None))
        h.address = unicode(kw['address'].strip())
        h.online_status = DBSession.query(Status)\
                          .filter_by(label='Offline').first()
                          
        res = self._get_geoip_data(h.address)
        if not res:
            errors['host_address'] = "The host '%s' could not be " + \
                                     "identified via GeoIP.  Please " + \
                                     "ensure the hostname resolves" % h.address
        if errors:
            transaction.doom()
            return dict(errors=errors, host=h)

        h.city = unicode(res.get('city', None))
        h.region_name   = unicode(res.get('region_name', None))
        h.longitude     = res.get('longitude', None)
        h.latitude      = res.get('latitude', None)
        h.country_name  = unicode(res.get('country_name', None))
        h.country_code  = unicode(res.get('country_code', None))
        h.country_code3 = unicode(res.get('country_code3', None))
        h.postal_code   = res.get('postal_code', None)
        flash(_("%s updated successfully!" % kw['address']), 'info')
        redirect(url('/dashboard'))
Example #8
0
File: user.py Project: jness/dmirr
 def process_new_form_errors(self, *args, **kw):
     if pylons.request.response_type == 'application/json':
         kw['errors'] = pylons.tmpl_context.form_errors
         return dict(kw)
     else:
         errors = _h.get_validation_errors()
         tmpl_context.form = create_user_form
         return dict(page='user', page_title='New User Registration', 
                     errors=errors, terms_of_use=TERMS_OF_USE)
Example #9
0
File: user.py Project: jness/dmirr
 def new(self, *a, **kw):
     if config['user_registration'] == 'closed':
         flash(_('User registration is currently closed'), 'warning')
         redirect(url('/'))
         
     errors = _h.get_validation_errors()
     tmpl_context.form = create_user_form
     return dict(page='user', page_title='New User Registration', 
                 errors=errors, terms_of_use=TERMS_OF_USE)
Example #10
0
File: user.py Project: jness/dmirr
 def edit(self, user_name=None, **kw):
     user = db.query(model.User).filter_by(user_name=user_name).first()
     if not user:
         raise HTTPNotFound
     
     _h.protect_user_obj(user)
         
     errors = _h.get_validation_errors()
     tmpl_context.form = edit_user_form
     return dict(page='user', page_title='Edit Account Settings', 
                 errors=errors, user=user)
Example #11
0
File: root.py Project: jness/dmirr
    def login(self, came_from=url('/')):
        """Start the user login."""
        if config['user_registration'] == 'closed':
            flash(_('User registration is currently closed'), 'warning')
            
        errors = _h.get_validation_errors()
        tmpl_context.form = create_user_form
        terms_of_use=open(config['terms_of_use_file']).read()

        login_counter = request.environ['repoze.who.logins']
        if login_counter > 0:
            flash(_('Wrong credentials'), 'warning')
        return dict(page='user', login_counter=str(login_counter),
                    page_title='New User Registration', came_from=came_from,
                    errors=errors, terms_of_use=terms_of_use)
Example #12
0
    def put(self, release_id=None, *a, **kw):
        errors = _h.get_validation_errors()
        r = DBSession.query(ProductRelease)\
            .filter_by(id=release_id)\
            .first()
        product = r.product
        allarchs = DBSession.query(Arch).all()
        _project_label = r.product.project.label
        
        if not r:
            raise HTTPNotFound
        
        _h.protect_obj_modify(r.product.project)
        _h.protect_obj_modify(product.project)
            
        r.label = unicode(re.sub(' ', '_', kw['label']).lower())
        r.display_name = unicode(kw.get('display_name', None))
        r.desc = kw.get('desc', None)
        r.path = unicode(kw.get('path', ''))
        r.product = product
        
        if kw.get('label') != r.label:
            existing_r = _h.get_release_by_name(kw.get('label', None))
            if _existing_r:
                errors['label'] = "%s already exists!" % kw.get('label', None)
    
        if not kw.get('archs'):
            errors['archs'] = "Must select atleast one arch"
        else:
            for a in allarchs:
                if _(a.id) in kw['archs']:
                    r.archs.append(a)
                else:
                    if a in r.archs:
                        r.archs.remove(a)
                
        if len(errors) > 0:
            transaction.doom()
            return dict(errors=errors, project=r.product.project, 
                        all_archs=allarchs, release=r)

        transaction.commit()
        flash(_("%s updated successfully!" % kw['display_name']), 'info')
        redirect(url('/project/%s/edit#products' % _project_label))
Example #13
0
 def post(self, *a, **kw):
     errors = _h.get_validation_errors()
     product = _h.get_product_by_name(kw.get('product_label', None))
     allarchs = DBSession.query(Arch).all()
     if not product:
         raise HTTPNotFound
     _product_label = product.label
     
     _h.protect_obj_modify(product.project)
     
     r = ProductRelease()
     
     _existing_r = _h.get_release_by_name(kw.get('label', None))
     if _existing_r:
         errors['label'] = "%s already exists!" % kw.get('label', None)
     
     if len(errors) > 0:
         transaction.doom()
         return dict(errors=errors, project=product.project, 
                     all_archs=allarchs, product=product, release=r)
     
     r.product = product
     r.label = unicode(re.sub(' ', '_', kw['label']).lower())
     r.display_name = unicode(kw.get('display_name', None))
     r.desc = kw.get('desc', None)
     r.path = unicode(kw.get('path', ''))
         
     if not kw.get('archs'):
         errors['archs'] = "Must select atleast one arch"
     else:
         for a in allarchs:
             if _(a.id) in kw['archs']:
                 r.archs.append(a)
             else:
                 if a in r.archs:
                     r.archs.remove(a)
                     
     # FIX ME: Add check to make sure the rsync path is valid
     
     DBSession.add(r)
     transaction.commit()
     flash(_("%s created successfully!" % kw['display_name']), 'info')
     redirect(url('/product_release/new?product=%s' % _product_label))
Example #14
0
File: site.py Project: jness/dmirr
    def assign_host(self, site_id, *a, **kw):
        errors = _h.get_validation_errors()
        s = DBSession.query(Site).filter_by(id=site_id).first()
        h = DBSession.query(Host).filter_by(id=kw.get('host_id', None)).first()
        
        _h.protect_obj(s)
        _h.protect_obj(h)

        if not s:
            raise HTTPNotFound
        if not h:
            raise HTTPNotFound    
        
        if errors:
            return dict(errors=errors, site=s)
            
        _s_label = s.label
        s.hosts.append(h)
        transaction.commit()
        redirect(url("/site/%s/edit#downstream_mirrors" % _s_label))
Example #15
0
    def assign_host(self, project_id, *a, **kw):
        errors = _h.get_validation_errors()
        p = DBSession.query(Project).filter_by(id=project_id).first()
        h = DBSession.query(Host).filter_by(id=kw.get('host_id', None)).first()
        
        _h.protect_obj(p)
        _h.protect_obj(h)

        if not p:
            raise HTTPNotFound
        if not h:
            raise HTTPNotFound    
        
        if errors:
            return dict(errors=errors, project=p)
            
        _p_label = p.label
        p.hosts.append(h)
        transaction.commit()
        redirect(url("/project/%s/edit#upstream_mirrors" % _p_label))
Example #16
0
File: user.py Project: jness/dmirr
 def post(self, **kw):
     if config['user_registration'] == 'closed':
         abort(500)
         
     errors = _h.get_validation_errors()
                   
     u = model.User()
     u.user_name = unicode(re.sub(' ', '_', kw['user_name']).lower())
     u.display_name = unicode(kw['display_name'])
     u.web_url = unicode(kw['web_url'])
     u.email_address = unicode(kw['email_address'])
     u.about = kw['about']
     u.agreed_to_terms = int(1)
     u.status = _h.status_by_name('PendingEmailVerification')
     u.password = kw['password']
     
     # add to the everyone group
     everyone = _h.group_by_name('dmirr_everyone')
     everyone.users.append(u)     
     
     msg = turbomail.Message(
         config['from_email'],
         u.email_address,
         "dMirr Email Verification"
         )
     u.verify_code = _h.gen_verification_code()
     _url = "%s/user/true_up?u=%s&vc=%s" % (config['base_url'], 
                                           u.user_name, u.verify_code)
     msg.plain = EMAIL_VERIFICATION_MSG % \
                 (u.display_name, _url, config['base_url'])
     
     db.add(u)
     transaction.commit()
     msg.send()
     flash(_('%s registration started, check email to complete.' \
             % kw['display_name']), 'info')
     redirect(url('/'))
Example #17
0
File: host.py Project: jness/dmirr
    def post(self, *a, **kw):
        h = _h.get_host_by_address(kw.get('address', None))
        errors  = _h.get_validation_errors()
        if h:
            errors['address'] = "Host %s already exists!" % h.address

        h = Host()            
        group = _h.get_group_by_name(kw.get('group_name', None))
        
        h.address = unicode(kw['address'].strip())
        h.user = request.identity['user']
        h.group = group
        
        res = self._get_geoip_data(h.address)
        if not res:
            errors['host_address'] = "The host '%s' could " % h.address + \
                                     "not be identified via GeoIP. " + \
                                     "Please ensure the hostname resolves" 
                    
        if errors:
            transaction.doom()
            return dict(errors=errors, host=h)
        
        _h.protect_obj(h)
        h.online_status = DBSession.query(Status)\
                          .filter_by(label='Offline').first()
        h.city = unicode(res.get('city', None))
        h.region_name   = unicode(res.get('region_name', None))
        h.longitude     = res.get('longitude', None)
        h.latitude      = res.get('latitude', None)
        h.country_name  = unicode(res.get('country_name', None))
        h.country_code  = unicode(res.get('country_code', None))
        h.country_code3 = unicode(res.get('country_code3', None))
        h.postal_code   = res.get('postal_code', None)
            
        flash(_("%s created successfully!" % kw['address']), 'info')
        redirect(url('/host/new'))
Example #18
0
File: user.py Project: jness/dmirr
    def true_up(self, **kw):
        errors = _h.get_validation_errors()
        u = db.query(model.User).filter_by(user_name=kw['u'])\
            .filter_by(verify_code=kw['vc']).first()

        if not u:
            flash(_('%s was not found or invalid code!' % kw['u']), 'warning')
            redirect(url('/login'))

        u.status = _h.status_by_name('Enabled')
        flash(_('%s successfully verified! You can now login!' % u.email_address), 'info')

        # the email           
        msg = turbomail.Message(
            config['from_email'],
            u.email_address,
            "Welcome To dMirr"
            )
        msg.plain = WELCOME_MSG % (u.display_name, u.user_name, config['base_url'])

        transaction.commit()
        msg.send()

        redirect(url('/login'))