Ejemplo n.º 1
0
 def get_resource_by_id(cls, resource_full_id):
     """
     * resource_full_id: fully qualified resource id in format
     "product:ticket:123". In case of global environment it is ":ticket:123"
     """
     nbhprefix, realm, resource_id = cls.split_full_id(resource_full_id)
     if nbhprefix:
         neighborhood = Neighborhood('product', nbhprefix)
         return neighborhood.child(realm, id=resource_id)
     else:
         return Resource(realm, id=resource_id)
Ejemplo n.º 2
0
 def __init__(self, env, username=None, resource=None, cache=None,
              groups=None):
     if resource and resource.neighborhood is not None:
         env = manager_for_neighborhood(env, resource.neighborhood)
         resource = Neighborhood(None, None).child(resource)
     self.env = env
     self.username = username or 'anonymous'
     self._resource = resource
     if cache is None:
         cache = {}
     self._cache = cache
Ejemplo n.º 3
0
 def get_product_list(cls, env, req, href_fcn=None):
     """Returns a list of products as (prefix, name, url) tuples
     """
     if href_fcn is None:
         href_fcn = req.href.products
     product_list = []
     for product in Product.select(env):
         if 'PRODUCT_VIEW' in req.perm(
                 Neighborhood('product',
                              product.prefix).child(product.resource)):
             product_list.append(
                 (product.prefix, product.name, href_fcn(product.prefix)))
     return product_list
Ejemplo n.º 4
0
    def render_widget(self, name, context, options):
        """Gather product list and render data in compact view
        """
        data = {}
        req = context.req
        title = ''
        params = ('max', 'cols')
        max_, cols = self.bind_params(name, options, *params)

        if not isinstance(req.perm.env, ProductEnvironment):
            for p in Product.select(self.env):
                if 'PRODUCT_VIEW' in req.perm(Neighborhood(
                        'product', p.prefix)):
                    for resource in (
                        {
                            'type': Milestone,
                            'name': 'milestone',
                            'hrefurl': True
                        },
                        {
                            'type': Component,
                            'name': 'component'
                        },
                        {
                            'type': Version,
                            'name': 'version'
                        },
                    ):
                        setattr(p, resource['name'] + 's',
                                self._get_product_info(p, resource, max_))
                    p.owner_link = Query.from_string(
                        self.env, 'status!=closed&'
                        'col=id&col=summary&col=owner&col=status&col=priority&'
                        'order=priority&group=product&owner=%s' %
                        (p._data['owner'] or '', )).get_href(req.href)
                    data.setdefault('product_list', []).append(p)
            title = _('Products')

        data['colseq'] = itertools.cycle(xrange(cols - 1, -1, -1)) if cols \
                         else itertools.repeat(1)

        return 'widget_product.html', \
            {
                'title': title,
                'data': data,
                'ctxtnav' : [
                    tag.a(_('More'),
                    href = context.req.href('products'))],
            }, \
            context
Ejemplo n.º 5
0
 def _render_list(self, req):
     """products list"""
     products = [
         p for p in Product.select(self.env)
         if 'PRODUCT_VIEW' in req.perm(Neighborhood('product', p.prefix))
     ]
     map(
         lambda p: setattr(
             p, 'href',
             resolve_product_href(lookup_product_env(self.env, p.prefix),
                                  self.env)), products)
     data = {
         'products': products,
         'context': web_context(req, Resource('product', None))
     }
     return 'product_list.html', data, None
Ejemplo n.º 6
0
        """Forward new ticket request to `trac.ticket.web_ui.TicketModule`
        but return plain text suitable for AJAX requests.
        """
        try:
            tm = self._get_ticket_module()
            req.perm.require('TICKET_CREATE')
            summary = req.args.pop('field_summary', '')
            desc = ""
            attrs = dict([k[6:], v] for k, v in req.args.iteritems()
                         if k.startswith('field_'))
            product, tid = self.create(req, summary, desc, attrs, True)
        except Exception, exc:
            self.log.exception("BH: Quick create ticket failed %s" % (exc,))
            req.send(str(exc), 'plain/text', 500)
        else:
            tres = Neighborhood('product', product)('ticket', tid)
            href = req.href
            req.send(to_json({'product': product, 'id': tid,
                              'url': get_resource_url(self.env, tres, href)}),
                     'application/json')

    def _get_ticket_module(self):
        ptm = None
        if ProductTicketModule is not None:
            ptm = self.env[ProductTicketModule]
        tm = self.env[TicketModule]
        if not (tm is None) ^ (ptm is None):
            raise TracError('Unable to load TicketModule (disabled)?')
        if tm is None:
            tm = ptm
        return tm
Ejemplo n.º 7
0
 def setUp(self):
     ProductPermissionCacheTestCase.setUp(self)
     nbh = Neighborhood('product', self.default_product)
     resource = nbh.child(None, None)
     self.perm = perm.PermissionCache(self.global_env, 'testuser', resource)
Ejemplo n.º 8
0
 def setUp(self):
     ProductPermissionCacheTestCase.setUp(self)
     nbh = Neighborhood('product', self.default_product)
     resource = nbh.child(None, None)
     self.perm = perm.PermissionCache(self.global_env, 'testuser', resource)