Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
dscc-admin-ch committed Jul 12, 2024
1 parent e6057d6 commit c05904c
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@

<h1>Source code for lomas_server.admin_database.admin_database</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">argparse</span>
<span class="kn">import</span> <span class="nn">functools</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">from</span> <span class="nn">abc</span> <span class="kn">import</span> <span class="n">ABC</span><span class="p">,</span> <span class="n">abstractmethod</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">wraps</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Callable</span><span class="p">,</span> <span class="n">Dict</span><span class="p">,</span> <span class="n">List</span>

<span class="kn">from</span> <span class="nn">constants</span> <span class="kn">import</span> <span class="n">MODEL_INPUT_TO_LIB</span>
Expand Down Expand Up @@ -123,7 +123,7 @@ <h1>Source code for lomas_server.admin_database.admin_database</h1><div class="h
<span class="sd"> before calling func.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="nd">@functools</span><span class="o">.</span><span class="n">wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="nd">@wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">wrapper_decorator</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">:</span> <span class="n">argparse</span><span class="o">.</span><span class="n">Namespace</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
Expand Down Expand Up @@ -158,14 +158,14 @@ <h1>Source code for lomas_server.admin_database.admin_database</h1><div class="h
<span class="sd"> before calling the wrapped function.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="nd">@functools</span><span class="o">.</span><span class="n">wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="nd">@wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">wrapper_decorator</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">:</span> <span class="n">argparse</span><span class="o">.</span><span class="n">Namespace</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">dataset_name</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">does_dataset_exist</span><span class="p">(</span><span class="n">dataset_name</span><span class="p">):</span>
<span class="k">raise</span> <span class="n">InvalidQueryException</span><span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;Dataset </span><span class="si">{</span><span class="n">dataset_name</span><span class="si">}</span><span class="s2"> does not exists. &quot;</span>
<span class="sa">f</span><span class="s2">&quot;Dataset </span><span class="si">{</span><span class="n">dataset_name</span><span class="si">}</span><span class="s2"> does not exist. &quot;</span>
<span class="o">+</span> <span class="s2">&quot;Please, verify the client object initialisation.&quot;</span><span class="p">,</span>
<span class="p">)</span>
<span class="k">return</span> <span class="n">func</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
Expand Down Expand Up @@ -197,7 +197,7 @@ <h1>Source code for lomas_server.admin_database.admin_database</h1><div class="h
<span class="sd"> to the dataset before calling the wrapped function.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="nd">@functools</span><span class="o">.</span><span class="n">wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="nd">@wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">wrapper_decorator</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">:</span> <span class="n">argparse</span><span class="o">.</span><span class="n">Namespace</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ <h1>Source code for lomas_server.admin_database.mongodb_database</h1><div class=
<span class="n">user_must_exist</span><span class="p">,</span>
<span class="n">user_must_have_access_to_dataset</span><span class="p">,</span>
<span class="p">)</span>
<span class="kn">from</span> <span class="nn">utils.error_handler</span> <span class="kn">import</span> <span class="n">InvalidQueryException</span>


<div class="viewcode-block" id="AdminMongoDatabase">
Expand Down Expand Up @@ -246,6 +247,11 @@ <h1>Source code for lomas_server.admin_database.mongodb_database</h1><div class=
<span class="sd"> Returns:</span>
<span class="sd"> bool: True if the user has access, False otherwise.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">does_dataset_exist</span><span class="p">(</span><span class="n">dataset_name</span><span class="p">):</span>
<span class="k">raise</span> <span class="n">InvalidQueryException</span><span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;Dataset </span><span class="si">{</span><span class="n">dataset_name</span><span class="si">}</span><span class="s2"> does not exist. &quot;</span>
<span class="o">+</span> <span class="s2">&quot;Please, verify the client object initialisation.&quot;</span><span class="p">,</span>
<span class="p">)</span>
<span class="n">doc_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">users</span><span class="o">.</span><span class="n">count_documents</span><span class="p">(</span>
<span class="p">{</span>
<span class="s2">&quot;user_name&quot;</span><span class="p">:</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">user_name</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ <h1>Source code for lomas_server.admin_database.yaml_database</h1><div class="hi
<span class="n">user_must_exist</span><span class="p">,</span>
<span class="n">user_must_have_access_to_dataset</span><span class="p">,</span>
<span class="p">)</span>
<span class="kn">from</span> <span class="nn">utils.error_handler</span> <span class="kn">import</span> <span class="n">InternalServerException</span>
<span class="kn">from</span> <span class="nn">utils.error_handler</span> <span class="kn">import</span> <span class="n">InternalServerException</span><span class="p">,</span> <span class="n">InvalidQueryException</span>


<div class="viewcode-block" id="AdminYamlDatabase">
Expand Down Expand Up @@ -254,6 +254,11 @@ <h1>Source code for lomas_server.admin_database.yaml_database</h1><div class="hi
<span class="sd"> Returns:</span>
<span class="sd"> bool: True if the user has access, False otherwise.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">does_dataset_exist</span><span class="p">(</span><span class="n">dataset_name</span><span class="p">):</span>
<span class="k">raise</span> <span class="n">InvalidQueryException</span><span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;Dataset </span><span class="si">{</span><span class="n">dataset_name</span><span class="si">}</span><span class="s2"> does not exist. &quot;</span>
<span class="o">+</span> <span class="s2">&quot;Please, verify the client object initialisation.&quot;</span><span class="p">,</span>
<span class="p">)</span>
<span class="k">for</span> <span class="n">user</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">database</span><span class="p">[</span><span class="s2">&quot;users&quot;</span><span class="p">]:</span>
<span class="k">if</span> <span class="n">user</span><span class="p">[</span><span class="s2">&quot;user_name&quot;</span><span class="p">]</span> <span class="o">==</span> <span class="n">user_name</span><span class="p">:</span>
<span class="k">for</span> <span class="n">dataset</span> <span class="ow">in</span> <span class="n">user</span><span class="p">[</span><span class="s2">&quot;datasets_list&quot;</span><span class="p">]:</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@

<h1>Source code for lomas_server.admin_database.admin_database</h1><div class="highlight"><pre>
<span></span><span class="kn">import</span> <span class="nn">argparse</span>
<span class="kn">import</span> <span class="nn">functools</span>
<span class="kn">import</span> <span class="nn">time</span>
<span class="kn">from</span> <span class="nn">abc</span> <span class="kn">import</span> <span class="n">ABC</span><span class="p">,</span> <span class="n">abstractmethod</span>
<span class="kn">from</span> <span class="nn">functools</span> <span class="kn">import</span> <span class="n">wraps</span>
<span class="kn">from</span> <span class="nn">typing</span> <span class="kn">import</span> <span class="n">Callable</span><span class="p">,</span> <span class="n">Dict</span><span class="p">,</span> <span class="n">List</span>

<span class="kn">from</span> <span class="nn">constants</span> <span class="kn">import</span> <span class="n">MODEL_INPUT_TO_LIB</span>
Expand Down Expand Up @@ -123,7 +123,7 @@ <h1>Source code for lomas_server.admin_database.admin_database</h1><div class="h
<span class="sd"> before calling func.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="nd">@functools</span><span class="o">.</span><span class="n">wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="nd">@wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">wrapper_decorator</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">:</span> <span class="n">argparse</span><span class="o">.</span><span class="n">Namespace</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
Expand Down Expand Up @@ -158,14 +158,14 @@ <h1>Source code for lomas_server.admin_database.admin_database</h1><div class="h
<span class="sd"> before calling the wrapped function.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="nd">@functools</span><span class="o">.</span><span class="n">wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="nd">@wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">wrapper_decorator</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">:</span> <span class="n">argparse</span><span class="o">.</span><span class="n">Namespace</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
<span class="n">dataset_name</span> <span class="o">=</span> <span class="n">args</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">does_dataset_exist</span><span class="p">(</span><span class="n">dataset_name</span><span class="p">):</span>
<span class="k">raise</span> <span class="n">InvalidQueryException</span><span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;Dataset </span><span class="si">{</span><span class="n">dataset_name</span><span class="si">}</span><span class="s2"> does not exists. &quot;</span>
<span class="sa">f</span><span class="s2">&quot;Dataset </span><span class="si">{</span><span class="n">dataset_name</span><span class="si">}</span><span class="s2"> does not exist. &quot;</span>
<span class="o">+</span> <span class="s2">&quot;Please, verify the client object initialisation.&quot;</span><span class="p">,</span>
<span class="p">)</span>
<span class="k">return</span> <span class="n">func</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">)</span>
Expand Down Expand Up @@ -197,7 +197,7 @@ <h1>Source code for lomas_server.admin_database.admin_database</h1><div class="h
<span class="sd"> to the dataset before calling the wrapped function.</span>
<span class="sd"> &quot;&quot;&quot;</span>

<span class="nd">@functools</span><span class="o">.</span><span class="n">wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="nd">@wraps</span><span class="p">(</span><span class="n">func</span><span class="p">)</span>
<span class="k">def</span> <span class="nf">wrapper_decorator</span><span class="p">(</span>
<span class="bp">self</span><span class="p">,</span> <span class="o">*</span><span class="n">args</span><span class="p">:</span> <span class="n">argparse</span><span class="o">.</span><span class="n">Namespace</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">:</span> <span class="n">Dict</span><span class="p">[</span><span class="nb">str</span><span class="p">,</span> <span class="nb">str</span><span class="p">]</span>
<span class="p">)</span> <span class="o">-&gt;</span> <span class="kc">None</span><span class="p">:</span>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ <h1>Source code for lomas_server.admin_database.mongodb_database</h1><div class=
<span class="n">user_must_exist</span><span class="p">,</span>
<span class="n">user_must_have_access_to_dataset</span><span class="p">,</span>
<span class="p">)</span>
<span class="kn">from</span> <span class="nn">utils.error_handler</span> <span class="kn">import</span> <span class="n">InvalidQueryException</span>


<div class="viewcode-block" id="AdminMongoDatabase">
Expand Down Expand Up @@ -246,6 +247,11 @@ <h1>Source code for lomas_server.admin_database.mongodb_database</h1><div class=
<span class="sd"> Returns:</span>
<span class="sd"> bool: True if the user has access, False otherwise.</span>
<span class="sd"> &quot;&quot;&quot;</span>
<span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">does_dataset_exist</span><span class="p">(</span><span class="n">dataset_name</span><span class="p">):</span>
<span class="k">raise</span> <span class="n">InvalidQueryException</span><span class="p">(</span>
<span class="sa">f</span><span class="s2">&quot;Dataset </span><span class="si">{</span><span class="n">dataset_name</span><span class="si">}</span><span class="s2"> does not exist. &quot;</span>
<span class="o">+</span> <span class="s2">&quot;Please, verify the client object initialisation.&quot;</span><span class="p">,</span>
<span class="p">)</span>
<span class="n">doc_count</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">db</span><span class="o">.</span><span class="n">users</span><span class="o">.</span><span class="n">count_documents</span><span class="p">(</span>
<span class="p">{</span>
<span class="s2">&quot;user_name&quot;</span><span class="p">:</span> <span class="sa">f</span><span class="s2">&quot;</span><span class="si">{</span><span class="n">user_name</span><span class="si">}</span><span class="s2">&quot;</span><span class="p">,</span>
Expand Down
Loading

0 comments on commit c05904c

Please sign in to comment.