gitlabhq/doc/code/classes/Admin/UsersController.html

616 lines
28 KiB
HTML
Raw Normal View History

<?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>Admin::UsersController</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">Class</span>
Admin::UsersController
<span class="parent">&lt;
<a href="../AdminController.html">AdminController</a>
</span>
</h1>
<ul class="files">
<li><a href="../../files/app/controllers/admin/users_controller_rb.html">app/controllers/admin/users_controller.rb</a></li>
</ul>
</div>
<div id="bodyContent">
<div id="content">
<!-- Method ref -->
<div class="sectiontitle">Methods</div>
<dl class="methods">
<dt>B</dt>
<dd>
<ul>
<li>
<a href="#method-i-block">block</a>
</li>
</ul>
</dd>
<dt>C</dt>
<dd>
<ul>
<li>
<a href="#method-i-create">create</a>
</li>
</ul>
</dd>
<dt>D</dt>
<dd>
<ul>
<li>
<a href="#method-i-destroy">destroy</a>
</li>
</ul>
</dd>
<dt>E</dt>
<dd>
<ul>
<li>
<a href="#method-i-edit">edit</a>
</li>
</ul>
</dd>
<dt>I</dt>
<dd>
<ul>
<li>
<a href="#method-i-index">index</a>
</li>
</ul>
</dd>
<dt>N</dt>
<dd>
<ul>
<li>
<a href="#method-i-new">new</a>
</li>
</ul>
</dd>
<dt>S</dt>
<dd>
<ul>
<li>
<a href="#method-i-show">show</a>
</li>
</ul>
</dd>
<dt>T</dt>
<dd>
<ul>
<li>
<a href="#method-i-team_update">team_update</a>
</li>
</ul>
</dd>
<dt>U</dt>
<dd>
<ul>
<li>
<a href="#method-i-unblock">unblock</a>,
</li>
<li>
<a href="#method-i-update">update</a>
</li>
</ul>
</dd>
</dl>
<!-- Methods -->
<div class="sectiontitle">Instance Public methods</div>
<div class="method">
<div class="title method-title" id="method-i-block">
<b>block</b>()
<a href="../../classes/Admin/UsersController.html#method-i-block" name="method-i-block" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-block_source')" id="l_method-i-block_source">show</a>
</p>
<div id="method-i-block_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/controllers/admin/users_controller.rb, line 40</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">block</span>
<span class="ruby-ivar">@admin_user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:id</span>])
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@admin_user</span>.<span class="ruby-identifier">block</span>
<span class="ruby-identifier">redirect_to</span> <span class="ruby-value">:back</span>, <span class="ruby-identifier">alert</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;Successfully blocked&quot;</span>
<span class="ruby-keyword">else</span>
<span class="ruby-identifier">redirect_to</span> <span class="ruby-value">:back</span>, <span class="ruby-identifier">alert</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;Error occured. User was not blocked&quot;</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-create">
<b>create</b>()
<a href="../../classes/Admin/UsersController.html#method-i-create" name="method-i-create" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-create_source')" id="l_method-i-create_source">show</a>
</p>
<div id="method-i-create_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/controllers/admin/users_controller.rb, line 60</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">create</span>
<span class="ruby-identifier">admin</span> = <span class="ruby-identifier">params</span>[<span class="ruby-value">:user</span>].<span class="ruby-identifier">delete</span>(<span class="ruby-string">&quot;admin&quot;</span>)
<span class="ruby-ivar">@admin_user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:user</span>], <span class="ruby-identifier">as</span><span class="ruby-operator">:</span> <span class="ruby-value">:admin</span>)
<span class="ruby-ivar">@admin_user</span>.<span class="ruby-identifier">admin</span> = (<span class="ruby-identifier">admin</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">admin</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">&gt;</span> <span class="ruby-number">0</span>)
<span class="ruby-identifier">respond_to</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">format</span><span class="ruby-operator">|</span>
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@admin_user</span>.<span class="ruby-identifier">save</span>
<span class="ruby-identifier">format</span>.<span class="ruby-identifier">html</span> { <span class="ruby-identifier">redirect_to</span> [<span class="ruby-value">:admin</span>, <span class="ruby-ivar">@admin_user</span>], <span class="ruby-identifier">notice</span><span class="ruby-operator">:</span> <span class="ruby-string">'User was successfully created.'</span> }
<span class="ruby-identifier">format</span>.<span class="ruby-identifier">json</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">json</span><span class="ruby-operator">:</span> <span class="ruby-ivar">@admin_user</span>, <span class="ruby-identifier">status</span><span class="ruby-operator">:</span> <span class="ruby-value">:created</span>, <span class="ruby-identifier">location</span><span class="ruby-operator">:</span> <span class="ruby-ivar">@admin_user</span> }
<span class="ruby-keyword">else</span>
<span class="ruby-identifier">format</span>.<span class="ruby-identifier">html</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">action</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;new&quot;</span> }
<span class="ruby-identifier">format</span>.<span class="ruby-identifier">json</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">json</span><span class="ruby-operator">:</span> <span class="ruby-ivar">@admin_user</span>.<span class="ruby-identifier">errors</span>, <span class="ruby-identifier">status</span><span class="ruby-operator">:</span> <span class="ruby-value">:unprocessable_entity</span> }
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-destroy">
<b>destroy</b>()
<a href="../../classes/Admin/UsersController.html#method-i-destroy" name="method-i-destroy" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-destroy_source')" id="l_method-i-destroy_source">show</a>
</p>
<div id="method-i-destroy_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/controllers/admin/users_controller.rb, line 99</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">destroy</span>
<span class="ruby-ivar">@admin_user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:id</span>])
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@admin_user</span>.<span class="ruby-identifier">my_own_projects</span>.<span class="ruby-identifier">count</span> <span class="ruby-operator">&gt;</span> <span class="ruby-number">0</span>
<span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">admin_users_path</span>, <span class="ruby-identifier">alert</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;User is a project owner and can't be removed.&quot;</span> <span class="ruby-keyword">and</span> <span class="ruby-keyword">return</span>
<span class="ruby-keyword">end</span>
<span class="ruby-ivar">@admin_user</span>.<span class="ruby-identifier">destroy</span>
<span class="ruby-identifier">respond_to</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">format</span><span class="ruby-operator">|</span>
<span class="ruby-identifier">format</span>.<span class="ruby-identifier">html</span> { <span class="ruby-identifier">redirect_to</span> <span class="ruby-identifier">admin_users_url</span> }
<span class="ruby-identifier">format</span>.<span class="ruby-identifier">json</span> { <span class="ruby-identifier">head</span> <span class="ruby-value">:ok</span> }
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-edit">
<b>edit</b>()
<a href="../../classes/Admin/UsersController.html#method-i-edit" name="method-i-edit" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-edit_source')" id="l_method-i-edit_source">show</a>
</p>
<div id="method-i-edit_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/controllers/admin/users_controller.rb, line 36</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">edit</span>
<span class="ruby-ivar">@admin_user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:id</span>])
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-index">
<b>index</b>()
<a href="../../classes/Admin/UsersController.html#method-i-index" name="method-i-index" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-index_source')" id="l_method-i-index_source">show</a>
</p>
<div id="method-i-index_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/controllers/admin/users_controller.rb, line 2</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">index</span>
<span class="ruby-ivar">@admin_users</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">scoped</span>
<span class="ruby-ivar">@admin_users</span> = <span class="ruby-ivar">@admin_users</span>.<span class="ruby-identifier">filter</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:filter</span>])
<span class="ruby-ivar">@admin_users</span> = <span class="ruby-ivar">@admin_users</span>.<span class="ruby-identifier">search</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:name</span>]) <span class="ruby-keyword">if</span> <span class="ruby-identifier">params</span>[<span class="ruby-value">:name</span>].<span class="ruby-identifier">present?</span>
<span class="ruby-ivar">@admin_users</span> = <span class="ruby-ivar">@admin_users</span>.<span class="ruby-identifier">alphabetically</span>.<span class="ruby-identifier">page</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:page</span>])
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-new">
<b>new</b>()
<a href="../../classes/Admin/UsersController.html#method-i-new" name="method-i-new" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-new_source')" id="l_method-i-new_source">show</a>
</p>
<div id="method-i-new_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/controllers/admin/users_controller.rb, line 32</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">new</span>
<span class="ruby-ivar">@admin_user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">new</span>({ <span class="ruby-identifier">projects_limit</span><span class="ruby-operator">:</span> <span class="ruby-constant">Gitlab</span>.<span class="ruby-identifier">config</span>.<span class="ruby-identifier">gitlab</span>.<span class="ruby-identifier">default_projects_limit</span> }, <span class="ruby-identifier">as</span><span class="ruby-operator">:</span> <span class="ruby-value">:admin</span>)
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-show">
<b>show</b>()
<a href="../../classes/Admin/UsersController.html#method-i-show" name="method-i-show" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-show_source')" id="l_method-i-show_source">show</a>
</p>
<div id="method-i-show_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/controllers/admin/users_controller.rb, line 9</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">show</span>
<span class="ruby-ivar">@admin_user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:id</span>])
<span class="ruby-ivar">@projects</span> = <span class="ruby-keyword">if</span> <span class="ruby-ivar">@admin_user</span>.<span class="ruby-identifier">projects</span>.<span class="ruby-identifier">empty?</span>
<span class="ruby-constant">Project</span>
<span class="ruby-keyword">else</span>
<span class="ruby-constant">Project</span>.<span class="ruby-identifier">without_user</span>(<span class="ruby-ivar">@admin_user</span>)
<span class="ruby-keyword">end</span>.<span class="ruby-identifier">all</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-team_update">
<b>team_update</b>()
<a href="../../classes/Admin/UsersController.html#method-i-team_update" name="method-i-team_update" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-team_update_source')" id="l_method-i-team_update_source">show</a>
</p>
<div id="method-i-team_update_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/controllers/admin/users_controller.rb, line 19</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">team_update</span>
<span class="ruby-ivar">@admin_user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:id</span>])
<span class="ruby-constant">UsersProject</span>.<span class="ruby-identifier">user_bulk_import</span>(
<span class="ruby-ivar">@admin_user</span>,
<span class="ruby-identifier">params</span>[<span class="ruby-value">:project_ids</span>],
<span class="ruby-identifier">params</span>[<span class="ruby-value">:project_access</span>]
)
<span class="ruby-identifier">redirect_to</span> [<span class="ruby-value">:admin</span>, <span class="ruby-ivar">@admin_user</span>], <span class="ruby-identifier">notice</span><span class="ruby-operator">:</span> <span class="ruby-string">'Teams were successfully updated.'</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-unblock">
<b>unblock</b>()
<a href="../../classes/Admin/UsersController.html#method-i-unblock" name="method-i-unblock" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-unblock_source')" id="l_method-i-unblock_source">show</a>
</p>
<div id="method-i-unblock_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/controllers/admin/users_controller.rb, line 50</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">unblock</span>
<span class="ruby-ivar">@admin_user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:id</span>])
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@admin_user</span>.<span class="ruby-identifier">update_attribute</span>(<span class="ruby-value">:blocked</span>, <span class="ruby-keyword">false</span>)
<span class="ruby-identifier">redirect_to</span> <span class="ruby-value">:back</span>, <span class="ruby-identifier">alert</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;Successfully unblocked&quot;</span>
<span class="ruby-keyword">else</span>
<span class="ruby-identifier">redirect_to</span> <span class="ruby-value">:back</span>, <span class="ruby-identifier">alert</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;Error occured. User was not unblocked&quot;</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
<div class="method">
<div class="title method-title" id="method-i-update">
<b>update</b>()
<a href="../../classes/Admin/UsersController.html#method-i-update" name="method-i-update" class="permalink">Link</a>
</div>
<div class="description">
</div>
<div class="sourcecode">
<p class="source-link">
Source:
<a href="javascript:toggleSource('method-i-update_source')" id="l_method-i-update_source">show</a>
</p>
<div id="method-i-update_source" class="dyn-source">
<pre><span class="ruby-comment"># File app/controllers/admin/users_controller.rb, line 77</span>
<span class="ruby-keyword">def</span> <span class="ruby-keyword ruby-title">update</span>
<span class="ruby-identifier">admin</span> = <span class="ruby-identifier">params</span>[<span class="ruby-value">:user</span>].<span class="ruby-identifier">delete</span>(<span class="ruby-string">&quot;admin&quot;</span>)
<span class="ruby-keyword">if</span> <span class="ruby-identifier">params</span>[<span class="ruby-value">:user</span>][<span class="ruby-value">:password</span>].<span class="ruby-identifier">blank?</span>
<span class="ruby-identifier">params</span>[<span class="ruby-value">:user</span>].<span class="ruby-identifier">delete</span>(<span class="ruby-value">:password</span>)
<span class="ruby-identifier">params</span>[<span class="ruby-value">:user</span>].<span class="ruby-identifier">delete</span>(<span class="ruby-value">:password_confirmation</span>)
<span class="ruby-keyword">end</span>
<span class="ruby-ivar">@admin_user</span> = <span class="ruby-constant">User</span>.<span class="ruby-identifier">find</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:id</span>])
<span class="ruby-ivar">@admin_user</span>.<span class="ruby-identifier">admin</span> = (<span class="ruby-identifier">admin</span> <span class="ruby-operator">&amp;&amp;</span> <span class="ruby-identifier">admin</span>.<span class="ruby-identifier">to_i</span> <span class="ruby-operator">&gt;</span> <span class="ruby-number">0</span>)
<span class="ruby-identifier">respond_to</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">format</span><span class="ruby-operator">|</span>
<span class="ruby-keyword">if</span> <span class="ruby-ivar">@admin_user</span>.<span class="ruby-identifier">update_attributes</span>(<span class="ruby-identifier">params</span>[<span class="ruby-value">:user</span>], <span class="ruby-identifier">as</span><span class="ruby-operator">:</span> <span class="ruby-value">:admin</span>)
<span class="ruby-identifier">format</span>.<span class="ruby-identifier">html</span> { <span class="ruby-identifier">redirect_to</span> [<span class="ruby-value">:admin</span>, <span class="ruby-ivar">@admin_user</span>], <span class="ruby-identifier">notice</span><span class="ruby-operator">:</span> <span class="ruby-string">'User was successfully updated.'</span> }
<span class="ruby-identifier">format</span>.<span class="ruby-identifier">json</span> { <span class="ruby-identifier">head</span> <span class="ruby-value">:ok</span> }
<span class="ruby-keyword">else</span>
<span class="ruby-identifier">format</span>.<span class="ruby-identifier">html</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">action</span><span class="ruby-operator">:</span> <span class="ruby-string">&quot;edit&quot;</span> }
<span class="ruby-identifier">format</span>.<span class="ruby-identifier">json</span> { <span class="ruby-identifier">render</span> <span class="ruby-identifier">json</span><span class="ruby-operator">:</span> <span class="ruby-ivar">@admin_user</span>.<span class="ruby-identifier">errors</span>, <span class="ruby-identifier">status</span><span class="ruby-operator">:</span> <span class="ruby-value">:unprocessable_entity</span> }
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">end</span></pre>
</div>
</div>
</div>
</div>
</div>
</body>
</html>