diff --git a/common/copr_common/enums.py b/common/copr_common/enums.py index 6e3840e29..96a28bb5f 100644 --- a/common/copr_common/enums.py +++ b/common/copr_common/enums.py @@ -1,5 +1,6 @@ import random import string +from enum import Enum from six import with_metaclass @@ -137,3 +138,14 @@ class FailTypeEnum(with_metaclass(EnumType, object)): "git_checkout_error": 33, "srpm_build_error": 34, } + + +class ActionObjectTypeEnum(str, Enum): + COPR = "copr" + REPOSITORY = "repository" + BUILD = "build" + BUILDS = "builds" + COPR_CHROOT = "copr_chroot" + CHROOT = "chroot" + MODULE = "module" + NONE = "None" diff --git a/frontend/coprs_frontend/coprs/logic/actions_logic.py b/frontend/coprs_frontend/coprs/logic/actions_logic.py index a263b8f03..11122bb08 100644 --- a/frontend/coprs_frontend/coprs/logic/actions_logic.py +++ b/frontend/coprs_frontend/coprs/logic/actions_logic.py @@ -4,7 +4,7 @@ from sqlalchemy import and_, or_ from sqlalchemy.exc import IntegrityError -from copr_common.enums import ActionTypeEnum, BackendResultEnum +from copr_common.enums import ActionTypeEnum, BackendResultEnum, ActionObjectTypeEnum from coprs import db from coprs import models from coprs import helpers @@ -128,7 +128,7 @@ def send_createrepo(cls, copr, dirnames=None, chroots=None, devel=None, data_dict["devel"] = run == "dev" action = models.Action( action_type=ActionTypeEnum("createrepo"), - object_type="repository", + object_type=ActionObjectTypeEnum.REPOSITORY, object_id=0, data=json.dumps(data_dict), created_on=int(time.time()), @@ -145,7 +145,7 @@ def send_delete_copr(cls, copr): "project_dirnames": [copr_dir.name for copr_dir in copr.dirs], } action = models.Action(action_type=ActionTypeEnum("delete"), - object_type="copr", + object_type=ActionObjectTypeEnum.COPR, object_id=copr.id, data=json.dumps(data_dict), created_on=int(time.time())) @@ -197,7 +197,7 @@ def send_delete_build(cls, build): """ action = models.Action( action_type=ActionTypeEnum("delete"), - object_type="build", + object_type=ActionObjectTypeEnum.BUILD, object_id=build.id, data=json.dumps(cls.get_build_delete_data(build)), created_on=int(time.time()) @@ -244,7 +244,7 @@ def send_delete_multiple_builds(cls, builds): # not object_id here, we are working with multiple IDs action = models.Action( action_type=ActionTypeEnum("delete"), - object_type="builds", + object_type=ActionObjectTypeEnum.BUILDS, data=json.dumps(data), created_on=int(time.time()) ) @@ -284,7 +284,7 @@ def send_update_comps(cls, chroot): action = models.Action( action_type=ActionTypeEnum("update_comps"), - object_type="copr_chroot", + object_type=ActionObjectTypeEnum.COPR_CHROOT, data=json.dumps(data_dict), created_on=int(time.time()) ) @@ -305,7 +305,7 @@ def send_create_gpg_key(cls, copr): action = models.Action( action_type=ActionTypeEnum("gen_gpg_key"), - object_type="copr", + object_type=ActionObjectTypeEnum.COPR, data=json.dumps(data_dict), created_on=int(time.time()), ) @@ -316,7 +316,7 @@ def send_create_gpg_key(cls, copr): def send_rawhide_to_release(cls, data): action = models.Action( action_type=ActionTypeEnum("rawhide_to_release"), - object_type="None", + object_type=ActionObjectTypeEnum.NONE, data=json.dumps(data), created_on=int(time.time()), ) @@ -333,7 +333,7 @@ def send_fork_copr(cls, src, dst, builds_map): action = models.Action( action_type=ActionTypeEnum("fork"), - object_type="copr", + object_type=ActionObjectTypeEnum.COPR, old_value="{0}".format(src.full_name), new_value="{0}".format(dst.full_name), data=json.dumps({"user": dst.owner_name, "copr": dst.name, "builds_map": builds_map}), @@ -358,7 +358,7 @@ def send_build_module(cls, copr, module): action = models.Action( action_type=ActionTypeEnum("build_module"), - object_type="module", + object_type=ActionObjectTypeEnum.MODULE, object_id=module.id, old_value="", new_value="", @@ -383,7 +383,7 @@ def send_delete_chroot(cls, copr_chroot): action = models.Action( action_type=ActionTypeEnum("delete"), - object_type="chroot", + object_type=ActionObjectTypeEnum.CHROOT, object_id=None, data=json.dumps(data_dict), created_on=int(time.time()) diff --git a/frontend/coprs_frontend/coprs/logic/complex_logic.py b/frontend/coprs_frontend/coprs/logic/complex_logic.py index 81bdf2203..48b268a32 100644 --- a/frontend/coprs_frontend/coprs/logic/complex_logic.py +++ b/frontend/coprs_frontend/coprs/logic/complex_logic.py @@ -130,7 +130,7 @@ def delete_expired_projects(cls): def _wait_for_copr_to_be_deleted(cls, ownername, dirname): actions_to_wait = ( models.Action.query - .filter(models.Action.object_type == ActionObjectTypeEnum.copr) + .filter(models.Action.object_type == ActionObjectTypeEnum.COPR) .filter(models.Action.result == BackendResultEnum("waiting")) .filter(models.Action.action_type == ActionTypeEnum("delete")) .filter( diff --git a/frontend/coprs_frontend/coprs/logic/coprs_logic.py b/frontend/coprs_frontend/coprs/logic/coprs_logic.py index 58cdd9829..1f08046a2 100644 --- a/frontend/coprs_frontend/coprs/logic/coprs_logic.py +++ b/frontend/coprs_frontend/coprs/logic/coprs_logic.py @@ -16,7 +16,7 @@ from sqlalchemy.orm.exc import NoResultFound from sqlalchemy.orm.attributes import get_history -from copr_common.enums import ActionTypeEnum, BackendResultEnum, ActionPriorityEnum +from copr_common.enums import ActionTypeEnum, BackendResultEnum, ActionPriorityEnum, ActionObjectTypeEnum from coprs import app, db from coprs import exceptions from coprs import helpers @@ -859,7 +859,7 @@ def send_delete_dirs_action(cls): action = models.Action( action_type=ActionTypeEnum("remove_dirs"), - object_type="copr", + object_type=ActionObjectTypeEnum.COPR, data=json.dumps(remove_dirs), created_on=int(time.time())) diff --git a/frontend/coprs_frontend/tests/coprs_test_case.py b/frontend/coprs_frontend/tests/coprs_test_case.py index 36b10cd36..0486e992c 100644 --- a/frontend/coprs_frontend/tests/coprs_test_case.py +++ b/frontend/coprs_frontend/tests/coprs_test_case.py @@ -13,7 +13,7 @@ import coprs -from copr_common.enums import ActionTypeEnum, BackendResultEnum, StatusEnum +from copr_common.enums import ActionTypeEnum, BackendResultEnum, StatusEnum, ActionObjectTypeEnum from coprs import helpers from coprs import models from coprs import cache @@ -679,7 +679,7 @@ def f_copr_more_permissions(self, f_copr_permissions): @pytest.fixture def f_actions(self, f_db): self.delete_action = models.Action(action_type=ActionTypeEnum("delete"), - object_type="copr", + object_type=ActionObjectTypeEnum.COPR, object_id=self.c1.id, old_value="asd/qwe", new_value=None, diff --git a/frontend/coprs_frontend/tests/test_logic/test_coprs_logic.py b/frontend/coprs_frontend/tests/test_logic/test_coprs_logic.py index 5d8ec81ef..675fa2c4d 100644 --- a/frontend/coprs_frontend/tests/test_logic/test_coprs_logic.py +++ b/frontend/coprs_frontend/tests/test_logic/test_coprs_logic.py @@ -7,7 +7,7 @@ from sqlalchemy import desc -from copr_common.enums import ActionTypeEnum, StatusEnum +from copr_common.enums import ActionTypeEnum, StatusEnum, ActionObjectTypeEnum from coprs import app from coprs.forms import PinnedCoprsForm, ChrootForm, ModuleEnableNameValidator from coprs.logic.actions_logic import ActionsLogic @@ -31,7 +31,7 @@ class TestCoprsLogic(CoprsTestCase): def test_legal_flag_doesnt_block_copr_functionality(self, f_users, f_coprs, f_db): self.db.session.add(self.models.Action( - object_type="copr", + object_type=ActionObjectTypeEnum.COPR, object_id=self.c1.id, action_type=ActionTypeEnum("legal-flag"))) diff --git a/frontend/coprs_frontend/tests/test_logic/test_modules_logic.py b/frontend/coprs_frontend/tests/test_logic/test_modules_logic.py index 2e1cd891d..d9ce6097d 100644 --- a/frontend/coprs_frontend/tests/test_logic/test_modules_logic.py +++ b/frontend/coprs_frontend/tests/test_logic/test_modules_logic.py @@ -7,7 +7,7 @@ from tests.coprs_test_case import CoprsTestCase from coprs.logic.modules_logic import ModulesLogic, ModuleBuildFacade, ModulemdGenerator from coprs.logic.coprs_logic import CoprChrootsLogic -from copr_common.enums import ActionTypeEnum, BackendResultEnum, ModuleStatusEnum, StatusEnum +from copr_common.enums import ActionTypeEnum, BackendResultEnum, ModuleStatusEnum, StatusEnum, ActionObjectTypeEnum from coprs.exceptions import BadRequest from coprs import models, db @@ -40,7 +40,7 @@ def test_state(self, f_users, f_coprs, f_mock_chroots, f_builds, f_modules, f_db self.b3.build_chroots[0].status = StatusEnum("succeeded") action = models.Action( action_type=ActionTypeEnum("build_module"), - object_type="module", + object_type=ActionObjectTypeEnum.MODULE, object_id=self.m1.id, ) db.session.add(action)