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

get_available_layers_rpc function is returning an empty row #40

Open
jsmueller7 opened this issue Dec 6, 2024 · 0 comments
Open

get_available_layers_rpc function is returning an empty row #40

jsmueller7 opened this issue Dec 6, 2024 · 0 comments

Comments

@jsmueller7
Copy link

jsmueller7 commented Dec 6, 2024

The function get_available_layers_rpc, which is called every time the client opens an annotation szession, often returns an emtpy first row. It depends; sometimes this behavior isn't shown.

In the function code below the RETURN NEXT statement right after the policy check should be a simple RETURN. This way no empty rows are returned. Also the function will not return any information if the policy check fails (at the moment the policy check is ineffective).

DECLARE
    _context_name     VARCHAR;
    _document_id      uuid;
    _contexts_row      public.contexts % rowtype;
    _layer_context_row  public.layer_contexts % rowtype;
    _layer_row        public.layers % rowtype;
BEGIN

    -- Check project policy that contexts can be selected by this user
    IF NOT (check_action_policy_organization(auth.uid(), 'contexts', 'SELECT') 
      OR check_action_policy_project(auth.uid(), 'contexts', 'SELECT', _project_id)) 
    THEN
      RETURN NEXT;
    END IF;  

    -- Find all documents in the current context
    FOR _document_id IN SELECT pd.document_id 
      FROM public.project_documents pd WHERE pd.project_id = _project_id AND pd.is_archived IS NOT TRUE
    LOOP
      FOR _contexts_row IN SELECT * FROM public.contexts c
        WHERE c.project_id = _project_id
      LOOP
        FOR _layer_context_row IN SELECT * FROM public.layer_contexts lcx
          WHERE lcx.context_id = _contexts_row.id AND lcx.is_archived IS NOT TRUE
        LOOP
          FOR _layer_row IN SELECT * FROM public.layers l 
            WHERE l.id = _layer_context_row.layer_id AND l.document_id = _document_id AND l.is_archived IS NOT TRUE
          LOOP
            document_id := _document_id;
            context_id := _contexts_row.id;
            is_active := _layer_context_row.is_active_layer;
            layer_id := _layer_row.id;
            context_name := _contexts_row.name;
            RETURN NEXT;
          END LOOP;
        END LOOP; 
      END LOOP;
    END LOOP; 
END
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant