Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added configurable flag to make settings UI read-only #281

Merged
merged 5 commits into from
Oct 17, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Added
- Web UI includes a "Push Branch" button for local branches that are ahead of upstream
- Support for making the Settings UI read-only through `##class(SourceControl.Git.API).Configure()` (#258)

### Fixed
- Studio export path doesn't get weird mixed slahes on Windows (#252)
Expand Down
5 changes: 5 additions & 0 deletions cls/SourceControl/Git/Settings.cls
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ Property pullEventClass As %String(MAXLEN = 255) [ InitialExpression = {##class(
/// Character to replace % symbol when importing %-classes into the file systems
Property percentClassReplace As %String [ InitialExpression = {##class(SourceControl.Git.Utils).PercentClassReplace()} ];

/// Git project settings are read-only in the web user interface
Property settingsUIReadOnly As %Boolean [ InitialExpression = {##class(SourceControl.Git.Utils).SettingsUIReadOnly()} ];

/// Attribution: Git username for user ${username}
Property gitUserName As %String(MAXLEN = 255) [ InitialExpression = {##class(SourceControl.Git.Utils).GitUserName()} ];

Expand Down Expand Up @@ -72,6 +75,7 @@ Method %Save() As %Status
set @storage@("settings","ssh","privateKeyFile") = ..privateKeyFile
set @storage@("settings","pullEventClass") = ..pullEventClass
set @storage@("settings","percentClassReplace") = ..percentClassReplace
set @storage@("settings","settingsUIReadOnly") = ..settingsUIReadOnly

kill @##class(SourceControl.Git.Utils).MappingsNode()
merge @##class(SourceControl.Git.Utils).MappingsNode() = ..Mappings
Expand Down Expand Up @@ -168,3 +172,4 @@ Method OnAfterConfigure() As %Boolean
}

}

5 changes: 5 additions & 0 deletions cls/SourceControl/Git/Utils.cls
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ ClassMethod PercentClassReplace() As %Status [ CodeMode = expression ]
$Get(@..#Storage@("settings","percentClassReplace"), "")
}

ClassMethod SettingsUIReadOnly() As %Status [ CodeMode = expression ]
{
$Get(@..#Storage@("settings","settingsUIReadOnly"), 0)
}

/// Returns the current (or previous) value of the flag.
ClassMethod Locked(newFlagValue As %Boolean) As %Boolean
{
Expand Down
52 changes: 30 additions & 22 deletions csp/gitprojectsettings.csp
Original file line number Diff line number Diff line change
Expand Up @@ -62,36 +62,37 @@ body {
set webuiURL = ##class(SourceControl.Git.WebUIDriver).GetURLPrefix(%request, webuiURL)

set settings = ##class(SourceControl.Git.Settings).%New()

if $Data(%request.Data("gitsettings",1)) {
for param="gitBinPath","namespaceTemp","privateKeyFile","pullEventClass","percentClassReplace","gitUserName","gitUserEmail"{
set $Property(settings,param) = $Get(%request.Data(param,1))
}
set i = 1
set param = "NoFolders"
kill settings.Mappings

while ( $Data(%request.Data("MappingsExt",i)) ){
if ('settings.settingsUIReadOnly) {
if $Data(%request.Data("gitsettings",1)) {
for param="gitBinPath","namespaceTemp","privateKeyFile","pullEventClass","percentClassReplace","gitUserName","gitUserEmail"{
set $Property(settings,param) = $Get(%request.Data(param,1))
}
set i = 1
set param = "NoFolders"
kill settings.Mappings
while ( $Data(%request.Data("MappingsExt",i)) ){
if ($get(%request.Data("MappingsExt",i)) '= "") {
if ($Get(%request.Data(param,i)) = "NoFolders"){
set settings.Mappings($Get(%request.Data("MappingsExt",i)), $Get(%request.Data("MappingsCov",i)), $Get(%request.Data(param,i))) = 1
}
set settings.Mappings($Get(%request.Data("MappingsExt",i)), $Get(%request.Data("MappingsCov",i))) = $Get(%request.Data("MappingsPath",i))
if ($Get(%request.Data(param,i)) = "NoFolders"){
set settings.Mappings($Get(%request.Data("MappingsExt",i)), $Get(%request.Data("MappingsCov",i)), $Get(%request.Data(param,i))) = 1
}
set settings.Mappings($Get(%request.Data("MappingsExt",i)), $Get(%request.Data("MappingsCov",i))) = $Get(%request.Data("MappingsPath",i))
}
set i = i+1
set i = i+1
}
do settings.%Save()
}
do settings.%Save()
}
</server>
<div class = 'container'>
<form method='post'>
<form id="settingsForm" method='post'>
<input type="hidden" name="Namespace" value="#(..EscapeHTML(namespace))#" />
<input type="hidden" name="gitsettings" value="1" />
<div class="col-sm-12"><br></div>
<div class="row">
<div class="col-sm-1"></div>
<div class="col-sm-8">
<h1>Git Project Settings</h1>
<h1>Git Project Settings #($select(settings.settingsUIReadOnly:"(Read-Only)",1:""))#</h1>
</div>
<div class="col-sm-2">
<button class="btn btn-lg btn-outline-dark" id="goToWebUI">Go to WebUI
Expand Down Expand Up @@ -372,11 +373,13 @@ body {

<br/>

<div class="form-group row mb-3">
<div class="col-sm-12 text-center">
<input type='submit' class="btn-lg btn-primary" value = 'Save'/>
<csp:if condition="'settings.settingsUIReadOnly">
<div class="form-group row mb-3">
<div class="col-sm-12 text-center">
<input type='submit' class="btn-lg btn-primary" value = 'Save'/>
</div>
</div>
</div>
</csp:if>

</form>
<csp:if condition='$D(%request.Data("gitsettings",1)) && (##class(SourceControl.Git.Utils).NeedSettings() = 0)'>
Expand Down Expand Up @@ -440,6 +443,11 @@ $(function () {
});
$(function()
{
if (#(settings.settingsUIReadOnly)#) {
$(document).ready( function() {
$("#settingsForm input, select").attr("disabled",true);
})
}
$(document).on('click', '.btn-add', function(e)
{
e.preventDefault();
Expand Down
Loading