Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
    Jordi Collell
    @jordic
    are all parents of an object stored on the index metadata?
    a
    Ramon Navarro Bosch
    @bloodbare
    yups on the path index
    Jordi Collell
    @jordic
    @bloodbare I think the guillotina mailer is not transaction aware. perhaps it should provide a safe send where the email is sent after request.
    Ramon Navarro Bosch
    @bloodbare
    @jordic looking forward for a PR !
    we are also waiting for the users integration
    we should freeze funcitonality with a beta version soon otherwise its complex to keep our codes up to date
    Jordi Collell
    @jordic
    haha. still a bit blocked with catalog query (if we can ommit this is ready to be merged). the main problem is that we are providing plone compat theought the serializer.. (that is not callable from a catalog query)
    Ramon Navarro Bosch
    @bloodbare
    whats the problem with the catalog query ? you can query anything with the protocol: https://docs.google.com/document/d/1xooubzJKBnUzVlsa2f0GSwvuE1oir9hUdWUf1SU9S6E/edit
    Jordi Collell
    @jordic
    yeah i know.. but we are providing compat for plone throught the user serializer.
    Ramon Navarro Bosch
    @bloodbare
    Jordi Collell
    @jordic
    I have two options (if we want to implement it throught catalog)A. update the content type. B apply the transorm in the catalog result (that doesn't make sense for me)
    C. Discard the catalog query
    Ramon Navarro Bosch
    @bloodbare
    Searching for users can be done at the query, serialization with the objects, in this case the accesscontent permission is enough to understand if you can see the user “searchable information"
    isn’t it ?
    Jordi Collell
    @jordic
    yes. that's not the problem
    Sri Harsha Gangisetty
    @harwee
    Hello, I am trying to add custom permissions to a content type to update/delete/add the type
    I have created all the permissions and roles to do this, according to the docs I can provide add permissions by using add_permission but how can i explicitly define edit and delete permissions?
    Below is my current implementation
    image.png
    Nathan Van Gheem
    @vangheem
    you would need to override the services for PATCH/DELETE
    I would recommend using local permisison to assign roles to users you want to be able to do these actions
    instead of trying to use custom permissions on each of those
    Sri Harsha Gangisetty
    @harwee
    So it's more like create custom roles and add already existing permissions to the custom roles right?
    Thanks! I think using local permissions is the easiest way to do things.
    Sri Harsha Gangisetty
    @harwee
    Also I am using guillotina_dbusers to create and manage users.
    I am trying to get/create and authenticate the user inside a middleware. But I cannot figure out how to create/get the user from database directly instead of posting the endpoint /db/container/users
    Nathan Van Gheem
    @vangheem
    that's difficult I guess as you don't know what db/container the request is meant for necessarily yet in middleware
    what are you trying to do in the middleware?
    Sri Harsha Gangisetty
    @harwee
    I am using a CAS to maintain all the user accounts, CAS grants access tokens to applications using OIDC protocol. The frontend then queries its backend (guillotina) with the access token provided by CAS. now using this access token I am verifying (inside middleware) if the user corresponding to the access token exists on guillotina and authenticate the user, if the user does not exists create the user and then authenticate.
    Nathan Van Gheem
    @vangheem
    why not use guillotina auth instead of middleware?
    I imagine all you need to do is write a validator
    add to auth_token_validators configuration
    Sri Harsha Gangisetty
    @harwee
    I checked oauth implementation earlier, it don't think it stores user inside the database, does it?
    Nathan Van Gheem
    @vangheem
    it doesn't matter where the users are stored
    do your validation and then just call user = await find_user(self.request, token) like the other validators do
    Sri Harsha Gangisetty
    @harwee

    I tried what you suggested, it mimics the behavior of oauth implementation. If i have I have to delegate all the roles/permission management to CAS, so I have been trying to implement something like this

        original_write_state = bool(self.request._db_write_enabled)
        self.request._db_write_enabled = True
        _, _, user_container = await get_user_container(self.request)
    
        ## 
        user_context = await user_container.async_get("users") ## user_container equals Container at /db/user
        user_id = user_info.pop("uuid").replace("-","")
        options = {
            "_p_oid": user_id
        }
        user = await user_context.async_get(user_id)
        print(user) ## always None
        if not user:
            user = await create_content_in_container(user_context, "User", user_id, request=self.request, check_security=False, **options)
            user.add_behavior("guillotina.behaviors.dublincore.IDublinCore")
            deserializer = query_multi_adapter((user, self.request), IResourceDeserializeFromJson)
            await deserializer(user_info, validate_all=True, create=True)
        self.request._db_write_enabled = bool(original_write_state)
        print(user)  ## Prints object

    This is the print output when I query any api, it first tries to check if a user by id exists and is always None and then

        None
        < User at /user/users/b3812586d5cb479185492b2cd75b70b3 by 139998936343752 >
        None
        < User at /user/users/b3812586d5cb479185492b2cd75b70b3 by 139998936345544 >
        None
        < User at /user/users/b3812586d5cb479185492b2cd75b70b3 by 139998925460168 >

    User content type object gets created but is not persisted into the database, is there anything wrong with this code?

    Nathan Van Gheem
    @vangheem

    @harwee can you try it with managed_transaction? Even if you try overriding write enabled, it still will not attempt to commit at request end for none write requests(GET, OPTIONS, etc).

    Can you see if something like this works?

    from guillotina.transactions import managed_transaction
    
    _, _, user_container = await get_user_container(self.request)
    user_context = await user_container.async_get("users") ## user_container equals Container at /db/user
    user_id = user_info.pop("uuid").replace("-","")
    options = {
        "_p_oid": user_id,  # unique object id across entire db
        "id": user_id  # id is unique in folder/part of path
    }
    user = await user_context.async_get(user_id)
    print(user) ## always None
    if user: is None
        async with managed_transaction(request=self.request, write=True, adopt_parent_txn=True):
            user = await create_content_in_container(user_context, "User", user_id, request=self.request, check_security=False, **options)
            user.add_behavior("guillotina.behaviors.dublincore.IDublinCore")
    print(user)  ## Prints object
    Sri Harsha Gangisetty
    @harwee
    @vangheem I think it's the problem with not able to write to db during GET, OPTIONS request, your solution worked! Thankyou
    Nathan Van Gheem
    @vangheem
    @bloodbare ^^ this is a reminder of things we need to make sure are documented in guillotina 5 releases. All this is much easier to work with; however, we need to document it...
    Ramon Navarro Bosch
    @bloodbare
    @vangheem agree, sorry I’m still on moving mode
    Alek Kowalczyk
    @alex-kowalczyk
    What is a best way to perform schema migrations?
    Also, is there any schema generator I could use to generate classes based on existing DB schema?
    Nathan Van Gheem
    @vangheem

    @alex-kowalczyk easiest way is to just write a script to convert/move or do whatever you need to do with the data.

    You can run scripts like this::

    async def run(container):
        ob = await navigate_to(container, 'my/object')
        ob.foo = ob.bar
        del ob.bar

    then
    g run --script=myscript.py

    But it depends on what you are trying to do. Guillotina behaves like a nosql db so you are able to write code to lazy migrate data. Even if you remove a schema field, the data is still stored on the object and you can still have access to it.

    I'm not aware of a way to generate schemas; however, you can utilize the JSONField(https://guillotina.readthedocs.io/en/latest/api/fields.html#guillotina.schema.JSONField) to do things in a way that do not require writing python classes.

    Jordi Masip
    @masipcat_gitlab
    Hi @alex-kowalczyk , at Vinissimus we've built guillotina_evolution (https://github.com/vinissimus/guillotina_evolution) to solve this! It's similar to @vangheem 's solution but it keeps track the which generation is each container so you don't have to take care of which migrations you need to run, just run guillotina g-evolve.
    Nathan Van Gheem
    @vangheem
    @masipcat_gitlab really cool!
    Alek Kowalczyk
    @alex-kowalczyk
    @masipcat_gitlab @vangheem Thank you!
    Md Nazrul Islam
    @nazrulworld
    Hi @/all
    How can I get all registered content-types? Is there already helper function?
    Md Nazrul Islam
    @nazrulworld
    Thanks all, got the way
    Nathan Van Gheem
    @vangheem
    Sorry, I missed your message!
    Md Nazrul Islam
    @nazrulworld
    @vangheem it's OK :) 👍
    Facundo J Gonzalez
    @gonzalezfj
    Hi guys