gitlabhq/doc/code/classes/Authority.html
2012-12-30 14:43:00 +02:00

528 lines
No EOL
22 KiB
HTML

<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>Authority</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="stylesheet" href="../css/reset.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../css/main.css" type="text/css" media="screen" />
<link rel="stylesheet" href="../css/github.css" type="text/css" media="screen" />
<script src="../js/jquery-1.3.2.min.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/jquery-effect.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/main.js" type="text/javascript" charset="utf-8"></script>
<script src="../js/highlight.pack.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div class="banner">
<h1>
<span class="type">Module</span>
Authority
</h1>
<ul class="files">
<li><a href="../files/app/roles/authority_rb.html">app/roles/authority.rb</a></li>
</ul>
</div>
<div id="bodyContent">
<div id="content">
<!-- Method ref -->
<div class="sectiontitle">Methods</div>
<dl class="methods">
<dt>A</dt>
<dd>
<ul>
<li>
<a href="#method-i-add_access">add_access</a>,
</li>
<li>
<a href="#method-i-allow_read_for-3F">allow_read_for?</a>
</li>
</ul>
</dd>
<dt>D</dt>
<dd>
<ul>
<li>
<a href="#method-i-dev_access_for-3F">dev_access_for?</a>
</li>
</ul>
</dd>
<dt>G</dt>
<dd>
<ul>
<li>
<a href="#method-i-guest_access_for-3F">guest_access_for?</a>
</li>
</ul>
</dd>
<dt>M</dt>
<dd>
<ul>
<li>
<a href="#method-i-master_access_for-3F">master_access_for?</a>
</li>
</ul>
</dd>
<dt>R</dt>
<dd>
<ul>
<li>
<a href="#method-i-report_access_for-3F">report_access_for?</a>,
</li>
<li>
<a href="#method-i-repository_masters">repository_masters</a>,
</li>
<li>
<a href="#method-i-repository_readers">repository_readers</a>,
</li>
<li>
<a href="#method-i-repository_writers">repository_writers</a>,
</li>
<li>
<a href="#method-i-reset_access">reset_access</a>
</li>
</ul>
</dd>
</dl>
<!-- Methods -->
<div class="sectiontitle">Instance Public methods</div>
<div class="method">
<div class="title method-title" id="method-i-add_access">
<b>add_access</b>(user, *access)
<a href="../classes/Authority.html#method-i-add_access" name="method-i-add_access" class="permalink">Link</a>
</div>
<div class="description">
<p>Compatible with all access rights Should be rewrited for new access rights</p>
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-add_access_source')" id="l_method-i-add_access_source">show</a>
</p>
<div id="method-i-add_access_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/roles/authority.rb, line 4</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">add_access</span>(<span class="ruby-identifier">user</span>, *<span class="ruby-identifier">access</span>)
<span class="ruby-identifier">access</span> = <span class="ruby-keyword">if</span> <span class="ruby-identifier">access</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value">:admin</span>)
{ <span class="ruby-identifier">project_access</span><span class="ruby-operator">:</span> <span class="ruby-constant">UsersProject</span><span class="ruby-operator">::</span><span class="ruby-constant">MASTER</span> }
<span class="ruby-keyword">elsif</span> <span class="ruby-identifier">access</span>.<span class="ruby-identifier">include?</span>(<span class="ruby-value">:write</span>)
{ <span class="ruby-identifier">project_access</span><span class="ruby-operator">:</span> <span class="ruby-constant">UsersProject</span><span class="ruby-operator">::</span><span class="ruby-constant">DEVELOPER</span> }
<span class="ruby-keyword">else</span>
{ <span class="ruby-identifier">project_access</span><span class="ruby-operator">:</span> <span class="ruby-constant">UsersProject</span><span class="ruby-operator">::</span><span class="ruby-constant">REPORTER</span> }
<span class="ruby-keyword">end</span>
<span class="ruby-identifier">opts</span> = { <span class="ruby-identifier">user</span><span class="ruby-operator">:</span> <span class="ruby-identifier">user</span> }
<span class="ruby-identifier">opts</span>.<span class="ruby-identifier">merge!</span>(<span class="ruby-identifier">access</span>)
<span class="ruby-identifier">users_projects</span>.<span class="ruby-identifier">create</span>(<span class="ruby-identifier">opts</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-allow_read_for-3F">
<b>allow_read_for?</b>(user)
<a href="../classes/Authority.html#method-i-allow_read_for-3F" name="method-i-allow_read_for-3F" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-allow_read_for-3F_source')" id="l_method-i-allow_read_for-3F_source">show</a>
</p>
<div id="method-i-allow_read_for-3F_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/roles/authority.rb, line 39</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">allow_read_for?</span>(<span class="ruby-identifier">user</span>)
<span class="ruby-operator">!</span><span class="ruby-identifier">users_projects</span>.<span class="ruby-identifier">where</span>(<span class="ruby-identifier">user_id</span><span class="ruby-operator">:</span> <span class="ruby-identifier">user</span>.<span class="ruby-identifier">id</span>).<span class="ruby-identifier">empty?</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-dev_access_for-3F">
<b>dev_access_for?</b>(user)
<a href="../classes/Authority.html#method-i-dev_access_for-3F" name="method-i-dev_access_for-3F" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-dev_access_for-3F_source')" id="l_method-i-dev_access_for-3F_source">show</a>
</p>
<div id="method-i-dev_access_for-3F_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/roles/authority.rb, line 51</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">dev_access_for?</span>(<span class="ruby-identifier">user</span>)
<span class="ruby-operator">!</span><span class="ruby-identifier">users_projects</span>.<span class="ruby-identifier">where</span>(<span class="ruby-identifier">user_id</span><span class="ruby-operator">:</span> <span class="ruby-identifier">user</span>.<span class="ruby-identifier">id</span>, <span class="ruby-identifier">project_access</span><span class="ruby-operator">:</span> [<span class="ruby-constant">UsersProject</span><span class="ruby-operator">::</span><span class="ruby-constant">DEVELOPER</span>, <span class="ruby-constant">UsersProject</span><span class="ruby-operator">::</span><span class="ruby-constant">MASTER</span>]).<span class="ruby-identifier">empty?</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-guest_access_for-3F">
<b>guest_access_for?</b>(user)
<a href="../classes/Authority.html#method-i-guest_access_for-3F" name="method-i-guest_access_for-3F" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-guest_access_for-3F_source')" id="l_method-i-guest_access_for-3F_source">show</a>
</p>
<div id="method-i-guest_access_for-3F_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/roles/authority.rb, line 43</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">guest_access_for?</span>(<span class="ruby-identifier">user</span>)
<span class="ruby-operator">!</span><span class="ruby-identifier">users_projects</span>.<span class="ruby-identifier">where</span>(<span class="ruby-identifier">user_id</span><span class="ruby-operator">:</span> <span class="ruby-identifier">user</span>.<span class="ruby-identifier">id</span>).<span class="ruby-identifier">empty?</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-master_access_for-3F">
<b>master_access_for?</b>(user)
<a href="../classes/Authority.html#method-i-master_access_for-3F" name="method-i-master_access_for-3F" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-master_access_for-3F_source')" id="l_method-i-master_access_for-3F_source">show</a>
</p>
<div id="method-i-master_access_for-3F_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/roles/authority.rb, line 55</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">master_access_for?</span>(<span class="ruby-identifier">user</span>)
<span class="ruby-operator">!</span><span class="ruby-identifier">users_projects</span>.<span class="ruby-identifier">where</span>(<span class="ruby-identifier">user_id</span><span class="ruby-operator">:</span> <span class="ruby-identifier">user</span>.<span class="ruby-identifier">id</span>, <span class="ruby-identifier">project_access</span><span class="ruby-operator">:</span> [<span class="ruby-constant">UsersProject</span><span class="ruby-operator">::</span><span class="ruby-constant">MASTER</span>]).<span class="ruby-identifier">empty?</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-report_access_for-3F">
<b>report_access_for?</b>(user)
<a href="../classes/Authority.html#method-i-report_access_for-3F" name="method-i-report_access_for-3F" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-report_access_for-3F_source')" id="l_method-i-report_access_for-3F_source">show</a>
</p>
<div id="method-i-report_access_for-3F_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/roles/authority.rb, line 47</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">report_access_for?</span>(<span class="ruby-identifier">user</span>)
<span class="ruby-operator">!</span><span class="ruby-identifier">users_projects</span>.<span class="ruby-identifier">where</span>(<span class="ruby-identifier">user_id</span><span class="ruby-operator">:</span> <span class="ruby-identifier">user</span>.<span class="ruby-identifier">id</span>, <span class="ruby-identifier">project_access</span><span class="ruby-operator">:</span> [<span class="ruby-constant">UsersProject</span><span class="ruby-operator">::</span><span class="ruby-constant">REPORTER</span>, <span class="ruby-constant">UsersProject</span><span class="ruby-operator">::</span><span class="ruby-constant">DEVELOPER</span>, <span class="ruby-constant">UsersProject</span><span class="ruby-operator">::</span><span class="ruby-constant">MASTER</span>]).<span class="ruby-identifier">empty?</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-repository_masters">
<b>repository_masters</b>()
<a href="../classes/Authority.html#method-i-repository_masters" name="method-i-repository_masters" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-repository_masters_source')" id="l_method-i-repository_masters_source">show</a>
</p>
<div id="method-i-repository_masters_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/roles/authority.rb, line 33</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">repository_masters</span>
<span class="ruby-identifier">keys</span> = <span class="ruby-constant">Key</span>.<span class="ruby-identifier">joins</span>({<span class="ruby-identifier">user</span><span class="ruby-operator">:</span> <span class="ruby-value">:users_projects</span>}).
<span class="ruby-identifier">where</span>(<span class="ruby-string">&quot;users_projects.project_id = ? AND users_projects.project_access = ?&quot;</span>, <span class="ruby-identifier">id</span>, <span class="ruby-constant">UsersProject</span><span class="ruby-operator">::</span><span class="ruby-constant">MASTER</span>)
<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">map</span>(&amp;<span class="ruby-value">:identifier</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-repository_readers">
<b>repository_readers</b>()
<a href="../classes/Authority.html#method-i-repository_readers" name="method-i-repository_readers" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-repository_readers_source')" id="l_method-i-repository_readers_source">show</a>
</p>
<div id="method-i-repository_readers_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/roles/authority.rb, line 21</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">repository_readers</span>
<span class="ruby-identifier">keys</span> = <span class="ruby-constant">Key</span>.<span class="ruby-identifier">joins</span>({<span class="ruby-identifier">user</span><span class="ruby-operator">:</span> <span class="ruby-value">:users_projects</span>}).
<span class="ruby-identifier">where</span>(<span class="ruby-string">&quot;users_projects.project_id = ? AND users_projects.project_access = ?&quot;</span>, <span class="ruby-identifier">id</span>, <span class="ruby-constant">UsersProject</span><span class="ruby-operator">::</span><span class="ruby-constant">REPORTER</span>)
<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">map</span>(&amp;<span class="ruby-value">:identifier</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">deploy_keys</span>.<span class="ruby-identifier">map</span>(&amp;<span class="ruby-value">:identifier</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-repository_writers">
<b>repository_writers</b>()
<a href="../classes/Authority.html#method-i-repository_writers" name="method-i-repository_writers" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-repository_writers_source')" id="l_method-i-repository_writers_source">show</a>
</p>
<div id="method-i-repository_writers_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/roles/authority.rb, line 27</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">repository_writers</span>
<span class="ruby-identifier">keys</span> = <span class="ruby-constant">Key</span>.<span class="ruby-identifier">joins</span>({<span class="ruby-identifier">user</span><span class="ruby-operator">:</span> <span class="ruby-value">:users_projects</span>}).
<span class="ruby-identifier">where</span>(<span class="ruby-string">&quot;users_projects.project_id = ? AND users_projects.project_access = ?&quot;</span>, <span class="ruby-identifier">id</span>, <span class="ruby-constant">UsersProject</span><span class="ruby-operator">::</span><span class="ruby-constant">DEVELOPER</span>)
<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">map</span>(&amp;<span class="ruby-value">:identifier</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-reset_access">
<b>reset_access</b>(user)
<a href="../classes/Authority.html#method-i-reset_access" name="method-i-reset_access" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-reset_access_source')" id="l_method-i-reset_access_source">show</a>
</p>
<div id="method-i-reset_access_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/roles/authority.rb, line 17</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">reset_access</span>(<span class="ruby-identifier">user</span>)
<span class="ruby-identifier">users_projects</span>.<span class="ruby-identifier">where</span>(<span class="ruby-identifier">project_id</span><span class="ruby-operator">:</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">id</span>, <span class="ruby-identifier">user_id</span><span class="ruby-operator">:</span> <span class="ruby-identifier">user</span>.<span class="ruby-identifier">id</span>).<span class="ruby-identifier">destroy</span> <span class="ruby-keyword">if</span> <span class="ruby-keyword">self</span>.<span class="ruby-identifier">id</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
</div>
</div>
</body>
</html>