Update project folder permission settings

VickeyC
VickeyC Registered Posts: 27 ✭✭✭✭

Please share the Python code for updating project folder permission settings.


Operating system used: RHEL 7.9

Best Answer

  • Sergey
    Sergey Dataiker, Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS Core Concepts Posts: 365 Dataiker
    edited July 17 Answer ✓

    Ok, thanks. Sorry, I have missed that you are doing the direct permission assignment by replacing the existing variable. This will not work. You need to append new permissions to the array you got from get_permissions() function:

    pf_settings = new_project_folder.get_settings()
    pf_permissions = pf_settings.get_permissions()
    
    new_permission = {'group': MyProjectGroup, 'read': True, 'writeContents': True, 'admin': False}
    
    pf_permissions.append(new_permission)
    pf_settings.save()

Answers

  • Sergey
    Sergey Dataiker, Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS Core Concepts Posts: 365 Dataiker
    edited July 17

    Hi @VickeyC

    We have a good starting sample in our docs:

    https://doc.dataiku.com/dss/latest/python-api/project-folders.html#modifying-settings

    You just need to get a project folder id:

    prj_folder = client.get_project_folder(prj_folder_id)

    and update the permissions either by modifying dictionaries containing existing permissions, or adding new/removing old ones.

  • VickeyC
    VickeyC Registered Posts: 27 ✭✭✭✭

    @sergeyd
    Yes, I'm very familiar with that page. The missing link for me is the format of the new permissions. What exactly would the code look like? I've tried this on a folder with no permissions defined:

    prj_folder = client.get_project_folder(new_project_folder.id)
    pf_settings = prj_folder.get_settings()

    pf_settings.permissions = [{'group=MyProjectGroup', 'read=True', 'writeContents=True'}]

    The python code executes without errors, but the folder still doesn't have any permissions. What am I doing wrong? Note that MyProjectGroup is a variable

  • Sergey
    Sergey Dataiker, Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS Core Concepts Posts: 365 Dataiker
    edited July 17

    Variables are fine. The issue here is that you are passing over not dictionary "key:values" pairs but just assigning variables.

    Here is what you should have instead:

    pf_settings.permissions = [{'group': MyProjectGroup, 'read': True, 'writeContents': True, 'admin': True}]

  • VickeyC
    VickeyC Registered Posts: 27 ✭✭✭✭

    @sergeyd
    Thanks for that info.

    Unfortunately, my folder permissions are still not being updated. Here's my code:

    root_folder = client.get_root_project_folder()
    root_children = root_folder.list_child_folders()
    new_project_folder_name = projectName

    folder_exists = False
    for i in root_children:
    if i.name == new_project_folder_name:
    new_project_folder_id = i.id
    folder_exists = True

    # Create the project folder if it doesn't already exist
    if not folder_exists:
    new_project_folder = root_folder.create_sub_folder(new_project_folder_name)

    # Update the project folder settings and permissions
    pf_settings = new_project_folder.get_settings()
    pf_permissions = pf_settings.get_permissions()

    pf_settings.permissions = [{'group': MyProjectGroup, 'read': True, 'writeContents': True, 'admin': False}]
    pf_settings.save()

    What can I do differently to make this work? The save function doesn't seem to save anything.

  • Sergey
    Sergey Dataiker, Dataiku DSS Core Designer, Dataiku DSS & SQL, Dataiku DSS Core Concepts Posts: 365 Dataiker

    Hm...where do you define your MyProjectGroup variable in the code?

  • VickeyC
    VickeyC Registered Posts: 27 ✭✭✭✭

    @sergeyd
    It's there in an earlier part of the code. Here's what it looks like:

    MyProjectGroup = "my_project_group"

  • VickeyC
    VickeyC Registered Posts: 27 ✭✭✭✭

    I have it working now, thanks!

Setup Info
    Tags
      Help me…