GitHub user johannes-ws added a comment to the discussion: How to get 
permission id for datasource access on specific dataset using Superset 5.0.0 
endpoint?

There is not <code>perm["permission_name"]</code> and 
<code>perm["view_menu_name"]</code> at 
<code>/api/v1/security/permissions-resources/</code>.

    "result": [
      {
        "id": 0,
        "permission": {
          "name": "string"
        },
        "view_menu": {
          "name": "string"
        }
      }
    ]

Responses above i copy paste from 
<code>/api/v1/security/permissions-resources/</code> at Superset API docs. But 
when i try to get <code>/api/v1/security/permissions-resources/</code>, it 
gives me this result.

    {'id': 1, 'permission': {'name': 'can_read'}, 'view_menu': {'name': 
'SavedQuery'}}
    {'id': 2, 'permission': {'name': 'can_write'}, 'view_menu': {'name': 
'SavedQuery'}}
    {'id': 3, 'permission': {'name': 'can_read'}, 'view_menu': {'name': 
'CssTemplate'}}
    {'id': 4, 'permission': {'name': 'can_write'}, 'view_menu': {'name': 
'CssTemplate'}}
    {'id': 5, 'permission': {'name': 'can_read'}, 'view_menu': {'name': 
'ReportSchedule'}}
    {'id': 6, 'permission': {'name': 'can_write'}, 'view_menu': {'name': 
'ReportSchedule'}}
    {'id': 7, 'permission': {'name': 'can_read'}, 'view_menu': {'name': 
'Chart'}}
    {'id': 8, 'permission': {'name': 'can_write'}, 'view_menu': {'name': 
'Chart'}}
    {'id': 9, 'permission': {'name': 'can_read'}, 'view_menu': {'name': 
'Annotation'}}
    {'id': 10, 'permission': {'name': 'can_write'}, 'view_menu': {'name': 
'Annotation'}}
    {'id': 11, 'permission': {'name': 'can_read'}, 'view_menu': {'name': 
'Dataset'}}
    {'id': 12, 'permission': {'name': 'can_write'}, 'view_menu': {'name': 
'Dataset'}}
    {'id': 13, 'permission': {'name': 'can_read'}, 'view_menu': {'name': 'Log'}}
    {'id': 14, 'permission': {'name': 'can_write'}, 'view_menu': {'name': 
'Log'}}
    {'id': 15, 'permission': {'name': 'can_read'}, 'view_menu': {'name': 
'Dashboard'}}
    {'id': 16, 'permission': {'name': 'can_write'}, 'view_menu': {'name': 
'Dashboard'}}
    {'id': 17, 'permission': {'name': 'can_read'}, 'view_menu': {'name': 
'Database'}}
    {'id': 18, 'permission': {'name': 'can_write'}, 'view_menu': {'name': 
'Database'}}
    {'id': 19, 'permission': {'name': 'can_read'}, 'view_menu': {'name': 
'Query'}}
    {'id': 25, 'permission': {'name': 'can_upload'}, 'view_menu': {'name': 
'Database'}}
    {'id': 26, 'permission': {'name': 'can_this_form_get'}, 'view_menu': 
{'name': 'ResetPasswordView'}}
    {'id': 27, 'permission': {'name': 'can_this_form_post'}, 'view_menu': 
{'name': 'ResetPasswordView'}}
    {'id': 28, 'permission': {'name': 'can_this_form_get'}, 'view_menu': 
{'name': 'ResetMyPasswordView'}}
    {'id': 29, 'permission': {'name': 'can_this_form_post'}, 'view_menu': 
{'name': 'ResetMyPasswordView'}}
    {'id': 30, 'permission': {'name': 'can_this_form_get'}, 'view_menu': 
{'name': 'UserInfoEditView'}}
    {'id': 31, 'permission': {'name': 'can_this_form_post'}, 'view_menu': 
{'name': 'UserInfoEditView'}}
    {'id': 32, 'permission': {'name': 'can_userinfo'}, 'view_menu': {'name': 
'UserDBModelView'}}
    {'id': 33, 'permission': {'name': 'can_show'}, 'view_menu': {'name': 
'UserDBModelView'}}
    {'id': 34, 'permission': {'name': 'can_delete'}, 'view_menu': {'name': 
'UserDBModelView'}}
    {'id': 35, 'permission': {'name': 'can_add'}, 'view_menu': {'name': 
'UserDBModelView'}}
    {'id': 36, 'permission': {'name': 'can_list'}, 'view_menu': {'name': 
'UserDBModelView'}}
    {'id': 37, 'permission': {'name': 'can_edit'}, 'view_menu': {'name': 
'UserDBModelView'}}
    {'id': 38, 'permission': {'name': 'resetmypassword'}, 'view_menu': {'name': 
'UserDBModelView'}}
    {'id': 39, 'permission': {'name': 'resetpasswords'}, 'view_menu': {'name': 
'UserDBModelView'}}
    {'id': 40, 'permission': {'name': 'userinfoedit'}, 'view_menu': {'name': 
'UserDBModelView'}}
    {'id': 41, 'permission': {'name': 'can_show'}, 'view_menu': {'name': 
'RoleModelView'}}
    {'id': 42, 'permission': {'name': 'can_delete'}, 'view_menu': {'name': 
'RoleModelView'}}
    {'id': 43, 'permission': {'name': 'can_add'}, 'view_menu': {'name': 
'RoleModelView'}}
    {'id': 44, 'permission': {'name': 'can_list'}, 'view_menu': {'name': 
'RoleModelView'}}
    {'id': 45, 'permission': {'name': 'can_edit'}, 'view_menu': {'name': 
'RoleModelView'}}
    {'id': 46, 'permission': {'name': 'copyrole'}, 'view_menu': {'name': 
'RoleModelView'}}
    {'id': 47, 'permission': {'name': 'can_show'}, 'view_menu': {'name': 
'UserGroupModelView'}}
    {'id': 48, 'permission': {'name': 'can_add'}, 'view_menu': {'name': 
'UserGroupModelView'}}
    {'id': 49, 'permission': {'name': 'can_delete'}, 'view_menu': {'name': 
'UserGroupModelView'}}
    {'id': 50, 'permission': {'name': 'can_download'}, 'view_menu': {'name': 
'UserGroupModelView'}}
    {'id': 51, 'permission': {'name': 'can_list'}, 'view_menu': {'name': 
'UserGroupModelView'}}
    {'id': 52, 'permission': {'name': 'can_edit'}, 'view_menu': {'name': 
'UserGroupModelView'}}
    {'id': 53, 'permission': {'name': 'can_get'}, 'view_menu': {'name': 
'Permission'}}
    {'id': 54, 'permission': {'name': 'can_info'}, 'view_menu': {'name': 
'Permission'}}
    {'id': 55, 'permission': {'name': 'can_list_role_permissions'}, 
'view_menu': {'name': 'Role'}}
    {'id': 56, 'permission': {'name': 'can_info'}, 'view_menu': {'name': 
'Role'}}
    {'id': 57, 'permission': {'name': 'can_update_role_users'}, 'view_menu': 
{'name': 'Role'}}
    {'id': 58, 'permission': {'name': 'can_post'}, 'view_menu': {'name': 
'Role'}}
    {'id': 59, 'permission': {'name': 'can_put'}, 'view_menu': {'name': 'Role'}}
    {'id': 60, 'permission': {'name': 'can_update_role_groups'}, 'view_menu': 
{'name': 'Role'}}
    {'id': 61, 'permission': {'name': 'can_delete'}, 'view_menu': {'name': 
'Role'}}
    {'id': 62, 'permission': {'name': 'can_add_role_permissions'}, 'view_menu': 
{'name': 'Role'}}
    {'id': 63, 'permission': {'name': 'can_get'}, 'view_menu': {'name': 'Role'}}
    {'id': 64, 'permission': {'name': 'can_info'}, 'view_menu': {'name': 
'User'}}
    {'id': 65, 'permission': {'name': 'can_post'}, 'view_menu': {'name': 
'User'}}
    {'id': 66, 'permission': {'name': 'can_put'}, 'view_menu': {'name': 'User'}}
    {'id': 67, 'permission': {'name': 'can_delete'}, 'view_menu': {'name': 
'User'}}
    {'id': 68, 'permission': {'name': 'can_get'}, 'view_menu': {'name': 'User'}}
    {'id': 69, 'permission': {'name': 'can_info'}, 'view_menu': {'name': 
'ViewMenu'}}
    {'id': 70, 'permission': {'name': 'can_post'}, 'view_menu': {'name': 
'ViewMenu'}}
    {'id': 71, 'permission': {'name': 'can_put'}, 'view_menu': {'name': 
'ViewMenu'}}
    {'id': 72, 'permission': {'name': 'can_delete'}, 'view_menu': {'name': 
'ViewMenu'}}
    {'id': 73, 'permission': {'name': 'can_get'}, 'view_menu': {'name': 
'ViewMenu'}}
    {'id': 74, 'permission': {'name': 'can_info'}, 'view_menu': {'name': 
'PermissionViewMenu'}}
    {'id': 75, 'permission': {'name': 'can_post'}, 'view_menu': {'name': 
'PermissionViewMenu'}}
    {'id': 76, 'permission': {'name': 'can_put'}, 'view_menu': {'name': 
'PermissionViewMenu'}}
    {'id': 77, 'permission': {'name': 'can_delete'}, 'view_menu': {'name': 
'PermissionViewMenu'}}
    {'id': 78, 'permission': {'name': 'can_get'}, 'view_menu': {'name': 
'PermissionViewMenu'}}
    {'id': 79, 'permission': {'name': 'can_info'}, 'view_menu': {'name': 
'Group'}}
    {'id': 80, 'permission': {'name': 'can_post'}, 'view_menu': {'name': 
'Group'}}
    {'id': 81, 'permission': {'name': 'can_put'}, 'view_menu': {'name': 
'Group'}}
    {'id': 82, 'permission': {'name': 'can_delete'}, 'view_menu': {'name': 
'Group'}}
    {'id': 83, 'permission': {'name': 'can_get'}, 'view_menu': {'name': 
'Group'}}
    {'id': 84, 'permission': {'name': 'can_get'}, 'view_menu': {'name': 
'OpenApi'}}
    {'id': 85, 'permission': {'name': 'can_show'}, 'view_menu': {'name': 
'SwaggerView'}}
    {'id': 86, 'permission': {'name': 'can_get'}, 'view_menu': {'name': 
'MenuApi'}}
    {'id': 87, 'permission': {'name': 'can_list'}, 'view_menu': {'name': 
'AsyncEventsRestApi'}}
    {'id': 88, 'permission': {'name': 'can_read'}, 'view_menu': {'name': 
'AdvancedDataType'}}
    {'id': 89, 'permission': {'name': 'can_read'}, 'view_menu': {'name': 
'AvailableDomains'}}
    {'id': 90, 'permission': {'name': 'can_invalidate'}, 'view_menu': {'name': 
'CacheRestApi'}}
    {'id': 91, 'permission': {'name': 'can_warm_up_cache'}, 'view_menu': 
{'name': 'Chart'}}
    {'id': 92, 'permission': {'name': 'can_export'}, 'view_menu': {'name': 
'Chart'}}
    {'id': 93, 'permission': {'name': 'can_write'}, 'view_menu': {'name': 
'DashboardFilterStateRestApi'}}
    {'id': 94, 'permission': {'name': 'can_read'}, 'view_menu': {'name': 
'DashboardFilterStateRestApi'}}
    {'id': 95, 'permission': {'name': 'can_write'}, 'view_menu': {'name': 
'DashboardPermalinkRestApi'}}
    {'id': 96, 'permission': {'name': 'can_read'}, 'view_menu': {'name': 
'DashboardPermalinkRestApi'}}
    {'id': 97, 'permission': {'name': 'can_export'}, 'view_menu': {'name': 
'Dashboard'}}
    {'id': 98, 'permission': {'name': 'can_get_embedded'}, 'view_menu': 
{'name': 'Dashboard'}}
    {'id': 99, 'permission': {'name': 'can_delete_embedded'}, 'view_menu': 
{'name': 'Dashboard'}}
    {'id': 100, 'permission': {'name': 'can_cache_dashboard_screenshot'}, 
'view_menu': {'name': 'Dashboard'}}
    {'id': 101, 'permission': {'name': 'can_set_embedded'}, 'view_menu': 
{'name': 'Dashboard'}}
    {'id': 102, 'permission': {'name': 'can_export'}, 'view_menu': {'name': 
'Database'}}
    {'id': 103, 'permission': {'name': 'can_export'}, 'view_menu': {'name': 
'Dataset'}}
    {'id': 104, 'permission': {'name': 'can_duplicate'}, 'view_menu': {'name': 
'Dataset'}}
    {'id': 105, 'permission': {'name': 'can_warm_up_cache'}, 'view_menu': 
{'name': 'Dataset'}}

There is not permission.name "datasource_access" and view_menu.name 
perm_string. This is my code.

    def get_permissions_id(session, base_url, perm_string):
        permissions_url = f"{base_url}/api/v1/security/permissions-resources/"
        params = {"q": json.dumps({"page_size": -1})}

        try:
            response = session.get(permissions_url, params=params)
            response.raise_for_status()

            try:
                data = response.json()
            except ValueError:
                logger.error(f"Response is not valid JSON: {response.text}")
                return None

            for perm in data['result']:
                if perm['permission']['name'] == "datasource_access" and 
perm['view_menu']['name'] == perm_string:
                    permission_id = perm['id']
                    logger.info(f"Permission '{perm_string}' found with ID: 
{permission_id}")
                    return permission_id

            logger.warning(f"Permission '{perm_string}' not found.")
            return None

        except requests.exceptions.HTTPError as http_err:
            logger.error(f"HTTP error occurred while fetching permissions ID: 
{http_err} - {response.text}")
        except requests.exceptions.RequestException as req_err:
            logger.error(f"Request error occurred while fetching permissions 
ID: {req_err}")
        except Exception as err:
            logger.exception(f"Unexpected error while fetching permissions ID: 
{err}")

        return None

Is this bug or not? @dosu 

GitHub link: 
https://github.com/apache/superset/discussions/34571#discussioncomment-14017605

----
This is an automatically sent email for notifications@superset.apache.org.
To unsubscribe, please send an email to: 
notifications-unsubscr...@superset.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@superset.apache.org
For additional commands, e-mail: notifications-h...@superset.apache.org

Reply via email to