mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-05-07 20:07:30 +02:00
(refs #1286) Update the repository settings form
This commit is contained in:
@@ -242,8 +242,8 @@ trait WikiControllerBase extends ControllerBase {
|
||||
|
||||
private def isEditable(repository: RepositoryInfo)(implicit context: Context): Boolean = {
|
||||
repository.repository.options.wikiOption match {
|
||||
case "ALL" => true // TODO read permission
|
||||
case "PUBLIC" => true // TODO read permission
|
||||
case "ALL" => repository.repository.isPrivate == false || hasReadPermission(repository.owner, repository.name, context.loginAccount)
|
||||
case "PUBLIC" => hasReadPermission(repository.owner, repository.name, context.loginAccount)
|
||||
case "PRIVATE" => hasWritePermission(repository.owner, repository.name, context.loginAccount)
|
||||
case "DISABLE" => false
|
||||
}
|
||||
|
||||
@@ -38,9 +38,9 @@ trait RepositoryService { self: AccountService =>
|
||||
parentUserName = parentUserName,
|
||||
parentRepositoryName = parentRepositoryName,
|
||||
options = RepositoryOptions(
|
||||
issuesOption = "PRIVATE",
|
||||
issuesOption = "PRIVATE", // TODO DISABLE for the forked repository?
|
||||
externalIssuesUrl = None,
|
||||
wikiOption = "PUBLIC",
|
||||
wikiOption = "PUBLIC", // TODO DISABLE for the forked repository?
|
||||
externalWikiUrl = None,
|
||||
allowFork = true
|
||||
)
|
||||
@@ -360,13 +360,15 @@ trait RepositoryService { self: AccountService =>
|
||||
* If a group is added as a collaborator, this method returns users who are belong to that group.
|
||||
*/
|
||||
def getCollaboratorUserNames(userName: String, repositoryName: String, filter: Seq[Permission] = Nil)(implicit s: Session): List[String] = {
|
||||
val q1 = Collaborators.filter(_.byRepository(userName, repositoryName))
|
||||
val q1 = Collaborators
|
||||
.innerJoin(Accounts).on { case (t1, t2) => (t1.collaboratorName === t2.userName) && (t2.groupAccount === false.bind) }
|
||||
.filter { case (t1, t2) => t1.byRepository(userName, repositoryName) }
|
||||
.map { case (t1, t2) => t1.collaboratorName }
|
||||
|
||||
val q2 = Collaborators.filter(_.byRepository(userName, repositoryName))
|
||||
val q2 = Collaborators
|
||||
.innerJoin(Accounts).on { case (t1, t2) => (t1.collaboratorName === t2.userName) && (t2.groupAccount === true.bind) }
|
||||
.innerJoin(GroupMembers).on { case ((t1, t2), t3) => t2.userName === t3.groupName }
|
||||
.filter { case ((t1, t2), t3) => t1.byRepository(userName, repositoryName) }
|
||||
.map { case ((t1, t2), t3) => t3.userName }
|
||||
|
||||
q1.union(q2).list.filter { x => filter.isEmpty || filter.exists(_.name == x) }
|
||||
@@ -383,6 +385,16 @@ trait RepositoryService { self: AccountService =>
|
||||
}
|
||||
}
|
||||
|
||||
def hasReadPermission(owner: String, repository: String, loginAccount: Option[Account])(implicit s: Session): Boolean = {
|
||||
loginAccount match {
|
||||
case Some(a) if(a.isAdmin) => true
|
||||
case Some(a) if(a.userName == owner) => true
|
||||
case Some(a) if(getGroupMembers(owner).exists(_.userName == a.userName)) => true
|
||||
case Some(a) if(getCollaboratorUserNames(owner, repository, Seq(Permission.ADMIN, Permission.WRITE, Permission.READ)).contains(a.userName)) => true
|
||||
case _ => false
|
||||
}
|
||||
}
|
||||
|
||||
private def getForkedCount(userName: String, repositoryName: String)(implicit s: Session): Int =
|
||||
Query(Repositories.filter { t =>
|
||||
(t.originUserName === userName.bind) && (t.originRepositoryName === repositoryName.bind)
|
||||
|
||||
@@ -39,45 +39,6 @@
|
||||
</div>
|
||||
</label>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading strong">Features</div>
|
||||
<div class="panel-body">
|
||||
<fieldset class="form-group">
|
||||
@* TODO Make radio to choose issues option
|
||||
<label class="checkbox" for="enableIssues">
|
||||
<input type="checkbox" id="enableIssues" name="enableIssues"@if(repository.repository.options.enableIssues){ checked}/>
|
||||
Issues<br>
|
||||
<div class="normal muted">
|
||||
Provides Lightweight issue tracking integrated with this repository. Add issues to milestones, label issues, and close & reference issues from commit messages.
|
||||
</div>
|
||||
</label>
|
||||
*@
|
||||
<label for="externalIssuesUrl" class="strong">External URL:
|
||||
<span class="normal muted">(Put if you have the external issue tracking system for this project)</span>
|
||||
</label>
|
||||
<input type="text" class="form-control" id="externalIssuesUrl" name="externalIssuesUrl" value="@repository.repository.options.externalIssuesUrl"/>
|
||||
</fieldset>
|
||||
<fieldset class="form-group">
|
||||
@* TODO Make radio to choose wiki option
|
||||
<label class="checkbox" for="enableWiki">
|
||||
<input type="checkbox" id="enableWiki" name="enableWiki"@if(repository.repository.options.enableWiki){ checked}/>
|
||||
Wiki<br>
|
||||
<div class="normal muted">
|
||||
Provides a simple solution to manage documents. All users who can look this repository can read and collaborators can edit pages.
|
||||
</div>
|
||||
</label>
|
||||
<label class="checkbox" for="allowWikiEditing">
|
||||
<input type="checkbox" id="allowWikiEditing" name="allowWikiEditing"@if(repository.repository.options.allowWikiEditing){ checked}/>
|
||||
Allow read-only users to edit Wiki pages<br>
|
||||
</label>
|
||||
*@
|
||||
<label for="externalWikiUrl" class="strong">External URL:
|
||||
<span class="normal muted">(Put if you have the external Wiki for this project)</span>
|
||||
</label>
|
||||
<input type="text" class="form-control" id="externalWikiUrl" name="externalWikiUrl" value="@repository.repository.options.externalWikiUrl"/>
|
||||
</fieldset>
|
||||
<fieldset class="form-group">
|
||||
<label class="checkbox" for="allowFork">
|
||||
<input type="checkbox" id="allowFork" name="allowFork"@if(repository.repository.options.allowFork){ checked}/>
|
||||
@@ -89,6 +50,68 @@
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading strong">Issues</div>
|
||||
<div class="panel-body">
|
||||
<fieldset class="form-group">
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input type="radio" name="issuesOption" value="DISABLE" @if(repository.repository.options.issuesOption == "DISABLE"){ checked}> Disables issues tracking system
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input type="radio" name="issuesOption" value="PRIVATE" @if(repository.repository.options.issuesOption == "PRIVATE"){ checked}> Writable users can view, create and comment on issues
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input type="radio" name="issuesOption" value="PUBLIC" @if(repository.repository.options.issuesOption == "PUBLIC"){ checked}> Readable users can view, create and comment on isues
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input type="radio" name="issuesOption" value="ALL" @if(repository.repository.options.issuesOption == "ALL"){ checked}> Anyone can view, create and comment on issues
|
||||
</label>
|
||||
</div>
|
||||
<label for="externalIssuesUrl" class="strong">External URL:
|
||||
<span class="normal muted">(Put if you have the external issue tracking system for this project)</span>
|
||||
</label>
|
||||
<input type="text" class="form-control" id="externalIssuesUrl" name="externalIssuesUrl" value="@repository.repository.options.externalIssuesUrl"/>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading strong">Wiki</div>
|
||||
<div class="panel-body">
|
||||
<fieldset class="form-group">
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input type="radio" name="wikiOption" value="DISABLE" @if(repository.repository.options.wikiOption == "DISABLE"){ checked}> Disables wiki
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input type="radio" name="wikiOption" value="PRIVATE" @if(repository.repository.options.wikiOption == "PRIVATE"){ checked}> Writable users can view, create and edit wiki pages
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input type="radio" name="wikiOption" value="PUBLIC" @if(repository.repository.options.wikiOption == "PUBLIC"){ checked}> Readable users can view, create and edit wiki pages
|
||||
</label>
|
||||
</div>
|
||||
<div class="radio">
|
||||
<label>
|
||||
<input type="radio" name="wikiOption" value="ALL" @if(repository.repository.options.wikiOption == "ALL"){ checked}> Anyone can view, create and edit wiki pages
|
||||
</label>
|
||||
</div>
|
||||
<label for="externalWikiUrl" class="strong">External URL:
|
||||
<span class="normal muted">(Put if you have the external Wiki for this project)</span>
|
||||
</label>
|
||||
<input type="text" class="form-control" id="externalWikiUrl" name="externalWikiUrl" value="@repository.repository.options.externalWikiUrl"/>
|
||||
</fieldset>
|
||||
</div>
|
||||
</div>
|
||||
<div class="align-right" style="margin-top: 20px;">
|
||||
<input type="submit" class="btn btn-success" value="Apply changes"/>
|
||||
</div>
|
||||
@@ -100,14 +123,13 @@
|
||||
$(function(){
|
||||
updateFeatures();
|
||||
|
||||
$('#enableIssues, #enableWiki').click(function(){
|
||||
$('input[name=issuesOption], input[name=wikiOption]').click(function(){
|
||||
updateFeatures();
|
||||
});
|
||||
});
|
||||
|
||||
function updateFeatures() {
|
||||
$('#externalIssuesUrl').prop('disabled', $('#enableIssues').prop('checked'));
|
||||
$('#allowWikiEditing').prop('disabled', !$('#enableWiki').prop('checked'));
|
||||
$('#externalWikiUrl').prop('disabled', $('#enableWiki').prop('checked'));
|
||||
$('#externalIssuesUrl').prop('disabled', !$('input[name=issuesOption]').select('[value=DISABLE]').prop('checked'));
|
||||
$('#externalWikiUrl').prop('disabled', !$('input[name=wikiOption]').select('[value=DISABLE]').prop('checked'));
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
to: String,
|
||||
diffs: Seq[gitbucket.core.util.JGitUtil.DiffInfo],
|
||||
repository: gitbucket.core.service.RepositoryService.RepositoryInfo,
|
||||
hasWritePermission: Boolean,
|
||||
isEditable: Boolean,
|
||||
info: Option[Any])(implicit context: gitbucket.core.controller.Context)
|
||||
@import gitbucket.core.view.helpers
|
||||
@gitbucket.core.html.main(s"Compare Revisions - ${repository.owner}/${repository.name}", Some(repository)){
|
||||
@@ -27,7 +27,7 @@
|
||||
<div class="pull-left">
|
||||
@gitbucket.core.helper.html.diff(diffs, repository, None, None, false, None, false, false)
|
||||
</div>
|
||||
@if(hasWritePermission){
|
||||
@if(isEditable){
|
||||
<div>
|
||||
@if(pageName.isDefined){
|
||||
<a href="@helpers.url(repository)/wiki/@helpers.urlEncode(pageName)/_revert/@from...@to" class="btn">Revert Changes</a>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
page: gitbucket.core.service.WikiService.WikiPageInfo,
|
||||
pages: List[String],
|
||||
repository: gitbucket.core.service.RepositoryService.RepositoryInfo,
|
||||
hasWritePermission: Boolean,
|
||||
isEditable: Boolean,
|
||||
sidebar: Option[gitbucket.core.service.WikiService.WikiPageInfo],
|
||||
footer: Option[gitbucket.core.service.WikiService.WikiPageInfo])(implicit context: gitbucket.core.controller.Context)
|
||||
@import gitbucket.core.view.helpers
|
||||
@@ -12,7 +12,7 @@
|
||||
<div>
|
||||
<div class="pull-right">
|
||||
<a class="btn btn-small btn-default" href="@helpers.url(repository)/wiki/@helpers.urlEncode(pageName)/_history">Page History</a>
|
||||
@if(hasWritePermission){
|
||||
@if(isEditable){
|
||||
<a class="btn btn-default" href="@helpers.url(repository)/wiki/@helpers.urlEncode(pageName)/_edit">Edit Page</a>
|
||||
<a class="btn btn-success" href="@helpers.url(repository)/wiki/_new">New Page</a>
|
||||
}
|
||||
@@ -49,13 +49,13 @@
|
||||
}
|
||||
@sidebar.map { sidebarPage =>
|
||||
<div class="wiki-sidebar">
|
||||
@if(hasWritePermission){
|
||||
@if(isEditable){
|
||||
<a href="@helpers.url(repository)/wiki/_Sidebar/_edit" style="text-decoration: none;"><span class="octicon octicon-pencil pull-right"></span></a>
|
||||
}
|
||||
@helpers.markdown(sidebarPage.content, repository, true, false, false, false, pages)
|
||||
</div>
|
||||
}.getOrElse{
|
||||
@if(hasWritePermission){
|
||||
@if(isEditable){
|
||||
<a class="button-link" href="@helpers.url(repository)/wiki/_Sidebar/_edit" style="text-decoration: none;">
|
||||
<div class="wiki-sidebar-dotted text-center"><i class="octicon octicon-plus"></i> Add a custom sidebar</div>
|
||||
</a>
|
||||
@@ -88,13 +88,13 @@
|
||||
</div>
|
||||
@footer.map { footerPage =>
|
||||
<div class="wiki-sidebar wiki-footer">
|
||||
@if(hasWritePermission){
|
||||
@if(isEditable){
|
||||
<a href="@helpers.url(repository)/wiki/_Footer/_edit" style="text-decoration: none;"><span class="octicon octicon-pencil pull-right"></span></a>
|
||||
}
|
||||
@helpers.markdown(footerPage.content, repository, true, false, false, false, pages)
|
||||
</div>
|
||||
}.getOrElse{
|
||||
@if(hasWritePermission){
|
||||
@if(isEditable){
|
||||
<a class="button-link" href="@helpers.url(repository)/wiki/_Footer/_edit" style="text-decoration: none;">
|
||||
<div class="wiki-sidebar-dotted text-center"><i class="octicon octicon-plus"></i> Add a custom footer</div>
|
||||
</a>
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
@(pages: List[String],
|
||||
repository: gitbucket.core.service.RepositoryService.RepositoryInfo,
|
||||
hasWritePermission: Boolean)(implicit context: gitbucket.core.controller.Context)
|
||||
isEditable: Boolean)(implicit context: gitbucket.core.controller.Context)
|
||||
@import gitbucket.core.view.helpers
|
||||
@gitbucket.core.html.main(s"Pages - ${repository.owner}/${repository.name}", Some(repository)){
|
||||
@gitbucket.core.html.menu("wiki", repository){
|
||||
@@ -10,7 +10,7 @@
|
||||
</li>
|
||||
<li class="pull-right">
|
||||
<div class="btn-group">
|
||||
@if(hasWritePermission){
|
||||
@if(isEditable){
|
||||
<a class="btn btn-small btn-default" href="@helpers.url(repository)/wiki/_new">New Page</a>
|
||||
}
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user