
    h.                     
   d dl Z d dlmZ d dlmZ  e j
                  de      Zdededefd	Zdedede j                  e j                  e      fd
Zddede j                  e   ddfdZdedede j                  e   ddfdZy)    N)cache)Model	UserModel)bounduser
permissionreturnc                     d| S )a  
    Generates a unique cache key for a given user and permission.

    The key is a string in the format "filer:perm:<permission>", i.e. it does not
    contain the user id. This will be sufficient for most use cases.

    Patch this method to include the user id in the cache key if necessary, e.g.,
    for far more than 1,000 admin users to make the cached unit require less memory.

    Parameters:
    user (UserModel): The user for whom the cache key is being generated.
        The `user` can be an instance of the default `django.contrib.auth.models.User`
        or any custom user model specified by `AUTH_USER_MODEL` in the settings.
    permission (str): The permission for which the cache key is being generated.

    Returns:
    str: The generated cache key.
    zfiler:perm: )r   r   s     ;/home/dcms/DCMS/lib/python3.12/site-packages/filer/cache.pyget_folder_perm_cache_keyr   
   s    & %%    c                 ~    t        j                  t        | |            }|r|j                  | j                  d      S y)a  
    Retrieves the cached folder permissions for a given user and permission.

    If the cache value exists, it returns the permissions for the user.
    If the cache value does not exist, it returns None.

    Parameters:
    user (UserModel): The user for whom the permissions are being retrieved.
        The `user` can be an instance of the default `django.contrib.auth.models.User`
        or any custom user model specified by `AUTH_USER_MODEL` in the settings.
    permission (str): The permission for which the permissions are being retrieved.

    Returns:
    set or None: The permissions for the user, or None if no cache value exists.
    N)r   getr   pk)r   r   cache_values      r   get_folder_permission_cacher       s5      ))5dJGHKtww--r   c                     |'dD ]!  }t        j                  t        | |             # yt        j                  t        | |             y)aE  
    Clears the cached folder permissions for a given user.

    If a specific permission is provided, it clears the cache for that permission only.
    If no specific permission is provided, it clears the cache for all permissions.

    Parameters:
    user (UserModel): The user for whom the permissions are being cleared.
        The `user` can be an instance of the default `django.contrib.auth.models.User`
        or any custom user model specified by `AUTH_USER_MODEL` in the settings.
    permission (str, optional): The specific permission to clear. Defaults to None.
    N)can_readcan_editcan_add_children)r   deleter   )r   r   perms      r   clear_folder_permission_cacher   6   sE     @ 	@DLL24>?	@ 	.tZ@Ar   id_listc                     t        j                  t        | |            xs i }t        |      || j                  <   t        j                  t        | |      |       y)a  
    Updates the cached folder permissions for a given user and permission.

    It first retrieves the current permissions from the cache (or an empty dictionary if none exist).
    Then it updates the permissions for the user with the provided list of IDs.
    Finally, it sets the updated permissions back into the cache.

    Parameters:
    user (UserModel): The user for whom the permissions are being updated.
        The `user` can be an instance of the default `django.contrib.auth.models.User`
        or any custom user model specified by `AUTH_USER_MODEL` in the settings.
    permission (str): The permission to update.
    id_list (set): The set of IDs to set as the new permissions.
    N)r   r   r   setr   )r   r   r   permss       r   update_folder_permission_cacher   J   sF     II/jABHbE\E$''N	II'j95Ar   )N)typingdjango.core.cacher   django.db.modelsr   TypeVarr   strr   OptionalSetintr   r   r   r   r   r   <module>r(      s     # " FNN;e4	&I &3 &3 &,i S V__U[U_U_`cUdEe ,B	 Bvs?S B_c B(B B BfjjY\o Bbf Br   