allura-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hei...@apache.org
Subject [37/46] allura git commit: [#7886] ticket:789 Helper to check if limit is exceeded for artifact
Date Mon, 15 Jun 2015 12:27:56 GMT
[#7886] ticket:789 Helper to check if limit is exceeded for artifact


Project: http://git-wip-us.apache.org/repos/asf/allura/repo
Commit: http://git-wip-us.apache.org/repos/asf/allura/commit/d22046ce
Tree: http://git-wip-us.apache.org/repos/asf/allura/tree/d22046ce
Diff: http://git-wip-us.apache.org/repos/asf/allura/diff/d22046ce

Branch: refs/heads/hs/7873
Commit: d22046ce603f7ec97a1c2ba3b38011f8c22446b7
Parents: be93d3d
Author: Igor Bondarenko <jetmind2@gmail.com>
Authored: Wed Jun 10 07:48:45 2015 +0000
Committer: Dave Brondsema <dbrondsema@slashdotmedia.com>
Committed: Fri Jun 12 18:44:25 2015 +0000

----------------------------------------------------------------------
 Allura/allura/model/artifact.py | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/allura/blob/d22046ce/Allura/allura/model/artifact.py
----------------------------------------------------------------------
diff --git a/Allura/allura/model/artifact.py b/Allura/allura/model/artifact.py
index 32ebc10..1d4e230 100644
--- a/Allura/allura/model/artifact.py
+++ b/Allura/allura/model/artifact.py
@@ -32,6 +32,8 @@ from webhelpers import feedgenerator as FG
 from allura.lib import helpers as h
 from allura.lib import security
 from allura.lib import utils
+from allura.lib import plugin
+from allura.lib import exceptions as forge_exc
 
 from allura.lib.search import SearchIndexable
 from .session import main_orm_session
@@ -408,6 +410,26 @@ class Artifact(MappedClass, SearchIndexable):
         '''Persistent, email-friendly (Message-ID header) id of this artifact'''
         return h.gen_message_id(self._id)
 
+    @classmethod
+    def is_limit_exceeded(cls, app_config):
+        """
+        Returns True if any of artifact creation rate limits are exceeded,
+        False otherwise
+        """
+        pkg = cls.__module__.split('.', 1)[0]
+        opt = u'{}.rate_limits'.format(pkg)
+        count = cls.query.find(dict(app_config_id=app_config._id)).count()
+        provider = plugin.ProjectRegistrationProvider.get()
+        start = provider.registration_date(app_config.project)
+        # have to have the replace because, the generation_time is offset-aware
+        # UTC and h.rate_limit uses offset-naive UTC dates
+        start = start.replace(tzinfo=None)
+        try:
+            h.rate_limit(opt, count, start)
+        except forge_exc.RatelimitError:
+            return True
+        return False
+
 
 class Snapshot(Artifact):
 


Mime
View raw message