X-Git-Url: https://osm.etsi.org/gitweb/?p=osm%2FNBI.git;a=blobdiff_plain;f=osm_nbi%2Fbase_topic.py;h=2986b8180eb035587fbf386e4466b203d7d4569e;hp=1f7f5d49fb805fa7b6549297bf0c904ce9c06561;hb=6b02b05e51fb2837731027ae063ecbdb2c71135d;hpb=d7749588e6cc73661d052fc5bb41605e1b588128 diff --git a/osm_nbi/base_topic.py b/osm_nbi/base_topic.py index 1f7f5d4..2986b81 100644 --- a/osm_nbi/base_topic.py +++ b/osm_nbi/base_topic.py @@ -69,6 +69,7 @@ class BaseTopic: # static variables for all instance classes topic = None # to_override topic_msg = None # to_override + quota_name = None # to_override. If not provided topic will be used for quota_name schema_new = None # to_override schema_edit = None # to_override multiproject = True # True if this Topic can be shared by several projects. Then it contains _admin.projects_read @@ -107,12 +108,12 @@ class BaseTopic: """ Check whether topic quota is exceeded by the given project Used by relevant topics' 'new' function to decide whether or not creation of the new item should be allowed - :param projects: projects (tuple) for which quota should be checked - :param override: boolean. If true, don't raise ValidationError even though quota be exceeded + :param session[project_id]: projects (tuple) for which quota should be checked + :param session[force]: boolean. If true, skip quota checking :return: None :raise: DbException if project not found - ValidationError if quota exceeded and not overridden + ValidationError if quota exceeded in one of the projects """ if session["force"]: return @@ -120,11 +121,12 @@ class BaseTopic: for project in projects: proj = self.auth.get_project(project) pid = proj["_id"] - quota = proj.get("quotas", {}).get(self.topic, self.default_quota) + quota_name = self.quota_name or self.topic + quota = proj.get("quotas", {}).get(quota_name, self.default_quota) count = self.db.count(self.topic, {"_admin.projects_read": pid}) if count >= quota: name = proj["name"] - raise ValidationError("quota ({}={}) exceeded for project {} ({})".format(self.topic, quota, name, pid), + raise ValidationError("quota ({}={}) exceeded for project {} ({})".format(quota_name, quota, name, pid), http_code=HTTPStatus.UNAUTHORIZED) def _validate_input_new(self, input, force=False):