-
Notifications
You must be signed in to change notification settings - Fork 2.2k
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
Adding optional audit meta fields to track createdBy/updatedBy user #490
Adding optional audit meta fields to track createdBy/updatedBy user #490
Conversation
I decided to refactor this feature into a more testable code. I encapsulated all the functionality into a I also added a unit test for the feature. Unaware of any existing naming convention for Keystone unit tests, I simply named it |
+1 |
First off, big thanks to @JohnnyEstilles for wrapping this up and sharing it. It's an important thing to add to Keystone, and this is a good way to do it. I wanted to raise some alternative ideas for discussion, because I think we should do this once and right so that when others build on it, it's our best foot forward. Then I propose we either merge this, or implement an alternative solution quickly (which would also build on #514). I'm not sure that I think a better way of doing it is:
I think I also haven't made it We could specify alternative paths for each of the 4 fields this would add to the schema by setting the options to a var Test = new keystone.List('Test', { This would allow backwards compatibility with the current Internally, we may use the For background: the idea behind Once this has been sorted out, we should add it into the Admin UI really nicely; it's currently completely missing (in part because I've been reluctant to build more momentum behind the current implementation, because of the ideas above). |
@JedWatson, I completely agree. The one and only reason I used As a matter of fact, my original implementation uses options with names almost identical to the ones you suggested (except I called mine
... and, the ability to specify user-defined fields ...
The reason I used Now that I understand your intentions my suggested course of action is to rescind this PR and submit a new one implemented as follows:
Regarding this last point and the use of mappings. I understand that use cases like this was not your intended purpose. However, the existing mappings functionality allow us to develop new features (like this one) which alter field names in favor of more intelligible and less ambiguous ones (e.g. Let me know what you think. |
I like the latest suggestions... any magic (of mappings I'd say, rescind 514 too. :) |
Just waiting on @JedWatson's green light to go ahead with the plan. |
Actually, I incorrectly made this the "Keystone way" to do this, have been trying to work out how to roll it back without breaking compatibility since... sorry about that. You've been heading in the right direction all along, I just needed to get my thoughts clearer on it.
Yup, me too, with a clearer purpose though. At the moment, it's designed to take a "conceptual" path that internal Keystone features (including the Admin UI) can understand, like The thing I think I got wrong, was it automaps any field added to the schema to any "mapped" path. Really, it should go the other way - plugins ( I think special (mapped) fields shouldn't show up in the main Item Details form in the Admin UI, they should be handled specifically (as To round this out, we should roll the handling of Green Light I'll merge #514 now - this is a neat way of automating a common use of it, but I think it stands on its own as a feature, too. Then:
re: Then: Tests and add the new options to the docs. Let's do this :) |
Sounds like a plan! I'm on it! :-) |
Rescinding pull request. |
I submitted a new PR (#523) adding the List |
…-option Adding List 'track' option (replaces #490)
After reading the comments on #458 I remembered that I had implemented this several months ago, so I decided to share it with you all.
My implementation consists of an optional
audit meta
pattern that can be added to theList
object (mirroring the existingstandard meta
pattern implementation).The option is enabled as follows:
This adds two fields to
List
(createdBy
andupdatedBy
). I used these names to mirror thecreatedOn
andupdatedOn
fields added by thestandard pattern
. Both fields are of typeRelationship
and they both refer to the model defined in the Keystoneuser model
option.This is how I implemented it.
lib/list.js
standard meta
fields (if they dont' already exists)createdBy
andupdatedBy
Relationship fields withref
pointing tokeystone.get('user model')
createdBy
andupdatedBy
fields to the existingcreatedBy
andmodifiedBy
mappings (I personally would have preferred using the same names as their respective fields, but I decided to use the two existing mappings ... which oddly appear to be unused elsewhere in Keystone).NOTE: The idea of using the mappings is to give developers the option to implement their own
createdBy
and/ormodifiedBy
fields, while still using the originalstandard meta
(if they so desire). Below is a somewhat silly example, but I'm sure it gets the point across.lib/updateHandler.js
createdBy
mapping, and if one exists I set the corresponding mapped field touser._id
(which was cached earlier usingreq.user
in theUpdateHandler()
constructor), but only whenitem.isNew
.modifiedBy
mapping, and if one exists I set the corresponding mapped field touser._id
That's it! And ... as usual ... feel free to tweak away!