mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-12-24 09:20:04 +01:00
(refs #474)Add “Allow write access” flag
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
<column name="DEPLOY_KEY_ID" type="int" nullable="false" autoIncrement="true" unique="true"/>
|
||||
<column name="TITLE" type="varchar(100)" nullable="false"/>
|
||||
<column name="PUBLIC_KEY" type="text" nullable="false"/>
|
||||
<column name="ALLOW_WRITE" type="boolean" nullable="false" defaultValueBoolean="false"/>
|
||||
</createTable>
|
||||
|
||||
<addPrimaryKey constraintName="IDX_DEPLOY_KEY_PK" tableName="DEPLOY_KEY" columnNames="USER_NAME, REPOSITORY_NAME, DEPLOY_KEY_ID"/>
|
||||
|
||||
@@ -58,11 +58,12 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
|
||||
|
||||
// for deploy key
|
||||
case class DeployKeyForm(title: String, publicKey: String)
|
||||
case class DeployKeyForm(title: String, publicKey: String, allowWrite: Boolean)
|
||||
|
||||
val deployKeyForm = mapping(
|
||||
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
||||
"publicKey" -> trim(label("Key" , text(required)))
|
||||
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
||||
"publicKey" -> trim(label("Key" , text(required))), // TODO duplication check in the repository?
|
||||
"allowWrite" -> trim(label("Key" , boolean()))
|
||||
)(DeployKeyForm.apply)
|
||||
|
||||
// for web hook url addition
|
||||
@@ -391,7 +392,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
|
||||
/** Register a deploy key */
|
||||
post("/:owner/:repository/settings/deploykey", deployKeyForm)(ownerOnly { (form, repository) =>
|
||||
addDeployKey(repository.owner, repository.name, form.title, form.publicKey)
|
||||
addDeployKey(repository.owner, repository.name, form.title, form.publicKey, form.allowWrite)
|
||||
redirect(s"/${repository.owner}/${repository.name}/settings/deploykey")
|
||||
})
|
||||
|
||||
|
||||
@@ -11,7 +11,8 @@ trait DeployKeyComponent { self: Profile =>
|
||||
val deployKeyId = column[Int]("DEPLOY_KEY_ID", O AutoInc)
|
||||
val title = column[String]("TITLE")
|
||||
val publicKey = column[String]("PUBLIC_KEY")
|
||||
def * = (userName, repositoryName, deployKeyId, title, publicKey) <> (DeployKey.tupled, DeployKey.unapply)
|
||||
val allowWrite = column[Boolean]("ALLOW_WRITE")
|
||||
def * = (userName, repositoryName, deployKeyId, title, publicKey, allowWrite) <> (DeployKey.tupled, DeployKey.unapply)
|
||||
|
||||
def byPrimaryKey(userName: String, repositoryName: String, deployKeyId: Int) =
|
||||
(this.userName === userName.bind) && (this.repositoryName === repositoryName.bind) && (this.deployKeyId === deployKeyId.bind)
|
||||
@@ -23,5 +24,6 @@ case class DeployKey(
|
||||
repositoryName: String,
|
||||
deployKeyId: Int = 0,
|
||||
title: String,
|
||||
publicKey: String
|
||||
publicKey: String,
|
||||
allowWrite: Boolean
|
||||
)
|
||||
|
||||
@@ -6,11 +6,20 @@ import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
|
||||
trait DeployKeyService {
|
||||
|
||||
def addDeployKey(userName: String, repositoryName: String, title: String, publicKey: String)(implicit s: Session): Unit =
|
||||
DeployKeys.insert(DeployKey(userName = userName, repositoryName = repositoryName, title = title, publicKey = publicKey))
|
||||
def addDeployKey(userName: String, repositoryName: String, title: String, publicKey: String, allowWrite: Boolean)
|
||||
(implicit s: Session): Unit =
|
||||
DeployKeys.insert(DeployKey(
|
||||
userName = userName,
|
||||
repositoryName = repositoryName,
|
||||
title = title,
|
||||
publicKey = publicKey,
|
||||
allowWrite = allowWrite
|
||||
))
|
||||
|
||||
def getDeployKeys(userName: String, repositoryName: String)(implicit s: Session): List[DeployKey] =
|
||||
DeployKeys.filter(x => (x.userName === userName.bind) && (x.repositoryName === repositoryName.bind)).sortBy(_.deployKeyId).list
|
||||
DeployKeys
|
||||
.filter(x => (x.userName === userName.bind) && (x.repositoryName === repositoryName.bind))
|
||||
.sortBy(_.deployKeyId).list
|
||||
|
||||
def getAllDeployKeys()(implicit s: Session): List[DeployKey] =
|
||||
DeployKeys.filter(_.publicKey.trim =!= "").list
|
||||
|
||||
@@ -30,7 +30,7 @@
|
||||
<fieldset class="form-group">
|
||||
<label for="publicKey" class="strong">Key</label>
|
||||
<div><span id="error-publicKey" class="error"></span></div>
|
||||
<textarea name="publicKey" id="publicKey" class="form-control" style="height: 250px;"></textarea>
|
||||
<textarea name="publicKey" id="publicKey" class="form-control" style="height: 200px;"></textarea>
|
||||
</fieldset>
|
||||
<input type="submit" class="btn btn-success" value="Add"/>
|
||||
</div>
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
<hr>
|
||||
}
|
||||
<strong style="line-height: 30px;">@key.title</strong> (@SshUtil.fingerPrint(key.publicKey).getOrElse("Key is invalid."))
|
||||
@if(key.allowWrite){
|
||||
<label class="label label-warning">Write access</label>
|
||||
}
|
||||
<a href="@helpers.url(repository)/settings/deploykey/delete/@key.deployKeyId" class="btn btn-sm btn-danger pull-right">Delete</a>
|
||||
}
|
||||
</div>
|
||||
@@ -31,7 +34,12 @@
|
||||
<fieldset class="form-group">
|
||||
<label for="publicKey" class="strong">Key</label>
|
||||
<div><span id="error-publicKey" class="error"></span></div>
|
||||
<textarea name="publicKey" id="publicKey" class="form-control" style="height: 250px;"></textarea>
|
||||
<textarea name="publicKey" id="publicKey" class="form-control" style="height: 200px;"></textarea>
|
||||
</fieldset>
|
||||
<fieldset class="form-group">
|
||||
<label>
|
||||
<input type="checkbox" name="allowWrite"> Allow write access
|
||||
</label>
|
||||
</fieldset>
|
||||
<input type="submit" class="btn btn-success" value="Add"/>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user