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

[Bug] model put uses parent new and not child new function #255

Open
z1pti3 opened this issue Nov 20, 2021 · 0 comments
Open

[Bug] model put uses parent new and not child new function #255

z1pti3 opened this issue Nov 20, 2021 · 0 comments
Labels
bug Something isn't working
Projects
Milestone

Comments

@z1pti3
Copy link
Owner

z1pti3 commented Nov 20, 2021

When a new Item is created using the model PUT API it uses the parent new function and not the child. This prevent you from setting default values when a new item is created.

All new's should use kwargs and then model put should us the child new not the parent

model.py

newObjectID = super(type(class_), class_).new().inserted_id

This means the new secret objects have to define the token when the ENC value is first defined. It would be better if this could have been part of the new function instead. But the new function as shown does not get called.


    def new(self,acl,name,secretValue,comment=""):
        self.acl = acl
        self.name = name
        self.secretValue = secretValue
        self.comment = comment
        return super(_secret, self).new()

    def setAttribute(self,attr,value,sessionData=None):
        if attr == "secretValue" and not value.startswith("ENC "):
            if jimi.db.fieldACLAccess(sessionData,self.acl,attr,accessType="write"):
                if not self.token:
                    self.token = secrets.token_hex(128)
                    self.update(["token"])
                self.secretValue = "ENC {0}".format(jimi.auth.getENCFromPassword(value))
                return True
            return False
        return super(_secret, self).setAttribute(attr,value,sessionData=sessionData)
@z1pti3 z1pti3 added the bug Something isn't working label Nov 20, 2021
@z1pti3 z1pti3 added this to the v4.0 milestone Nov 20, 2021
@z1pti3 z1pti3 added this to Backlog in Roadmap via automation Nov 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
Roadmap
Backlog
Development

No branches or pull requests

1 participant