package jetbrains.buildserver.metarunner.editor import jetbrains.buildServer.web.openapi.{PluginDescriptor, WebControllerManager} import javax.servlet.http.{HttpServletResponse, HttpServletRequest} import jetbrains.buildServer.controllers.{RequestPermissionsChecker, BaseController, AuthorizationInterceptor} import jetbrains.buildserver.metarunner.UpdatableRunnerSpecs import jetbrains.buildServer.serverSide.auth.{Permission, AuthorityHolder} import scala.collection.JavaConversions._ import org.springframework.web.servlet.ModelAndView import com.intellij.openapi.util.io.FileUtil /** * @author Eugene Petrenko (eugene.petrenko@jetbrains.com) * 16.12.10 18:50 */ class EditController(webControllerManager: WebControllerManager, descriptor: PluginDescriptor, auth: AuthorizationInterceptor, specs: UpdatableRunnerSpecs) extends BaseController { val path = descriptor.getPluginResourcesPath("edit.html") webControllerManager.registerController(path, this) auth.addPathBasedPermissionsChecker(path, new RequestPermissionsChecker() { def checkPermissions(p: AuthorityHolder, p2: HttpServletRequest) = { p.isPermissionGrantedGlobally(Permission.CHANGE_SERVER_SETTINGS) && p.isPermissionGrantedForAnyProject(Permission.EDIT_PROJECT) && p.isPermissionGrantedForAnyProject(Permission.CUSTOMIZE_BUILD_PARAMETERS) } }) def doHandle(p1: HttpServletRequest, p2: HttpServletResponse) = { val rt = specs.findRunnerSpec(p1.getParameter("run-type")) if (rt == null) { simpleView("Meta-Runner id should be defined") } else { val map = Map[String,Any]("editBean" -> new EditBean() { def getHash = "hash-007" def getText = new String(FileUtil.loadFileText(rt.getMetaRunnerXml, "utf8")) }) new ModelAndView(descriptor.getPluginResourcesPath("/edit.jsp"), map) } } }