Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update activity stream, #9768, #9769 #10662

Merged
merged 4 commits into from
Mar 26, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions arches/app/models/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,9 +228,11 @@ def save(self, *args, **kwargs):
context = kwargs.pop("context", None)
transaction_id = kwargs.pop("transaction_id", None)
super(Resource, self).save(*args, **kwargs)
self.save_edit(user=user, edit_type="create", transaction_id=transaction_id)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think as the ticket author pointed out it's possible that moving this call to solve #9769 is not necessary if we do the filtering in #9768 as in this PR, but I still like the idea of doing it in case the another caller somewhere else in the application chooses not to filter in the same precise way.


for tile in self.tiles:
tile.resourceinstance_id = self.resourceinstanceid
tile.save(request=request, index=False, transaction_id=transaction_id, context=context)
tile.save(request=request, index=False, resource_creation=True, transaction_id=transaction_id, context=context)
if request is None:
if user is None:
user = {}
Expand All @@ -243,7 +245,6 @@ def save(self, *args, **kwargs):
except NotUserNorGroup:
pass

self.save_edit(user=user, edit_type="create", transaction_id=transaction_id)
if index is True:
self.index(context)

Expand Down
6 changes: 5 additions & 1 deletion arches/app/models/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ def save_edit(
edit.edittype = edit_type
edit.newprovisionalvalue = newprovisionalvalue
edit.oldprovisionalvalue = oldprovisionalvalue
edit.note = note
if transaction_id is not None:
edit.transactionid = transaction_id
edit.save()
Expand Down Expand Up @@ -391,6 +392,8 @@ def save(self, *args, **kwargs):
index = kwargs.pop("index", True)
user = kwargs.pop("user", None)
new_resource_created = kwargs.pop("new_resource_created", False)
resource_creation = kwargs.pop("resource_creation", False)
note = "resource creation" if resource_creation else None
context = kwargs.pop("context", None)
transaction_id = kwargs.pop("transaction_id", None)
provisional_edit_log_details = kwargs.pop("provisional_edit_log_details", None)
Expand Down Expand Up @@ -470,6 +473,7 @@ def save(self, *args, **kwargs):
provisional_edit_log_details=provisional_edit_log_details,
transaction_id=transaction_id,
new_resource_created=new_resource_created,
note=note,
)
else:
self.save_edit(
Expand All @@ -486,7 +490,7 @@ def save(self, *args, **kwargs):
for tile in self.tiles:
tile.resourceinstance = self.resourceinstance
tile.parenttile = self
tile.save(*args, request=request, index=False, **kwargs)
tile.save(*args, request=request, resource_creation=resource_creation, index=False, **kwargs)

resource = Resource.objects.get(pk=self.resourceinstance_id)
resource.save_descriptors(context={'tile': self})
Expand Down
20 changes: 16 additions & 4 deletions arches/app/views/resource.py
Original file line number Diff line number Diff line change
Expand Up @@ -637,10 +637,17 @@ def get(self, request, page=None):
except (ValueError, TypeError) as e:
return HttpResponseBadRequest()

totalItems = models.EditLog.objects.all().exclude(resourceclassid=settings.SYSTEM_SETTINGS_RESOURCE_MODEL_ID).count()

totalItems = (
models.EditLog.objects.all()
.exclude(resourceclassid=settings.SYSTEM_SETTINGS_RESOURCE_MODEL_ID)
.exclude(note="resource creation")
.count()
)
edits = (
models.EditLog.objects.all().exclude(resourceclassid=settings.SYSTEM_SETTINGS_RESOURCE_MODEL_ID).order_by("timestamp")[st:end]
models.EditLog.objects.all()
.exclude(resourceclassid=settings.SYSTEM_SETTINGS_RESOURCE_MODEL_ID)
.exclude(note="resource creation")
.order_by("timestamp")[st:end]
)
jacobtylerwalls marked this conversation as resolved.
Show resolved Hide resolved

# setting last to be same as first, changing later if there are more pages
Expand Down Expand Up @@ -673,7 +680,12 @@ def get(self, request):
if hasattr(settings, "ACTIVITY_STREAM_PAGE_SIZE"):
page_size = int(settings.ACTIVITY_STREAM_PAGE_SIZE)

totalItems = models.EditLog.objects.all().exclude(resourceclassid=settings.SYSTEM_SETTINGS_RESOURCE_MODEL_ID).count()
totalItems = (
models.EditLog.objects.all()
.exclude(resourceclassid=settings.SYSTEM_SETTINGS_RESOURCE_MODEL_ID)
.exclude(note="resource creation")
.count()
)

uris = {
"root": request.build_absolute_uri(reverse("as_stream_collection")),
Expand Down
6 changes: 4 additions & 2 deletions arches/app/views/tile.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ def post(self, request):
if self.action == "update_tile":
json = request.POST.get("data", None)
accepted_provisional = request.POST.get("accepted_provisional", None)
resource_creation = False
if accepted_provisional is not None:
accepted_provisional_edit = JSONDeserializer().deserialize(accepted_provisional)
if json is not None:
Expand All @@ -111,6 +112,7 @@ def post(self, request):
try:
models.ResourceInstance.objects.get(pk=data["resourceinstance_id"])
except ObjectDoesNotExist:
resource_creation = True
try:
resource = Resource(uuid.UUID(str(data["resourceinstance_id"])))
except ValueError:
Expand Down Expand Up @@ -141,7 +143,7 @@ def post(self, request):
try:
if accepted_provisional is None:
try:
tile.save(request=request, transaction_id=transaction_id)
tile.save(request=request, resource_creation=resource_creation, transaction_id=transaction_id)
except TileValidationError as e:
resource_tiles_exist = models.TileModel.objects.filter(resourceinstance=tile.resourceinstance).exists()
if not resource_tiles_exist:
Expand All @@ -163,7 +165,7 @@ def post(self, request):
"edit": accepted_provisional_edit,
"provisional_editor": provisional_editor,
}
tile.save(request=request, provisional_edit_log_details=prov_edit_log_details)
tile.save(request=request, resource_creation=resource_creation, provisional_edit_log_details=prov_edit_log_details)

if tile.provisionaledits is not None and str(request.user.id) in tile.provisionaledits:
tile.data = tile.provisionaledits[str(request.user.id)]["value"]
Expand Down