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 metrics on transfer/owner change #810
Update metrics on transfer/owner change #810
Conversation
'owner', | ||
'organization', | ||
], | ||
'queryset_class': OwnedQuerySet, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we use that? Maybe inheriting from Owned.meta['queryset_class']
is possible but quite ugly :/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is Mongoengine behavior: child classes inherit this queryset (at least used in tests), unless this is explicitely overriden.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay.
udata/models/owned.py
Outdated
import logging | ||
|
||
from blinker import signal | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless new line
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same coding style used in every module: import grouped by packages if not builtin.
udata/models/owned.py
Outdated
|
||
def owned_pre_save(sender, document, **kwargs): | ||
''' | ||
Owned pre_save handler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure that comment is useful? (redundant with method name?)
udata/models/owned.py
Outdated
|
||
def owned_post_save(sender, document, **kwargs): | ||
''' | ||
Owned post_save handler |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
@@ -99,10 +101,89 @@ def test_request_transfer_to_same_organization(self): | |||
self.assert_transfer_started(dataset, org, org, comment) | |||
|
|||
|
|||
class TransferAcceptTest(TestCase, DBTestMixin): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
@@ -49,6 +46,8 @@ def __init__(self, app=None): | |||
self.ValidationError = ValidationError | |||
self.ObjectId = ObjectId | |||
self.DBRef = DBRef | |||
self.Owned = Owned |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't get why we need these two lines?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This allows, as every other db mixins, to be used as db.Owned
and db.OwnedQuerySet
.
db
act as a facade pattern everywhere.
'resources.id', | ||
'resources.urlhash', | ||
], | ||
] + db.Owned.meta['indexes'], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if db.Owned.INDEXES
is easier to understand. Here it looks to be dynamic.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But where does it come from ?
The meta['indexes']
the only way (I know) to get the mixin default indexes.
It relies on mongoengine default (documented) behavior in which meta
is a dictionary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I thought it was udata-related. My bad.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
;)
udata/models/owned.py
Outdated
def owned_pre_save(sender, document, **kwargs): | ||
''' | ||
Owned pre_save handler | ||
Need to fetch original owner before the new one erase it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for on_owner_change
to transfer metrics too
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't understand :/
udata/models/owned.py
Outdated
''' | ||
Owned post_save handler | ||
Dispatch the `Owned.on_owner_change` signal | ||
once the document has been saved. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
including the previous owner
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 👍
|
||
class DomainModel(UDataDocument): | ||
'''Placeholder for inheritance''' | ||
pass |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Useless pass
;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just extracted from models/__init__.py
as it was. I think the only usecase is isinstance(document, DomainModel)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In that case, why not directly isinstance(document, UDataDocument)
?
This PR fix metrics not being updated after transfer for initial owner (organization or user):
models/__init__.py
into modules (models/queryset.py
,models/document.py
)Tests require #809 to pass