mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 13:35:50 +01:00
Add System Settings page.
This commit is contained in:
@@ -6,7 +6,8 @@ class ScalatraBootstrap extends LifeCycle {
|
|||||||
override def init(context: ServletContext) {
|
override def init(context: ServletContext) {
|
||||||
context.mount(new IndexController, "/")
|
context.mount(new IndexController, "/")
|
||||||
context.mount(new SignInController, "/*")
|
context.mount(new SignInController, "/*")
|
||||||
context.mount(new UsersController, "/*")
|
context.mount(new UserManagementController, "/*")
|
||||||
|
context.mount(new SystemSettingsController, "/*")
|
||||||
context.mount(new CreateRepositoryController, "/*")
|
context.mount(new CreateRepositoryController, "/*")
|
||||||
context.mount(new AccountController, "/*")
|
context.mount(new AccountController, "/*")
|
||||||
context.mount(new RepositoryViewerController, "/*")
|
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 util.AdminOnlyAuthenticator
|
||||||
import jp.sf.amateras.scalatra.forms._
|
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])
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -11,6 +11,8 @@ object Directory {
|
|||||||
|
|
||||||
val GitBucketHome = new File(System.getProperty("user.home"), "gitbucket").getAbsolutePath
|
val GitBucketHome = new File(System.getProperty("user.home"), "gitbucket").getAbsolutePath
|
||||||
|
|
||||||
|
val GitBucketConf = new File(GitBucketHome, "gitbucket.conf")
|
||||||
|
|
||||||
val RepositoryHome = "%s/repositories".format(GitBucketHome)
|
val RepositoryHome = "%s/repositories".format(GitBucketHome)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
17
src/main/twirl/admin/menu.scala.html
Normal file
17
src/main/twirl/admin/menu.scala.html
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
@(active: String)(body: Html)(implicit context: app.Context)
|
||||||
|
@import context._
|
||||||
|
<div class="row-fluid">
|
||||||
|
<div class="span3">
|
||||||
|
<ul class="nav nav-tabs nav-stacked">
|
||||||
|
<li@if(active=="users"){ class="active"}>
|
||||||
|
<a href="@path/admin/users">User Management</a>
|
||||||
|
</li>
|
||||||
|
<li@if(active=="system"){ class="active"}>
|
||||||
|
<a href="@path/admin/system">System Settings</a>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div class="span9">
|
||||||
|
@body
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
28
src/main/twirl/admin/system.scala.html
Normal file
28
src/main/twirl/admin/system.scala.html
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
@(settings: service.SystemSettingsService.SystemSettings)(implicit context: app.Context)
|
||||||
|
@import context._
|
||||||
|
@import view.helpers._
|
||||||
|
@html.main("System Settings"){
|
||||||
|
@menu("system"){
|
||||||
|
<form action="@path/admin/system" method="POST" validate="true">
|
||||||
|
<div class="box">
|
||||||
|
<div class="box-header">System Settings</div>
|
||||||
|
<div class="box-content">
|
||||||
|
<label><strong>Account registration</strong></label>
|
||||||
|
<fieldset>
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="allowAccountRegistration" value="true"@if(settings.allowAccountRegistration){ checked}>
|
||||||
|
<strong>Allow</strong> - Users can create account by themselves.
|
||||||
|
</label>
|
||||||
|
<label>
|
||||||
|
<input type="radio" name="allowAccountRegistration" value="false"@if(!settings.allowAccountRegistration){ checked}>
|
||||||
|
<strong>Deny</strong> - Only administrators can create account.
|
||||||
|
</label>
|
||||||
|
</fieldset>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<fieldset>
|
||||||
|
<input type="submit" class="btn btn-success" value="Apply changes"/>
|
||||||
|
</fieldset>
|
||||||
|
</form>
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
@(account: Option[model.Account])(implicit context: app.Context)
|
@(account: Option[model.Account])(implicit context: app.Context)
|
||||||
@import context._
|
@import context._
|
||||||
@html.main(if(account.isEmpty) "New User" else "Update User"){
|
@html.main(if(account.isEmpty) "New User" else "Update User"){
|
||||||
|
@menu("users"){
|
||||||
<form method="POST" action="@if(account.isEmpty){@path/admin/users/_new} else {@path/admin/users/@account.get.userName/_edit}" validate="true">
|
<form method="POST" action="@if(account.isEmpty){@path/admin/users/_new} else {@path/admin/users/@account.get.userName/_edit}" validate="true">
|
||||||
<fieldset>
|
<fieldset>
|
||||||
<label for="userName"><strong>Username</strong></label>
|
<label for="userName"><strong>Username</strong></label>
|
||||||
@@ -36,4 +37,5 @@
|
|||||||
<a href="@path/admin/users" class="btn">Cancel</a>
|
<a href="@path/admin/users" class="btn">Cancel</a>
|
||||||
</fieldset>
|
</fieldset>
|
||||||
</form>
|
</form>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,36 +1,41 @@
|
|||||||
@(users: List[model.Account])(implicit context: app.Context)
|
@(users: List[model.Account])(implicit context: app.Context)
|
||||||
@import context._
|
@import context._
|
||||||
@import view.helpers
|
@import view.helpers._
|
||||||
@html.main("Manage Users"){
|
@html.main("Manage Users"){
|
||||||
|
@menu("users"){
|
||||||
<div style="text-align: right; margin-bottom: 4px;">
|
<div style="text-align: right; margin-bottom: 4px;">
|
||||||
<a href="@path/admin/users/_new" class="btn">New User</a>
|
<a href="@path/admin/users/_new" class="btn">New User</a>
|
||||||
</div>
|
</div>
|
||||||
<table class="table table-borderd table-hover">
|
<table class="table table-bordered table-hover">
|
||||||
<tr>
|
|
||||||
<th>Username</th>
|
|
||||||
<th>Mail Address</th>
|
|
||||||
<th>Type</th>
|
|
||||||
<th>URL</th>
|
|
||||||
<th>Registered</th>
|
|
||||||
<th>Updated</th>
|
|
||||||
<th>Last Login</th>
|
|
||||||
</tr>
|
|
||||||
@users.map { account =>
|
@users.map { account =>
|
||||||
<tr>
|
<tr>
|
||||||
<td><a href="@path/admin/users/@account.userName/_edit">@account.userName</a></td>
|
|
||||||
<td>@account.mailAddress</td>
|
|
||||||
<td>
|
<td>
|
||||||
|
<div class="pull-right">
|
||||||
|
<a href="@path/admin/users/@account.userName/_edit">Edit</a>
|
||||||
|
</div>
|
||||||
|
<div class="strong">
|
||||||
|
<a href="@url(account.userName)">@account.userName</a>
|
||||||
@if(account.isAdmin){
|
@if(account.isAdmin){
|
||||||
Administrator
|
(Administrator)
|
||||||
} else {
|
} else {
|
||||||
Normal
|
(Normal)
|
||||||
}
|
}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<hr>
|
||||||
|
<i class="icon-envelope"></i> @account.mailAddress
|
||||||
|
@account.url.map { url =>
|
||||||
|
<i class="icon-home"></i> @url
|
||||||
|
}
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<span class="muted">Registered:</span> @datetime(account.registeredDate)
|
||||||
|
<span class="muted">Updated:</span> @datetime(account.updatedDate)
|
||||||
|
<span class="muted">Last Login:</span> @account.lastLoginDate.map(datetime)
|
||||||
|
</div>
|
||||||
</td>
|
</td>
|
||||||
<td>@account.url</td>
|
|
||||||
<td>@helpers.datetime(account.registeredDate)</td>
|
|
||||||
<td>@helpers.datetime(account.updatedDate)</td>
|
|
||||||
<td>@account.lastLoginDate.map(helpers.datetime)</td>
|
|
||||||
</tr>
|
</tr>
|
||||||
}
|
}
|
||||||
</table>
|
</table>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user