/usr/share/doc/python-django-guardian-doc/html/userguide/caveats.html is in python-django-guardian-doc 1.2.4+git20141127-0.2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 | <!DOCTYPE html>
<!--[if IE 8]><html class="no-js lt-ie9" lang="en" > <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js" lang="en" > <!--<![endif]-->
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Caveats — django-guardian 1.2.5.dev documentation</title>
<link href='http://fonts.googleapis.com/css?family=Lato:400,700|Roboto+Slab:400,700' rel='stylesheet' type='text/css'>
<script type="text/javascript">
var DOCUMENTATION_OPTIONS = {
URL_ROOT:'../',
VERSION:'1.2.5.dev',
COLLAPSE_INDEX:false,
FILE_SUFFIX:'.html',
HAS_SOURCE: true
};
</script>
<script type="text/javascript" src="../_static/jquery.js"></script>
<script type="text/javascript" src="../_static/underscore.js"></script>
<script type="text/javascript" src="../_static/doctools.js"></script>
<link rel="stylesheet" href="../_static/theme.css" type="text/css" />
<script type="text/javascript" src="_static/theme.js"></script>
<link rel="top" title="django-guardian 1.2.5.dev documentation" href="../index.html"/>
<link rel="up" title="User Guide" href="index.html"/>
<link rel="next" title="API Reference" href="../api/index.html"/>
<link rel="prev" title="Performance tuning" href="performance.html"/>
<script src="//cdnjs.cloudflare.com/ajax/libs/modernizr/2.6.2/modernizr.min.js"></script>
</head>
<body class="wy-body-for-nav">
<div class="wy-grid-for-nav">
<nav data-toggle="wy-nav-shift" class="wy-nav-side">
<div class="wy-side-nav-search">
<a href="../index.html" class="icon icon-home"> django-guardian</a>
<form class="wy-form" action="../search.html" method="get">
<input type="text" name="q" placeholder="Search docs" />
<input type="hidden" name="check_keywords" value="yes" />
<input type="hidden" name="area" value="default" />
</form>
</div>
<div class="wy-menu wy-menu-vertical" data-spy="affix">
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="../overview.html">Overview</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../overview.html#features">Features</a></li>
<li class="toctree-l2"><a class="reference internal" href="../overview.html#incoming">Incoming</a></li>
<li class="toctree-l2"><a class="reference internal" href="../overview.html#source-and-issue-tracker">Source and issue tracker</a></li>
<li class="toctree-l2"><a class="reference internal" href="../overview.html#alternate-projects">Alternate projects</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../installation.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="../configuration.html">Configuration</a></li>
<li class="toctree-l1"><a class="reference internal" href="../configuration.html#optional-settings">Optional settings</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../configuration.html#guardian-raise-403">GUARDIAN_RAISE_403</a></li>
<li class="toctree-l2"><a class="reference internal" href="../configuration.html#guardian-render-403">GUARDIAN_RENDER_403</a></li>
<li class="toctree-l2"><a class="reference internal" href="../configuration.html#guardian-template-403">GUARDIAN_TEMPLATE_403</a></li>
<li class="toctree-l2"><a class="reference internal" href="../configuration.html#anonymous-default-username-value">ANONYMOUS_DEFAULT_USERNAME_VALUE</a></li>
<li class="toctree-l2"><a class="reference internal" href="../configuration.html#guardian-get-init-anonymous-user">GUARDIAN_GET_INIT_ANONYMOUS_USER</a></li>
</ul>
</li>
<li class="toctree-l1 current"><a class="reference internal" href="index.html">User Guide</a><ul class="current">
<li class="toctree-l2"><a class="reference internal" href="assign.html">Assign object permissions</a></li>
<li class="toctree-l2"><a class="reference internal" href="check.html">Check object permissions</a></li>
<li class="toctree-l2"><a class="reference internal" href="remove.html">Remove object permissions</a></li>
<li class="toctree-l2"><a class="reference internal" href="admin-integration.html">Admin integration</a></li>
<li class="toctree-l2"><a class="reference internal" href="custom-user-model.html">Custom User model</a></li>
<li class="toctree-l2"><a class="reference internal" href="performance.html">Performance tuning</a></li>
<li class="toctree-l2 current"><a class="current reference internal" href="">Caveats</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../api/index.html">API Reference</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../api/guardian.admin.html">Admin</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/guardian.backends.html">Backends</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/guardian.core.html">Core</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/guardian.decorators.html">Decorators</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/guardian.forms.html">Forms</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/guardian.management.commands.html">Management commands</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/guardian.managers.html">Managers</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/guardian.mixins.html">Mixins</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/guardian.models.html">Models</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/guardian.shortcuts.html">Shortcuts</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/guardian.utils.html">Utilities</a></li>
<li class="toctree-l2"><a class="reference internal" href="../api/guardian.templatetags.guardian_tags.html">Template tags</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../develop/index.html">Development</a><ul>
<li class="toctree-l2"><a class="reference internal" href="../develop/overview.html">Overview</a></li>
<li class="toctree-l2"><a class="reference internal" href="../develop/example_project.html">Example project</a></li>
<li class="toctree-l2"><a class="reference internal" href="../develop/testing.html">Testing</a></li>
<li class="toctree-l2"><a class="reference internal" href="../develop/supported-versions.html">Supported versions</a></li>
<li class="toctree-l2"><a class="reference internal" href="../develop/changes.html">Changelog</a></li>
</ul>
</li>
<li class="toctree-l1"><a class="reference internal" href="../license.html">License</a></li>
</ul>
</div>
</nav>
<section data-toggle="wy-nav-shift" class="wy-nav-content-wrap">
<nav class="wy-nav-top">
<i data-toggle="wy-nav-top" class="icon icon-reorder"></i>
<a href="/">django-guardian</a>
</nav>
<div class="wy-nav-content">
<div class="rst-content">
<ul class="wy-breadcrumbs">
<li><a href="../index.html">Docs</a> »</li>
<li><a href="">Caveats</a></li>
</ul>
<hr/>
<div class="section" id="caveats">
<span id="id1"></span><h1>Caveats<a class="headerlink" href="#caveats" title="Permalink to this headline">¶</a></h1>
<div class="section" id="orphaned-object-permissions">
<h2>Orphaned object permissions<a class="headerlink" href="#orphaned-object-permissions" title="Permalink to this headline">¶</a></h2>
<p>Permissions, including so called <em>per object permissions</em>, are sometimes tricky
to manage. One case is how we can manage permissions that are no longer used.
Normally, there should be no problems, however with some particular setup it is
possible to reuse primary keys of database models which were used in the past
once. We will not answer how bad such situation can be - instead we will try to
cover how we can deal with this.</p>
<p>Let’s imagine our table has primary key to the filesystem path. We have a record
with pk equal to <tt class="docutils literal"><span class="pre">/home/www/joe.config</span></tt>. User <em>jane</em> has read access to
joe’s configuration and we store that information in database by creating
guardian’s object permissions. Now, <em>joe</em> user removes account from our site and
another user creates account with <em>joe</em> as username. The problem is that if we
haven’t removed object permissions explicitly in the process of first <em>joe</em>
account removal, <em>jane</em> still has read permissions for <em>joe’s</em> configuration
file - but this is another user.</p>
<p>There is no easy way to deal with orphaned permissions as they are not foreign
keyed with objects directly. Even if they would, there are some database engines
- or <em>ON DELETE</em> rules - which restricts removal of related objects.</p>
<div class="admonition important">
<p class="first admonition-title">Important</p>
<p class="last">It is <strong>extremely</strong> important to remove <a class="reference internal" href="../api/guardian.models.html#std:model-UserObjectPermission"><tt class="xref std std-model docutils literal"><span class="pre">UserObjectPermission</span></tt></a> and
<a class="reference internal" href="../api/guardian.models.html#std:model-GroupObjectPermission"><tt class="xref std std-model docutils literal"><span class="pre">GroupObjectPermission</span></tt></a> as we delete objects for which permissions
are defined.</p>
</div>
<p>Guardian comes with utility function which tries to help to remove orphaned
object permissions. Remember - those are only helpers. Applications should
remove those object permissions explicitly by itself.</p>
<p>Taking our previous example, our application should remove user object for
<em>joe</em>, however, permisions for <em>joe</em> user assigned to <em>jane</em> would <strong>NOT</strong>
be removed. In this case, it would be very easy to remove user/group object
permissions if we connect proper action with proper signal. This could be
achieved by following snippet:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.contrib.contenttypes.models</span> <span class="kn">import</span> <span class="n">ContentType</span>
<span class="kn">from</span> <span class="nn">django.db.models</span> <span class="kn">import</span> <span class="n">Q</span>
<span class="kn">from</span> <span class="nn">django.db.models.signals</span> <span class="kn">import</span> <span class="n">pre_delete</span>
<span class="kn">from</span> <span class="nn">guardian.models</span> <span class="kn">import</span> <span class="n">User</span>
<span class="kn">from</span> <span class="nn">guardian.models</span> <span class="kn">import</span> <span class="n">UserObjectPermission</span>
<span class="kn">from</span> <span class="nn">guardian.models</span> <span class="kn">import</span> <span class="n">GroupObjectPermission</span>
<span class="k">def</span> <span class="nf">remove_obj_perms_connected_with_user</span><span class="p">(</span><span class="n">sender</span><span class="p">,</span> <span class="n">instance</span><span class="p">,</span> <span class="o">**</span><span class="n">kwargs</span><span class="p">):</span>
<span class="n">filters</span> <span class="o">=</span> <span class="n">Q</span><span class="p">(</span><span class="n">content_type</span><span class="o">=</span><span class="n">ContentType</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">get_for_model</span><span class="p">(</span><span class="n">instance</span><span class="p">),</span>
<span class="n">object_pk</span><span class="o">=</span><span class="n">instance</span><span class="o">.</span><span class="n">pk</span><span class="p">)</span>
<span class="n">UserObjectPermission</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">filters</span><span class="p">)</span><span class="o">.</span><span class="n">delete</span><span class="p">()</span>
<span class="n">GroupObjectPermission</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">filter</span><span class="p">(</span><span class="n">filters</span><span class="p">)</span><span class="o">.</span><span class="n">delete</span><span class="p">()</span>
<span class="n">pre_delete</span><span class="o">.</span><span class="n">connect</span><span class="p">(</span><span class="n">remove_obj_perms_connected_with_user</span><span class="p">,</span> <span class="n">sender</span><span class="o">=</span><span class="n">User</span><span class="p">)</span>
</pre></div>
</div>
<p>This signal handler would remove all object permissions connected with user
just before user is actually removed.</p>
<p>If we forgot to add such handlers, we may still remove orphaned object
permissions by using <a class="reference internal" href="../api/guardian.management.commands.html#std:command-clean_orphan_obj_perms"><tt class="xref std std-command docutils literal"><span class="pre">clean_orphan_obj_perms</span></tt></a> command. If our
application uses <a class="reference external" href="http://www.celeryproject.org/">celery</a>, it is also very easy to remove orphaned permissions
periodically with <a class="reference internal" href="../api/guardian.utils.html#guardian.utils.clean_orphan_obj_perms" title="guardian.utils.clean_orphan_obj_perms"><tt class="xref py py-func docutils literal"><span class="pre">guardian.utils.clean_orphan_obj_perms()</span></tt></a> function.
We would still <strong>strongly</strong> advise to remove orphaned object permissions
explicitly (i.e. at view that confirms object removal or using signals as
described above).</p>
<div class="admonition seealso">
<p class="first admonition-title">See also</p>
<ul class="last simple">
<li><a class="reference internal" href="../api/guardian.utils.html#guardian.utils.clean_orphan_obj_perms" title="guardian.utils.clean_orphan_obj_perms"><tt class="xref py py-func docutils literal"><span class="pre">guardian.utils.clean_orphan_obj_perms()</span></tt></a></li>
<li><a class="reference internal" href="../api/guardian.management.commands.html#std:command-clean_orphan_obj_perms"><tt class="xref std std-command docutils literal"><span class="pre">clean_orphan_obj_perms</span></tt></a></li>
</ul>
</div>
</div>
</div>
<footer>
<hr/>
© Copyright 2010-2013, Lukasz Balcerzak.
</footer>
</div>
</div>
</section>
</div>
</body>
</html>
|