diff --git a/src/main/scala/gitbucket/core/controller/AccountController.scala b/src/main/scala/gitbucket/core/controller/AccountController.scala index 51dd1d1..ec883aa 100644 --- a/src/main/scala/gitbucket/core/controller/AccountController.scala +++ b/src/main/scala/gitbucket/core/controller/AccountController.scala @@ -206,9 +206,13 @@ // FileUtils.deleteDirectory(getWikiRepositoryDir(userName, repositoryName)) // FileUtils.deleteDirectory(getTemporaryDir(userName, repositoryName)) // } -// // Remove from GROUP_MEMBER, COLLABORATOR and REPOSITORY + // Remove from GROUP_MEMBER and COLLABORATOR removeUserRelatedData(userName) updateAccount(account.copy(isRemoved = true)) + + // call hooks + PluginRegistry().getAccountHooks.foreach(_.deleted(userName)) + session.invalidate redirect("/") } diff --git a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala index b175eb3..306764b 100644 --- a/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala +++ b/src/main/scala/gitbucket/core/controller/SystemSettingsController.scala @@ -225,7 +225,7 @@ // FileUtils.deleteDirectory(getWikiRepositoryDir(userName, repositoryName)) // FileUtils.deleteDirectory(getTemporaryDir(userName, repositoryName)) // } - // Remove from GROUP_MEMBER, COLLABORATOR and REPOSITORY + // Remove from GROUP_MEMBER and COLLABORATOR removeUserRelatedData(userName) } @@ -239,6 +239,10 @@ isRemoved = form.isRemoved)) updateImage(userName, form.fileId, form.clearImage) + + // call hooks + if(form.isRemoved) PluginRegistry().getAccountHooks.foreach(_.deleted(userName)) + redirect("/admin/users") } } getOrElse NotFound() diff --git a/src/main/scala/gitbucket/core/plugin/AccountHook.scala b/src/main/scala/gitbucket/core/plugin/AccountHook.scala new file mode 100644 index 0000000..b6db885 --- /dev/null +++ b/src/main/scala/gitbucket/core/plugin/AccountHook.scala @@ -0,0 +1,10 @@ +package gitbucket.core.plugin + +import gitbucket.core.model.Profile._ +import profile.api._ + +trait AccountHook { + + def deleted(userName: String)(implicit session: Session): Unit = () + +} diff --git a/src/main/scala/gitbucket/core/plugin/Plugin.scala b/src/main/scala/gitbucket/core/plugin/Plugin.scala index 5be1caa..3d2b51b 100644 --- a/src/main/scala/gitbucket/core/plugin/Plugin.scala +++ b/src/main/scala/gitbucket/core/plugin/Plugin.scala @@ -72,6 +72,16 @@ def repositoryRoutings(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[GitRepositoryRouting] = Nil /** + * Override to add account hooks. + */ + val accountHooks: Seq[AccountHook] = Nil + + /** + * Override to add account hooks. + */ + def accountHooks(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[AccountHook] = Nil + + /** * Override to add receive hooks. */ val receiveHooks: Seq[ReceiveHook] = Nil @@ -241,6 +251,9 @@ (repositoryRoutings ++ repositoryRoutings(registry, context, settings)).foreach { routing => registry.addRepositoryRouting(routing) } + (accountHooks ++ accountHooks(registry, context, settings)).foreach { accountHook => + registry.addAccountHook(accountHook) + } (receiveHooks ++ receiveHooks(registry, context, settings)).foreach { receiveHook => registry.addReceiveHook(receiveHook) } diff --git a/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala b/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala index b81afa0..c6dcc62 100644 --- a/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala +++ b/src/main/scala/gitbucket/core/plugin/PluginRegistory.scala @@ -33,6 +33,7 @@ "md" -> MarkdownRenderer, "markdown" -> MarkdownRenderer ) private val repositoryRoutings = new ListBuffer[GitRepositoryRouting] + private val accountHooks = new ListBuffer[AccountHook] private val receiveHooks = new ListBuffer[ReceiveHook] receiveHooks += new ProtectedBranchReceiveHook() @@ -103,6 +104,10 @@ } } + def addAccountHook(accountHook: AccountHook): Unit = accountHooks += accountHook + + def getAccountHooks: Seq[AccountHook] = accountHooks.toSeq + def addReceiveHook(commitHook: ReceiveHook): Unit = receiveHooks += commitHook def getReceiveHooks: Seq[ReceiveHook] = receiveHooks.toSeq