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
Typeclass-based object creation, validation, and authentication #1669
Conversation
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 like the consolidation of resources done here. I'm somewhat in two minds about the practice of storing these resources as class methods on the Account class:
Positives:
- It gathers those account-specific resources in a consistent way. Using
Account.validate_password
is pretty intuitive. - Storing it on the Account typeclass still allows people to override these classes (now on the Typeclass rather than on the Command as before).
Negatives:
- Nothing else in the Evennia API works like this from before.
- We already have a
create
functions in the Account manager, wrapped by theutils.create.account
function - theAccount.create
is a game-specific wrapper on top of that which confuses the matter; which one should one use? - Linking back to the first negative point - this breaks consistency with other typeclasses. You can't do
Object.create
orScript.create
, for example - the Account class becomes a discrepancy. This inconsistency does not an acceptable API do.
I can think of three possible solutions here:
- Rework this PR by storing these class functions in a new utility module. This has the advantage of minimal API change but means it becomes a lot harder or even impossible for the dev to override those functions without touching core (the reason they were in a Command in the first place)
- Consolidate all typeclasses to have a
.create
method on themselves, in the simplest form only as a wrapper of the manager method. This is a big or small API change depending on if we then considerutils.create
deprecated or not. - Keep this functionality in the Command, adding the new django-related functionality there. This is the smallest API change but pretty much removes the consolidation aspect of this PR.
I'll need to ponder this a bit but am open to discussion.
Unfortunately it depends. Whether you use Account.objects.create() or calling utils.create_account(), both are low-level calls-- you ask for an account, you get one, nothing more. It does not perform the post-creation steps currently implemented only in CmdUnconnectedCreate. As you point out, the benefit of implementing this as a class method is that if one decides they want additional steps taken (like subscribing to additional channels or granting starter bonuses) they can extend the functionality instead of having to reimplement all of it.
We could though. I just hadn't thought of that :)
I think this is the best option, but we don't really need to deprecate utils.create at all. Leave that for power users who don't want any hand-holding, while implementing friendlier and more thorough object.create() methods for the sake of easier adoption and configuration. My opinion (and part of the basis for this PR) is that a naive dev should be able to call something like object.create() and receive a default feature-complete object where possible, unless overridden or extended to do otherwise. |
@strikaco After some thinking I agree that this option is the sanest one - I think the way to go would be to add a new |
For additional consideration in support of this course of action, note that these objects already had
Looking into it, I notice that DefaultObjects are affected by the same workflow issue that led to this PR for Account objects. Wouldn't it make more sense to migrate the effective functionality of |
…ltRoom and DefaultExit.
…es DefaultAccount.authenticate_guest().
@Griatch Whenever you get a moment, I'd appreciate a quick review. Thanks! |
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.
Looking good. From a consistency perspective I think this will work well. However, since there is still no changes to the typeclass-base, other typeclassed entities like Msg and Comms will still be inconsistent as to the create
method. If we are changing the API, we need to do so consistently.
evennia/settings_default.py
Outdated
|
||
# Username validation plugins | ||
AUTH_USERNAME_VALIDATORS = [ | ||
{ |
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.
From a pure formatting perspective, we generally don't format dicts this way (javascript-like, maybe?), but tend to use a more compact form in this settings file.
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.
Is there a name for this compact style? It looks pretty but I'm unfamiliar with it and it isn't mentioned in the style guide.
How many typeclassed entities are there? I see "create_object", "create_script", "create_help_entry", "create_message", "create_channel", "create_account" listed in utils.create(). So far it seems I'm overlooking help_entry, message and channel? What should I have the typeclass base do? I can't account for custom entities or their creation path. Should I just raise a not-implemented exception? |
The base typeclasses are I mis-spoke about the While the |
I believe I've addressed the feedback to date; whenever you get a moment this is ready for review. |
@strikaco The code changes look good, but you must test your PRs against the entire test suite - it appears to pass when you run your tests in isolation, but fail when ran in combination with the rest of the Evennia test suite (and I've compared with and without this branch - the fault is introduced here). See the results from the Travis integration. |
@Griatch All bugs should be squashed; comprehensive tests pass locally but it doesn't look like Travis picked up the last commit. What now? |
...Looks like it picked it up after all. This one's ready. |
Brief overview of PR changes/additions
Motivation for adding to Evennia
Migration of logic out of Commands and into more contextually-agnostic locations.
Other info (issues closed, discussion etc)
Apologies for the torrent of changes in a single PR; once I started messing with one thing, the effects cascaded.
#1383:
#533: