Skip to content

Commit

Permalink
frontend: add relationship between Action model and Copr model
Browse files Browse the repository at this point in the history
with this we can get information about Actions in projects and
show it to user
  • Loading branch information
nikromen committed Jul 18, 2023
1 parent 46ae367 commit 1546133
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
2 changes: 1 addition & 1 deletion frontend/coprs_frontend/commands/rawhide_to_release.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ def rawhide_to_release_function(rawhide_chroot, dest_chroot, retry_forked):
))

if len(data["builds"]):
actions_logic.ActionsLogic.send_rawhide_to_release(data)
actions_logic.ActionsLogic.send_rawhide_to_release(copr, data)

db.session.commit()

Expand Down
23 changes: 17 additions & 6 deletions frontend/coprs_frontend/coprs/logic/actions_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ def send_createrepo(cls, copr, dirnames=None, chroots=None, devel=None,
object_id=0,
data=json.dumps(data_dict),
created_on=int(time.time()),
copr_id=copr.id,
)
if priority is not None:
action.priority = priority
Expand All @@ -148,7 +149,8 @@ def send_delete_copr(cls, copr):
object_type="copr",
object_id=copr.id,
data=json.dumps(data_dict),
created_on=int(time.time()))
created_on=int(time.time()),
copr_id=copr.id)
db.session.add(action)
return action

Expand Down Expand Up @@ -200,7 +202,8 @@ def send_delete_build(cls, build):
object_type="build",
object_id=build.id,
data=json.dumps(cls.get_build_delete_data(build)),
created_on=int(time.time())
created_on=int(time.time()),
copr_id=build.copr.id
)
db.session.add(action)
return action
Expand Down Expand Up @@ -246,7 +249,9 @@ def send_delete_multiple_builds(cls, builds):
action_type=ActionTypeEnum("delete"),
object_type="builds",
data=json.dumps(data),
created_on=int(time.time())
created_on=int(time.time()),
# TODO: all builds are from the same Copr?
copr_id=builds[0].copr.id,
)
db.session.add(action)
return action
Expand Down Expand Up @@ -286,7 +291,8 @@ def send_update_comps(cls, chroot):
action_type=ActionTypeEnum("update_comps"),
object_type="copr_chroot",
data=json.dumps(data_dict),
created_on=int(time.time())
created_on=int(time.time()),
copr_id=chroot.copr.id,
)
db.session.add(action)
return action
Expand All @@ -308,17 +314,19 @@ def send_create_gpg_key(cls, copr):
object_type="copr",
data=json.dumps(data_dict),
created_on=int(time.time()),
copr_id=copr.id,
)
db.session.add(action)
return action

@classmethod
def send_rawhide_to_release(cls, data):
def send_rawhide_to_release(cls, copr, data):
action = models.Action(
action_type=ActionTypeEnum("rawhide_to_release"),
object_type="None",
data=json.dumps(data),
created_on=int(time.time()),
copr_id=copr.id,
)
db.session.add(action)
return action
Expand All @@ -338,6 +346,7 @@ def send_fork_copr(cls, src, dst, builds_map):
new_value="{0}".format(dst.full_name),
data=json.dumps({"user": dst.owner_name, "copr": dst.name, "builds_map": builds_map}),
created_on=int(time.time()),
copr_id=dst.id,
)
db.session.add(action)
return action
Expand All @@ -364,6 +373,7 @@ def send_build_module(cls, copr, module):
new_value="",
data=json.dumps(data),
created_on=int(time.time()),
copr_id=copr.id,
)
db.session.add(action)
return action
Expand All @@ -386,7 +396,8 @@ def send_delete_chroot(cls, copr_chroot):
object_type="chroot",
object_id=None,
data=json.dumps(data_dict),
created_on=int(time.time())
created_on=int(time.time()),
copr_id=copr_chroot.copr.id,
)
db.session.add(action)
return action
Expand Down
17 changes: 9 additions & 8 deletions frontend/coprs_frontend/coprs/logic/coprs_logic.py
Original file line number Diff line number Diff line change
Expand Up @@ -840,8 +840,8 @@ def send_delete_dirs_action(cls):
"""
copr_ids = cls.get_copr_ids_with_pr_dirs().all()

remove_dirs = []
for copr_id in copr_ids:
remove_dirs = []
copr_id = copr_id[0]
all_dirs = cls.get_all_with_latest_submitted_build(copr_id)
for copr_dir in all_dirs:
Expand All @@ -857,13 +857,14 @@ def send_delete_dirs_action(cls):
cls.delete_with_builds(dir_object)
remove_dirs.append(dirname)

action = models.Action(
action_type=ActionTypeEnum("remove_dirs"),
object_type="copr",
data=json.dumps(remove_dirs),
created_on=int(time.time()))

db.session.add(action)
action = models.Action(
action_type=ActionTypeEnum("remove_dirs"),
object_type="copr",
data=json.dumps(remove_dirs),
created_on=int(time.time()),
copr_id=copr_id,
)
db.session.add(action)

@classmethod
def copr_name_from_dirname(cls, dirname):
Expand Down
5 changes: 5 additions & 0 deletions frontend/coprs_frontend/coprs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ class _CoprPublic(db.Model, helpers.Serializer):
group_id = db.Column(db.Integer, db.ForeignKey("group.id"))
forked_from_id = db.Column(db.Integer, db.ForeignKey("copr.id"))

actions = db.relationship(back_populates="copr")

# enable networking for the builds by default
build_enable_net = db.Column(db.Boolean, default=True,
server_default="1", nullable=False)
Expand Down Expand Up @@ -2139,6 +2141,9 @@ class Action(db.Model, helpers.Serializer):
# time ended as returned by int(time.time())
ended_on = db.Column(db.Integer, index=True)

copr_id = db.Column(db.Integer, db.ForeignKey("copr.id"), nullable=True)
copr = db.relationship("Copr", back_populates="actions", foreign_keys=[copr_id])

def __str__(self):
return self.__unicode__()

Expand Down

0 comments on commit 1546133

Please sign in to comment.