[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
This commit is contained in:
mindless committed 2009-11-24 03:59:43 +00:00
1 parent 51fa0395d4
commit 34c15c775e
4 files changed
+85 -3

No files matched your search

+39
View File
@@ -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) {