← Back to team overview

launchpad-reviewers team mailing list archive

[Merge] ~ines-almeida/launchpad:project-tokens/interfaces into launchpad:master

 

Ines Almeida has proposed merging ~ines-almeida/launchpad:project-tokens/interfaces into launchpad:master with ~ines-almeida/launchpad:project-tokens/update-models as a prerequisite.

Commit message:
Add interfaces to allow adding Project scoped access tokens through the UI and API


Requested reviews:
  Launchpad code reviewers (launchpad-reviewers)

For more details, see:
https://code.launchpad.net/~ines-almeida/launchpad/+git/launchpad/+merge/451543
-- 
Your team Launchpad code reviewers is requested to review the proposed merge of ~ines-almeida/launchpad:project-tokens/interfaces into launchpad:master.
diff --git a/lib/lp/registry/browser/product.py b/lib/lp/registry/browser/product.py
index bc77dd9..4c3a64f 100644
--- a/lib/lp/registry/browser/product.py
+++ b/lib/lp/registry/browser/product.py
@@ -469,6 +469,11 @@ class ProductEditLinksMixin(StructuralSubscriptionMenuMixin):
         return Link("+configure-blueprints", text, summary, icon="edit")
 
     @enabled_with_permission("launchpad.Edit")
+    def access_tokens(self):
+        text = "Manage access tokens"
+        return Link("+access-tokens", text, icon="edit")
+
+    @enabled_with_permission("launchpad.Edit")
     def branding(self):
         text = "Change branding"
         return Link("+branding", text, icon="edit")
@@ -547,6 +552,7 @@ class ProductActionNavigationMenu(NavigationMenu, ProductEditLinksMixin):
             "search_oci_project",
             "new_oci_project",
             "webhooks",
+            "access_tokens",
         ]
         add_subscribe_link(links)
         return links
diff --git a/lib/lp/registry/interfaces/product.py b/lib/lp/registry/interfaces/product.py
index 790f77d..af127f0 100644
--- a/lib/lp/registry/interfaces/product.py
+++ b/lib/lp/registry/interfaces/product.py
@@ -117,6 +117,10 @@ from lp.registry.interfaces.role import (
     IHasDrivers,
     IHasOwner,
 )
+from lp.services.auth.interfaces import (
+    IAccessTokenTarget,
+    IAccessTokenTargetEdit,
+)
 from lp.services.fields import (
     Description,
     IconImageUpload,
@@ -606,6 +610,7 @@ class IProductView(
     IHasCodeImports,
     IServiceUsage,
     IHasGitRepositories,
+    IAccessTokenTarget,
 ):
     """Public IProduct properties."""
 
@@ -1099,7 +1104,11 @@ class IProductView(
         """
 
 
-class IProductEditRestricted(IOfficialBugTagTargetRestricted, IWebhookTarget):
+class IProductEditRestricted(
+    IOfficialBugTagTargetRestricted,
+    IWebhookTarget,
+    IAccessTokenTargetEdit,
+):
     """`IProduct` properties which require launchpad.Edit permission."""
 
     @mutator_for(IProductView["bug_sharing_policy"])
diff --git a/lib/lp/registry/model/product.py b/lib/lp/registry/model/product.py
index f3bb669..e7683f0 100644
--- a/lib/lp/registry/model/product.py
+++ b/lib/lp/registry/model/product.py
@@ -150,6 +150,7 @@ from lp.registry.model.series import ACTIVE_STATUSES
 from lp.registry.model.sharingpolicy import SharingPolicyMixin
 from lp.registry.model.sourcepackagename import SourcePackageName
 from lp.registry.model.teammembership import TeamParticipation
+from lp.services.auth.model import AccessTokenTargetMixin
 from lp.services.database import bulk
 from lp.services.database.constants import UTC_NOW
 from lp.services.database.decoratedresultset import DecoratedResultSet
@@ -248,6 +249,7 @@ specification_policy_default = {
 @implementer(IBugSummaryDimension, IHasCustomLanguageCodes, IProduct)
 class Product(
     StormBase,
+    AccessTokenTargetMixin,
     BugTargetBase,
     HasDriversMixin,
     OfficialBugTagTargetMixin,
diff --git a/lib/lp/services/auth/tests/test_model.py b/lib/lp/services/auth/tests/test_model.py
index 9c9f7d0..84b4691 100644
--- a/lib/lp/services/auth/tests/test_model.py
+++ b/lib/lp/services/auth/tests/test_model.py
@@ -730,3 +730,10 @@ class TestAccessTokenTargetGitRepository(
             b"user.",
             response.body,
         )
+
+
+class TestAccessTokenTargetProject(
+    TestAccessTokenTargetBase, TestCaseWithFactory
+):
+    def makeTarget(self):
+        return self.factory.makeProduct()
diff --git a/lib/lp/services/webapp/tests/test_servers.py b/lib/lp/services/webapp/tests/test_servers.py
index e777ac2..491fed7 100644
--- a/lib/lp/services/webapp/tests/test_servers.py
+++ b/lib/lp/services/webapp/tests/test_servers.py
@@ -968,6 +968,13 @@ class TestWebServiceAccessTokensGitRepository(
         return self.factory.makeGitRepository(owner=owner)
 
 
+class TestWebServiceAccessTokensProject(
+    TestWebServiceAccessTokensBase, TestCaseWithFactory
+):
+    def makeTarget(self, owner=None):
+        return self.factory.makeProduct(owner=owner)
+
+
 def test_suite():
     suite = unittest.TestSuite()
     suite.addTest(