提交 34c15c77 编写于 作者: M mindless

[FIXED HUDSON-1867] Add ability to delete users from Hudson


git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@24009 71c3de6d-444a-0410-be80-ed276b4c234a
上级 51fa0395
......@@ -48,6 +48,7 @@ import org.kohsuke.stapler.export.ExportedBean;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletResponse;
import java.io.File;
import java.io.IOException;
import java.io.FileFilter;
......@@ -302,6 +303,7 @@ public class User extends AbstractModelObject implements AccessControlled, Savea
}
private static volatile long lastScanned;
/**
* Gets all the users.
*/
......@@ -406,6 +408,19 @@ public class User extends AbstractModelObject implements AccessControlled, Savea
SaveableListener.fireOnChange(this, getConfigFile());
}
/**
* Deletes the data directory and removes this user from Hudson.
*
* @throws IOException
* if we fail to delete.
*/
public synchronized void delete() throws IOException {
synchronized (byName) {
byName.remove(id);
Util.deleteRecursive(new File(getRootDir(), id));
}
}
/**
* Exposed remote API.
*/
......@@ -447,6 +462,22 @@ public class User extends AbstractModelObject implements AccessControlled, Savea
rsp.sendRedirect(".");
}
/**
* Deletes this user from Hudson.
*/
public void doDoDelete(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException {
requirePOST();
checkPermission(Hudson.ADMINISTER);
if (id.equals(Hudson.getAuthentication().getName())) {
rsp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Cannot delete self");
return;
}
delete();
rsp.sendRedirect2("../..");
}
public void doRssAll( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
rss(req, rsp, " all builds", RunList.fromRuns(getBuilds()));
}
......@@ -528,6 +559,14 @@ public class User extends AbstractModelObject implements AccessControlled, Savea
return getACL().hasPermission(permission);
}
/**
* With ADMINISTER permission, can delete users with persisted data but can't delete self.
*/
public boolean canDelete() {
return hasPermission(Hudson.ADMINISTER) && !id.equals(Hudson.getAuthentication().getName())
&& new File(getRootDir(), id).exists();
}
public Object getDynamic(String token) {
for (UserProperty property: getProperties().values()) {
if (property instanceof Action) {
......
<!--
The MIT License
Copyright (c) 2004-2009, Sun Microsystems, Inc., Alan Harder
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form" xmlns:i="jelly:fmt">
<l:layout>
<st:include page="sidepanel.jelly" />
<l:main-panel>
<form method="post" action="doDelete" name="delete">
${%Are you sure about deleting the user from Hudson?}
<f:submit value="${%Yes}" />
</form>
</l:main-panel>
</l:layout>
</j:jelly>
......@@ -33,7 +33,10 @@ THE SOFTWARE.
<l:task icon="images/24x24/search.gif" href="${rootURL}/${it.url}/" title="${%Status}" />
<l:task icon="images/24x24/notepad.gif" href="${rootURL}/${it.url}/builds" title="${%Builds}" />
<l:task icon="images/24x24/notepad.gif" href="${rootURL}/${it.url}/my-views/" title="${%My Views}" />
<l:task icon="images/24x24/setting.gif" href="${rootURL}/${it.url}/configure" title="${%Configure}" permission="${app.ADMINISTER}"/>
<l:task icon="images/24x24/setting.gif" href="${rootURL}/${it.url}/configure" title="${%Configure}" permission="${app.ADMINISTER}" />
<j:if test="${it.canDelete()}">
<l:task icon="images/24x24/edit-delete.gif" href="${rootURL}/${it.url}/delete" title="${%Delete}" />
</j:if>
<!-- TODO add all UserProperties that are also actions -->
</l:tasks>
</l:side-panel>
......
......@@ -39,7 +39,12 @@ THE SOFTWARE.
<tr>
<td><a href="${user.url}/"><img src="${imagesURL}/32x32/user.gif" alt=""/></a></td>
<td><a href="${user.url}/">${user}</a></td>
<td><a href="${user.url}/configure"><img src="${imagesURL}/32x32/setting.gif" alt="Setting"/></a></td>
<td>
<a href="${user.url}/configure"><img src="${imagesURL}/32x32/setting.gif" alt="Setting"/></a>
<j:if test="${user.canDelete()}">
<a href="${user.url}/delete"><img src="${imagesURL}/24x24/edit-delete.gif" alt="Delete"/></a>
</j:if>
</td>
</tr>
</j:forEach>
</table>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册