mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-02 03:26:06 +01:00
Save repository options.
This commit is contained in:
@@ -5,12 +5,19 @@ import jp.sf.amateras.scalatra.forms._
|
||||
|
||||
class SettingsController extends SettingsControllerBase with RepositoryService with AccountService
|
||||
|
||||
|
||||
trait SettingsControllerBase extends ControllerBase { self: RepositoryService with AccountService =>
|
||||
|
||||
case class OptionsForm(description: Option[String], defaultBranch: String, repositoryType: Int)
|
||||
|
||||
val optionsForm = mapping(
|
||||
"description" -> trim(label("Description" , optional(text()))),
|
||||
"defaultBranch" -> trim(label("Default Branch" , text(required, maxlength(100)))),
|
||||
"repositoryType" -> trim(label("Repository Type", number()))
|
||||
)(OptionsForm.apply)
|
||||
|
||||
case class CollaboratorForm(userName: String)
|
||||
|
||||
val form = mapping(
|
||||
val collaboratorForm = mapping(
|
||||
"userName" -> trim(label("Username", text(required, collaborator)))
|
||||
)(CollaboratorForm.apply)
|
||||
|
||||
@@ -27,6 +34,16 @@ trait SettingsControllerBase extends ControllerBase { self: RepositoryService wi
|
||||
settings.html.options(getRepository(owner, repository, servletContext).get)
|
||||
})
|
||||
|
||||
post("/:owner/:repository/settings/options", optionsForm){ form =>
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
|
||||
// save repository options
|
||||
saveRepositoryOptions(owner, repository, form.description, form.defaultBranch, form.repositoryType)
|
||||
|
||||
redirect("%s/%s/settings/options".format(owner, repository))
|
||||
}
|
||||
|
||||
get("/:owner/:repository/settings/collaborators")(ownerOnly {
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
@@ -34,7 +51,7 @@ trait SettingsControllerBase extends ControllerBase { self: RepositoryService wi
|
||||
settings.html.collaborators(getCollaborators(owner, repository), getRepository(owner, repository, servletContext).get)
|
||||
})
|
||||
|
||||
post("/:owner/:repository/settings/collaborators/_add", form)(ownerOnly { form =>
|
||||
post("/:owner/:repository/settings/collaborators/_add", collaboratorForm)(ownerOnly { form =>
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
addCollaborator(owner, repository, form.userName)
|
||||
|
||||
@@ -106,13 +106,21 @@ trait RepositoryService { self: AccountService =>
|
||||
/**
|
||||
* Updates the last activity date of the repository.
|
||||
*/
|
||||
def updateLastActivityDate(userName: String, repositoryName: String): Unit = {
|
||||
val q = for {
|
||||
r <- Repositories if (r.userName is userName.bind) && (r.repositoryName is repositoryName.bind)
|
||||
} yield r.lastActivityDate
|
||||
|
||||
q.update(new java.sql.Date(System.currentTimeMillis))
|
||||
}
|
||||
def updateLastActivityDate(userName: String, repositoryName: String): Unit =
|
||||
Query(Repositories)
|
||||
.filter { r => (r.userName is userName.bind) && (r.repositoryName is repositoryName.bind) }
|
||||
.map { _.lastActivityDate }
|
||||
.update (new java.sql.Date(System.currentTimeMillis))
|
||||
|
||||
/**
|
||||
* Save repository options.
|
||||
*/
|
||||
def saveRepositoryOptions(userName: String, repositoryName: String,
|
||||
description: Option[String], defaultBranch: String, repositoryType: Int): Unit =
|
||||
Query(Repositories)
|
||||
.filter { r => (r.userName is userName.bind) && (r.repositoryName is repositoryName.bind) }
|
||||
.map { r => r.description.? ~ r.defaultBranch ~ r.repositoryType ~ r.updatedDate }
|
||||
.update (description, defaultBranch, repositoryType, new java.sql.Date(System.currentTimeMillis))
|
||||
|
||||
/**
|
||||
* Add collaborator to the repository.
|
||||
|
||||
@@ -3,30 +3,38 @@
|
||||
@html.main("Settings"){
|
||||
@html.header("settings", repository)
|
||||
@menu("options", repository){
|
||||
<form id="form" method="post" action="@path/new" validate="true">
|
||||
<form id="form" method="post" action="@path/@repository.owner/@repository.name/settings/options" validate="true">
|
||||
<div class="box">
|
||||
<div class="box-header">Settings</div>
|
||||
<div class="box-content">
|
||||
<fieldset>
|
||||
<label for="description"><strong>Description</strong></label>
|
||||
<input type="text" name="description" id="description" style="width: 600px;" value="@repository.repository.description"/>
|
||||
</fieldset>
|
||||
<hr>
|
||||
<fieldset>
|
||||
<label for="defaultBranch"><strong>Default Branch</strong></label>
|
||||
<select name="defaultBranch" id="defaultBranch">
|
||||
<option value="master">master</option>
|
||||
@repository.branchList.map { branch =>
|
||||
<option value="@branch"@if(branch==repository.repository.defaultBranch){ selected}>@branch</option>
|
||||
}
|
||||
</select>
|
||||
</fieldset>
|
||||
<hr>
|
||||
<fieldset>
|
||||
<label><strong>Repository Type</strong></label>
|
||||
<label>
|
||||
<input type="radio" name="repositoryType" value="0" checked>
|
||||
<input type="radio" name="repositoryType" value="0"@if(repository.repository.repositoryType==0){ checked}>
|
||||
<strong>Public</strong> - All users and guests can read this repository.
|
||||
</label>
|
||||
<label>
|
||||
<input type="radio" name="repositoryType" value="1">
|
||||
<input type="radio" name="repositoryType" value="1"@if(repository.repository.repositoryType==1){ checked}>
|
||||
<strong>Private</strong> - Only collaborators can read this repository.
|
||||
</label>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
<!--
|
||||
<div class="box">
|
||||
<div class="box-header">Features</div>
|
||||
<div class="box-content">
|
||||
@@ -56,6 +64,7 @@
|
||||
</dl>
|
||||
</div>
|
||||
</div>
|
||||
-->
|
||||
<fieldset>
|
||||
<input type="submit" class="btn btn-primary" value="Apply changes"/>
|
||||
<!--
|
||||
|
||||
Reference in New Issue
Block a user