mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-09 06:55:54 +01:00
Add System Settings page.
This commit is contained in:
@@ -6,7 +6,8 @@ class ScalatraBootstrap extends LifeCycle {
|
||||
override def init(context: ServletContext) {
|
||||
context.mount(new IndexController, "/")
|
||||
context.mount(new SignInController, "/*")
|
||||
context.mount(new UsersController, "/*")
|
||||
context.mount(new UserManagementController, "/*")
|
||||
context.mount(new SystemSettingsController, "/*")
|
||||
context.mount(new CreateRepositoryController, "/*")
|
||||
context.mount(new AccountController, "/*")
|
||||
context.mount(new RepositoryViewerController, "/*")
|
||||
|
||||
30
src/main/scala/app/SystemSettingsController.scala
Normal file
30
src/main/scala/app/SystemSettingsController.scala
Normal file
@@ -0,0 +1,30 @@
|
||||
package app
|
||||
|
||||
import service.{AccountService, SystemSettingsService}
|
||||
import SystemSettingsService._
|
||||
import util.AdminOnlyAuthenticator
|
||||
import jp.sf.amateras.scalatra.forms._
|
||||
|
||||
class SystemSettingsController extends SystemSettingsControllerBase
|
||||
with SystemSettingsService with AccountService with AdminOnlyAuthenticator
|
||||
|
||||
trait SystemSettingsControllerBase extends ControllerBase {
|
||||
self: SystemSettingsService with AccountService with AdminOnlyAuthenticator =>
|
||||
|
||||
private case class SystemSettingsForm(allowAccountRegistration: Boolean)
|
||||
|
||||
private val form = mapping(
|
||||
"allowAccountRegistration" -> trim(label("Account registration", boolean()))
|
||||
)(SystemSettingsForm.apply)
|
||||
|
||||
|
||||
get("/admin/system")(adminOnly {
|
||||
admin.html.system(loadSystemSettings())
|
||||
})
|
||||
|
||||
post("/admin/system", form)(adminOnly { form =>
|
||||
saveSystemSettings(SystemSettings(form.allowAccountRegistration))
|
||||
redirect("/admin/system")
|
||||
})
|
||||
|
||||
}
|
||||
@@ -5,9 +5,9 @@ import service._
|
||||
import util.AdminOnlyAuthenticator
|
||||
import jp.sf.amateras.scalatra.forms._
|
||||
|
||||
class UsersController extends UsersControllerBase with AccountService with AdminOnlyAuthenticator
|
||||
class UserManagementController extends UserManagementControllerBase with AccountService with AdminOnlyAuthenticator
|
||||
|
||||
trait UsersControllerBase extends ControllerBase { self: AccountService with AdminOnlyAuthenticator =>
|
||||
trait UserManagementControllerBase extends ControllerBase { self: AccountService with AdminOnlyAuthenticator =>
|
||||
|
||||
case class UserForm(userName: String, password: String, mailAddress: String, isAdmin: Boolean, url: Option[String])
|
||||
|
||||
40
src/main/scala/service/SystemSettingsService.scala
Normal file
40
src/main/scala/service/SystemSettingsService.scala
Normal file
@@ -0,0 +1,40 @@
|
||||
package service
|
||||
|
||||
import util.Directory._
|
||||
import SystemSettingsService._
|
||||
|
||||
trait SystemSettingsService {
|
||||
|
||||
def saveSystemSettings(settings: SystemSettings): Unit = {
|
||||
val props = new java.util.Properties()
|
||||
props.setProperty(AllowAccountRegistration, settings.allowAccountRegistration.toString)
|
||||
props.store(new java.io.FileOutputStream(GitBucketConf), null)
|
||||
}
|
||||
|
||||
|
||||
def loadSystemSettings(): SystemSettings = {
|
||||
val props = new java.util.Properties()
|
||||
if(GitBucketConf.exists){
|
||||
props.load(new java.io.FileInputStream(GitBucketConf))
|
||||
}
|
||||
SystemSettings(getBoolean(props, "allow_account_registration"))
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object SystemSettingsService {
|
||||
|
||||
case class SystemSettings(allowAccountRegistration: Boolean)
|
||||
|
||||
private val AllowAccountRegistration = "allow_account_registration"
|
||||
|
||||
private def getBoolean(props: java.util.Properties, key: String, default: Boolean = false): Boolean = {
|
||||
val value = props.getProperty(key)
|
||||
if(value == null || value.isEmpty){
|
||||
default
|
||||
} else {
|
||||
value.toBoolean
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -10,6 +10,8 @@ import org.eclipse.jgit.lib.Ref
|
||||
object Directory {
|
||||
|
||||
val GitBucketHome = new File(System.getProperty("user.home"), "gitbucket").getAbsolutePath
|
||||
|
||||
val GitBucketConf = new File(GitBucketHome, "gitbucket.conf")
|
||||
|
||||
val RepositoryHome = "%s/repositories".format(GitBucketHome)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user