diff --git a/frontend/coprs_frontend/commands/rawhide_to_release.py b/frontend/coprs_frontend/commands/rawhide_to_release.py index 5bb303c1a..b69cda4c3 100644 --- a/frontend/coprs_frontend/commands/rawhide_to_release.py +++ b/frontend/coprs_frontend/commands/rawhide_to_release.py @@ -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() diff --git a/frontend/coprs_frontend/coprs/logic/actions_logic.py b/frontend/coprs_frontend/coprs/logic/actions_logic.py index a263b8f03..2ac6066b4 100644 --- a/frontend/coprs_frontend/coprs/logic/actions_logic.py +++ b/frontend/coprs_frontend/coprs/logic/actions_logic.py @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/frontend/coprs_frontend/coprs/logic/coprs_logic.py b/frontend/coprs_frontend/coprs/logic/coprs_logic.py index 58cdd9829..d3a41746c 100644 --- a/frontend/coprs_frontend/coprs/logic/coprs_logic.py +++ b/frontend/coprs_frontend/coprs/logic/coprs_logic.py @@ -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: @@ -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): diff --git a/frontend/coprs_frontend/coprs/models.py b/frontend/coprs_frontend/coprs/models.py index 038534b47..fe3095c5f 100644 --- a/frontend/coprs_frontend/coprs/models.py +++ b/frontend/coprs_frontend/coprs/models.py @@ -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) @@ -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__()