Skip to content

Commit

Permalink
common, frontend: Add ActionObjectTypeEnum for actions
Browse files Browse the repository at this point in the history
to prevent typos - Action.object_type is used for filtering Actions
to get their type
  • Loading branch information
nikromen committed Jul 12, 2023
1 parent 76e3e60 commit ef8d8c3
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 20 deletions.
12 changes: 12 additions & 0 deletions common/copr_common/enums.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import random
import string
from enum import Enum

from six import with_metaclass

Expand Down Expand Up @@ -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"
22 changes: 11 additions & 11 deletions frontend/coprs_frontend/coprs/logic/actions_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()),
Expand All @@ -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()))
Expand Down Expand Up @@ -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())
Expand Down Expand Up @@ -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())
)
Expand Down Expand Up @@ -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())
)
Expand All @@ -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()),
)
Expand All @@ -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()),
)
Expand All @@ -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}),
Expand All @@ -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="",
Expand All @@ -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())
Expand Down
2 changes: 1 addition & 1 deletion frontend/coprs_frontend/coprs/logic/complex_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions frontend/coprs_frontend/coprs/logic/coprs_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()))

Expand Down
4 changes: 2 additions & 2 deletions frontend/coprs_frontend/tests/coprs_test_case.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions frontend/coprs_frontend/tests/test_logic/test_coprs_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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")))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ef8d8c3

Please sign in to comment.