Exemplo n.º 1
0
    def _validate(self, input):
        """Make sure all the aliases are valid for the field's pillar.

        An alias is valid if it can be used as the name of a pillar and is
        not identical to the pillar's existing name.
        """
        context = self.context
        from lp.registry.interfaces.product import IProduct
        from lp.registry.interfaces.projectgroup import IProjectGroup
        from lp.registry.interfaces.distribution import IDistribution
        if IProduct.providedBy(context):
            name_field = IProduct['name']
        elif IProjectGroup.providedBy(context):
            name_field = IProjectGroup['name']
        elif IDistribution.providedBy(context):
            name_field = IDistribution['name']
        else:
            raise AssertionError("Unexpected context type.")
        name_field.bind(context)
        existing_aliases = context.aliases
        for name in self._split_input(input):
            if name == context.name:
                raise LaunchpadValidationError('This is your name: %s' % name)
            elif name in existing_aliases:
                # This is already an alias to this pillar, so there's no need
                # to validate it.
                pass
            else:
                name_field._validate(name)
Exemplo n.º 2
0
    def getBranchSharingPolicies(self, pillar):
        """See `ISharingService`."""
        # Only Products have branch sharing policies. Distributions just
        # default to Public.
        # If the branch sharing policy is EMBARGOED_OR_PROPRIETARY, then we
        # do not allow any other policies.
        allowed_policies = [BranchSharingPolicy.PUBLIC]
        # Commercial projects also allow proprietary branches.
        if (IProduct.providedBy(pillar)
            and pillar.has_current_commercial_subscription):

            if pillar.private:
                allowed_policies = [
                    BranchSharingPolicy.EMBARGOED_OR_PROPRIETARY,
                    BranchSharingPolicy.PROPRIETARY,
                ]
            else:
                allowed_policies = [
                    BranchSharingPolicy.PUBLIC,
                    BranchSharingPolicy.PUBLIC_OR_PROPRIETARY,
                    BranchSharingPolicy.PROPRIETARY_OR_PUBLIC,
                    BranchSharingPolicy.PROPRIETARY,
                ]

        if (pillar.branch_sharing_policy and
            not pillar.branch_sharing_policy in allowed_policies):
            allowed_policies.append(pillar.branch_sharing_policy)

        return self._makeEnumData(allowed_policies)
Exemplo n.º 3
0
 def can_configure_answers(self):
     """Can the user configure answers for the `IQuestionTarget`."""
     target = self.context
     if IProduct.providedBy(target) or IDistribution.providedBy(target):
         return check_permission("launchpad.Edit", self.context)
     else:
         return False
Exemplo n.º 4
0
    def _getPublicRevisionsHelper(obj, day_limit):
        """Helper method for Products and ProjectGroups."""
        # Here to stop circular imports.
        from lp.code.model.branch import Branch
        from lp.registry.model.product import Product
        from lp.code.model.branchrevision import BranchRevision

        origin = [
            Revision,
            Join(BranchRevision, BranchRevision.revision == Revision.id),
            Join(Branch, BranchRevision.branch == Branch.id),
            ]

        conditions = And(
            revision_time_limit(day_limit),
            Branch.information_type.is_in(PUBLIC_INFORMATION_TYPES))

        if IProduct.providedBy(obj):
            conditions = And(conditions, Branch.product == obj)
        elif IProjectGroup.providedBy(obj):
            origin.append(Join(Product, Branch.product == Product.id))
            conditions = And(conditions, Product.project == obj)
        else:
            raise AssertionError(
                "Not an IProduct or IProjectGroup: %r" % obj)

        result_set = Store.of(obj).using(*origin).find(
            Revision, conditions)
        result_set.config(distinct=True)
        return result_set.order_by(Desc(Revision.revision_date))
Exemplo n.º 5
0
    def announce(self, user, title, summary=None, url=None,
                 publication_date=None):
        """See IHasAnnouncements."""

        # We establish the appropriate target property.
        project = product = distribution = None
        if IProduct.providedBy(self):
            product = self
        elif IProjectGroup.providedBy(self):
            project = self
        elif IDistribution.providedBy(self):
            distribution = self
        else:
            raise AssertionError, 'Unsupported announcement target'

        # Create the announcement in the database.
        announcement = Announcement(
            registrant = user,
            title = title,
            summary = summary,
            url = url,
            product = product,
            project = project,
            distribution = distribution
            )

        announcement.setPublicationDate(publication_date)
        return announcement
Exemplo n.º 6
0
 def test_information_type_from_product(self):
     # information_type_from_product() returns an IProduct given
     # an IMilestone.
     milestone = self.factory.makeMilestone()
     product = information_type_from_product(milestone)
     self.assertTrue(IProduct.providedBy(product))
     self.assertEqual(product, milestone.product)
Exemplo n.º 7
0
    def getAnnouncements(self, limit=5, published_only=True):
        """See IHasAnnouncements."""

        # Create the SQL query.
        query = '1=1 '
        # Filter for published news items if necessary.
        if published_only:
            query += """ AND
                Announcement.date_announced <= timezone('UTC'::text, now()) AND
                Announcement.active IS TRUE
                """
        if IProduct.providedBy(self):
            if self.project is None:
                query += """ AND
                    Announcement.product = %s""" % sqlvalues(self.id)
            else:
                query += """ AND
                    (Announcement.product = %s OR Announcement.project = %s)
                    """ % sqlvalues(self.id, self.project)
        elif IProjectGroup.providedBy(self):
            query += """ AND
                (Announcement.project = %s OR Announcement.product IN
                    (SELECT id FROM Product WHERE project = %s))
                    """ % sqlvalues (self.id, self.id)
        elif IDistribution.providedBy(self):
            query += (' AND Announcement.distribution = %s'
                % sqlvalues(self.id))
        elif IAnnouncementSet.providedBy(self):
            # There is no need to filter for pillar if we are looking for
            # all announcements.
            pass
        else:
            raise AssertionError, 'Unsupported announcement target'
        return Announcement.select(query, limit=limit)
Exemplo n.º 8
0
    def traverse(self, segments):
        """See `IBranchNamespaceSet`."""
        traversed_segments = []

        def get_next_segment():
            try:
                result = segments.next()
            except StopIteration:
                raise InvalidNamespace("/".join(traversed_segments))
            if result is None:
                raise AssertionError("None segment passed to traverse()")
            traversed_segments.append(result)
            return result

        person_name = get_next_segment()
        person = self._findPerson(person_name)
        pillar_name = get_next_segment()
        pillar = self._findPillar(pillar_name)
        if pillar is None or IProduct.providedBy(pillar):
            namespace = self.get(person, product=pillar)
        else:
            distroseries_name = get_next_segment()
            distroseries = self._findDistroSeries(pillar, distroseries_name)
            sourcepackagename_name = get_next_segment()
            sourcepackagename = self._findSourcePackageName(sourcepackagename_name)
            namespace = self.get(person, distroseries=distroseries, sourcepackagename=sourcepackagename)
        branch_name = get_next_segment()
        return self._findOrRaise(NoSuchBranch, branch_name, namespace.getByName)
def set_service_usage(pillar_name, **kw):
    factory = LaunchpadObjectFactory()
    with celebrity_logged_in('admin'):
        pillar = getUtility(IPillarNameSet)[pillar_name]
        for attr, service_usage_name in kw.items():
            service_usage = getattr(ServiceUsage, service_usage_name)
            if attr == 'bug_tracking_usage':
                pillar.official_malone = (
                    service_usage == ServiceUsage.LAUNCHPAD)
                if service_usage == ServiceUsage.EXTERNAL:
                    pillar.bugtracker = factory.makeBugTracker()

            # if we're setting codehosting on product things get trickier.
            elif attr == 'codehosting_usage' and IProduct.providedBy(pillar):
                if service_usage == ServiceUsage.LAUNCHPAD:
                    branch = factory.makeProductBranch(product=pillar)
                    product_series = factory.makeProductSeries(
                        product=pillar,
                        branch=branch)
                    pillar.development_focus = product_series
                elif service_usage == ServiceUsage.EXTERNAL:
                    branch = factory.makeProductBranch(
                        product=pillar,
                        branch_type=BranchType.MIRRORED)
                    product_series = factory.makeProductSeries(
                        product=pillar,
                        branch=branch)
                    pillar.development_focus = product_series
                elif service_usage == ServiceUsage.UNKNOWN:
                    branch = factory.makeProductBranch(product=pillar)
                    product_series = factory.makeProductSeries(
                        product=pillar)
                    pillar.development_focus = product_series
            else:
                setattr(pillar, attr, service_usage)
Exemplo n.º 10
0
    def getSpecificationSharingPolicies(self, pillar):
        """See `ISharingService`."""
        # Only Products have specification sharing policies. Distributions just
        # default to Public.
        allowed_policies = [SpecificationSharingPolicy.PUBLIC]
        # Commercial projects also allow proprietary specifications.
        if (IProduct.providedBy(pillar)
            and pillar.has_current_commercial_subscription):

            if pillar.private:
                allowed_policies = [
                    SpecificationSharingPolicy.EMBARGOED_OR_PROPRIETARY,
                    SpecificationSharingPolicy.PROPRIETARY,
                ]
            else:
                allowed_policies = [
                    SpecificationSharingPolicy.PUBLIC,
                    SpecificationSharingPolicy.PUBLIC_OR_PROPRIETARY,
                    SpecificationSharingPolicy.PROPRIETARY_OR_PUBLIC,
                    SpecificationSharingPolicy.PROPRIETARY,
                ]

        if (pillar.specification_sharing_policy and
            not pillar.specification_sharing_policy in allowed_policies):
            allowed_policies.append(pillar.specification_sharing_policy)

        return self._makeEnumData(allowed_policies)
Exemplo n.º 11
0
 def create(cls, product, metadata):
     """See `IProductJob`."""
     if not IProduct.providedBy(product):
         raise TypeError("Product must be an IProduct: %s" % repr(product))
     job = ProductJob(
         product=product, job_type=cls.class_job_type, metadata=metadata)
     return cls(job)
Exemplo n.º 12
0
 def getByName(self, pillar, name):
     """See ISpecificationSet."""
     clauses = [Specification.name == name]
     if IDistribution.providedBy(pillar):
         clauses.append(Specification.distributionID == pillar.id)
     elif IProduct.providedBy(pillar):
         clauses.append(Specification.productID == pillar.id)
     return IStore(Specification).find(Specification, *clauses).one()
 def can_configure_blueprints(self):
     """Can the user configure blueprints for the `ISpecificationTarget`.
     """
     target = self.context
     if IProduct.providedBy(target) or IDistribution.providedBy(target):
         return check_permission('launchpad.Edit', self.context)
     else:
         return False
Exemplo n.º 14
0
 def _getOfficialTagClause(self):
     if IDistribution.providedBy(self):
         return (OfficialBugTag.distribution == self)
     elif IProduct.providedBy(self):
         return (OfficialBugTag.product == self)
     else:
         raise AssertionError(
             '%s is not a valid official bug target' % self)
Exemplo n.º 15
0
 def test_productseries_to_product(self):
     # productseries_to_product() returns an IProduct given an
     # IProductSeries.
     product_series = self.factory.makeProductSeries()
     product = productseries_to_product(product_series)
     self.assertTrue(IProduct.providedBy(product))
     self.assertEqual(product_series.product, product)
     self.assertEqual(product, IProduct(product_series))
Exemplo n.º 16
0
    def _getSharedPillars(self, person, user, pillar_class, extra_filter=None):
        """Helper method for getSharedProjects and getSharedDistributions.

        pillar_class is either Product or Distribution. Products define the
        owner foreign key attribute as _owner so we need to account for that,
        but otherwise the logic is the same for both pillar types.
        """
        if user is None:
            return []
        store = IStore(AccessPolicyGrantFlat)
        roles = IPersonRoles(user)
        if roles.in_admin:
            filter = True
        else:
            with_statement = With("teams",
                Select(TeamParticipation.teamID,
                    tables=TeamParticipation,
                    where=TeamParticipation.person == user.id))
            teams_sql = SQL("SELECT team from teams")
            store = store.with_(with_statement)
            if IProduct.implementedBy(pillar_class):
                ownerID = pillar_class._ownerID
            else:
                ownerID = pillar_class.ownerID
            filter = Or(
                extra_filter or False,
                ownerID.is_in(teams_sql),
                pillar_class.driverID.is_in(teams_sql))
        tables = [
            AccessPolicyGrantFlat,
            Join(
                AccessPolicy,
                AccessPolicyGrantFlat.policy_id == AccessPolicy.id)]
        if IProduct.implementedBy(pillar_class):
            access_policy_column = AccessPolicy.product_id
        else:
            access_policy_column = AccessPolicy.distribution_id
        result_set = store.find(
            pillar_class,
            pillar_class.id.is_in(
                Select(
                    columns=access_policy_column, tables=tables,
                    where=(AccessPolicyGrantFlat.grantee_id == person.id))
            ), filter)
        return result_set
Exemplo n.º 17
0
 def getBugNotification(self):
     """See `IBugChange`."""
     if IProduct.providedBy(self.old_value):
         template = u"** Project changed: %s => %s"
     else:
         template = u"** Package changed: %s => %s"
     text = template % (
         self.old_value.bugtargetname,
         self.new_value.bugtargetname)
     return {'text': text}
Exemplo n.º 18
0
 def getFAQ(self, id):
     """See `IQuestionCollection`."""
     faq = FAQ.getForTarget(id, None)
     if (faq is not None
         and IProduct.providedBy(faq.target)
         and faq.target in self.products):
         # Filter out faq not related to this project.
         return faq
     else:
         return None
Exemplo n.º 19
0
 def create_release(self):
     """The link to create a release for this milestone."""
     text = 'Create release'
     summary = 'Create a release from this milestone'
     # Releases only exist for products.
     # A milestone can only have a single product release.
     enabled = (IProduct.providedBy(self.context.target)
                and self.context.product_release is None)
     return Link(
         '+addrelease', text, summary, icon='add', enabled=enabled)
Exemplo n.º 20
0
 def initialize(self):
     context = self.context
     if IProduct.providedBy(context):
         self.context_name = "Project"
     elif IDistribution.providedBy(context):
         self.context_name = "Distribution"
     elif IProjectGroup.providedBy(context):
         self.context_name = "Project Group"
     else:
         raise AssertionError("Context is not a Product, Project group or Distribution: %r" % context)
Exemplo n.º 21
0
 def _settarget(self, target):
     """See `IOfficialBugTag`."""
     if IDistribution.providedBy(target):
         self.distribution = target
     elif IProduct.providedBy(target):
         self.product = target
     else:
         raise ValueError(
             'The target of an OfficialBugTag must be either an '
             'IDistribution instance or an IProduct instance.')
Exemplo n.º 22
0
 def setTarget(self, target):
     """See ISpecification."""
     if IProduct.providedBy(target):
         self.product = target
         self.distribution = None
     elif IDistribution.providedBy(target):
         self.product = None
         self.distribution = target
     else:
         raise AssertionError("Unknown target: %s" % target)
Exemplo n.º 23
0
 def _constraintForPillar(cls, pillar):
     from lp.registry.interfaces.distribution import IDistribution
     from lp.registry.interfaces.product import IProduct
     if IProduct.providedBy(pillar):
         col = cls.product
     elif IDistribution.providedBy(pillar):
         col = cls.distribution
     else:
         raise ValueError("%r is not a supported pillar" % pillar)
     return col == pillar
def get_specification_active_product_filter(context):
    if (IDistribution.providedBy(context) or IDistroSeries.providedBy(context)
        or IProduct.providedBy(context) or IProductSeries.providedBy(context)):
        return [], []
    from lp.registry.model.product import Product
    tables = [
        LeftJoin(Product, Specification.productID == Product.id)]
    active_products = (
        Or(Specification.product == None, Product.active == True))
    return tables, [active_products]
Exemplo n.º 25
0
 def __init__(self, context=None):
     super(BranchRestrictedOnProductVocabulary, self).__init__(context)
     if IProduct.providedBy(self.context):
         self.product = self.context
     elif IProductSeries.providedBy(self.context):
         self.product = self.context.product
     elif IBranch.providedBy(self.context):
         self.product = self.context.product
     else:
         # An unexpected type.
         raise AssertionError('Unexpected context type')
 def getProposalsForContext(context, status=None, visible_by_user=None):
     """See `IBranchMergeProposalGetter`."""
     collection = getUtility(IAllBranches).visibleByUser(visible_by_user)
     if context is None:
         pass
     elif IProduct.providedBy(context):
         collection = collection.inProduct(context)
     elif IPerson.providedBy(context):
         collection = collection.ownedBy(context)
     else:
         raise BadBranchMergeProposalSearchContext(context)
     return collection.getMergeProposals(status)
Exemplo n.º 27
0
def get_karma_context_parameters(context):
    """Return the proper karma context parameters based on the object."""
    # XXX flacoste 2007-07-13 bug=125849:
    # This should go away once bug #125849 is fixed.
    params = dict(product=None, distribution=None)
    if IProduct.providedBy(context):
        params['product'] = context
    elif IDistribution.providedBy(context):
        params['distribution'] = context
    else:
        raise AssertionError('Unknown karma context: %r' % context)
    return params
Exemplo n.º 28
0
 def setRenderedValue(self, value):
     """See IWidget."""
     self.setUpSubWidgets()
     if IBranchTarget.providedBy(value):
         if IProduct.providedBy(value.context):
             self.default_option = 'product'
             self.product_widget.setRenderedValue(value.context)
             return
         elif IPerson.providedBy(value.context):
             self.default_option = 'personal'
             return
     else:
         raise AssertionError('Not a valid value: %r' % value)
Exemplo n.º 29
0
    def create(cls, policies):
        from lp.registry.interfaces.distribution import IDistribution
        from lp.registry.interfaces.product import IProduct

        insert_values = []
        for pillar, type in policies:
            if IProduct.providedBy(pillar):
                insert_values.append((pillar, None, type))
            elif IDistribution.providedBy(pillar):
                insert_values.append((None, pillar, type))
            else:
                raise ValueError("%r is not a supported pillar" % pillar)
        return create(
            (cls.product, cls.distribution, cls.type), insert_values,
            get_objects=True)
Exemplo n.º 30
0
 def setRenderedValue(self, value):
     """See IWidget."""
     self.setUpSubWidgets()
     if IProduct.providedBy(value):
         self.default_option = 'product'
         self.product_widget.setRenderedValue(value)
     elif IDistribution.providedBy(value):
         self.default_option = 'package'
         self.distribution_widget.setRenderedValue(value)
     elif IDistributionSourcePackage.providedBy(value):
         self.default_option = 'package'
         self.distribution_widget.setRenderedValue(value.distribution)
         self.package_widget.setRenderedValue(value.sourcepackagename)
     else:
         raise AssertionError('Not a valid value: %r' % value)