Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
API update to 9.2
Browse files Browse the repository at this point in the history
  • Loading branch information
Cyberboss committed Aug 29, 2021
1 parent 38c1a62 commit c861a24
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<OutputType>Exe</OutputType>
<RuntimeIdentifiers>win-x64;linux-x64</RuntimeIdentifiers>
<TargetFramework>net5.0</TargetFramework>
<Version>2.2.1</Version>
<Version>2.3.0</Version>
<LangVersion>latest</LangVersion>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)'=='Release'">
Expand Down Expand Up @@ -74,7 +74,7 @@
<PackageReference Include="System.Reactive" Version="5.0.0" />
<PackageReference Include="System.Security.Cryptography.ProtectedData" Version="5.0.0" />
<PackageReference Include="TextCopy" Version="4.3.1" />
<PackageReference Include="Tgstation.Server.Client" Version="10.1.0" />
<PackageReference Include="Tgstation.Server.Client" Version="10.2.0" />
</ItemGroup>
<ItemGroup>
<Compile Update="Views\Pages\AddUserGroup.xaml.cs">
Expand Down
26 changes: 22 additions & 4 deletions src/Tgstation.Server.ControlPanel/ViewModels/CompilerViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,16 @@ public int NewPort
Update.Recheck();
}
}

public int NewTimeout
{
get => newTimeout ?? ((int?)model.Timeout?.TotalMinutes) ?? 60;
set
{
this.RaiseAndSetIfChanged(ref newTimeout, value);
Update.Recheck();
}
}
public string NewDme
{
get => newDme;
Expand Down Expand Up @@ -150,6 +160,7 @@ public bool ApiRequire
public bool CanSecurity => rightsProvider.DreamMakerRights.HasFlag(DreamMakerRights.SetSecurityLevel);
public bool CanSecurityView => !Refreshing && CanSecurity;
public bool CanPortView => !Refreshing && CanPort;
public bool CanTimeout => rightsProvider.DreamMakerRights.HasFlag(DreamMakerRights.SetTimeout);

public EnumCommand<CompilerCommand> Close { get; }
public EnumCommand<CompilerCommand> Refresh { get; }
Expand All @@ -175,6 +186,7 @@ public bool ApiRequire

string newDme;
int newPort;
int? newTimeout;

bool refreshing;
bool apiRequire;
Expand Down Expand Up @@ -207,6 +219,7 @@ public CompilerViewModel(PageContextViewModel pageContext, IDreamMakerClient dre
this.RaisePropertyChanged(nameof(CanGetJobs));
this.RaisePropertyChanged(nameof(CanPort));
this.RaisePropertyChanged(nameof(CanDme));
this.RaisePropertyChanged(nameof(CanTimeout));
};

jobPages = new Dictionary<int, IReadOnlyList<CompileJobViewModel>>();
Expand Down Expand Up @@ -240,6 +253,7 @@ void ResetFields()
{
NewDme = string.Empty;
NewPort = 0;
this.RaiseAndSetIfChanged(ref newTimeout, null);
AutoDetectDme = Model?.ProjectName == null;
newSecurityLevel = Model?.ApiValidationSecurityLevel ?? DreamDaemonSecurity.Safe;
ApiRequire = Model?.RequireDMApiValidation ?? true;
Expand Down Expand Up @@ -273,7 +287,7 @@ async Task DoRefresh(CancellationToken cancellationToken)
jobPages.Clear();
selectedPage = 0;

await LoadPage(cancellationToken).ConfigureAwait(true);
await LoadPage().ConfigureAwait(true);

await readTask.ConfigureAwait(true);
ResetFields();
Expand All @@ -284,7 +298,7 @@ async Task DoRefresh(CancellationToken cancellationToken)
}
}

async Task LoadPage(CancellationToken cancellationToken)
async Task LoadPage()
{
Refreshing = true;
try
Expand Down Expand Up @@ -325,6 +339,7 @@ public bool CanRunCommand(CompilerCommand command)
//either a new dme name is set, or the checkbox is different than the model
&& (!string.IsNullOrEmpty(NewDme) || (AutoDetectDme ^ (Model?.ProjectName == null))
|| NewPort != 0
|| newTimeout.HasValue
|| newSecurityLevel != Model?.ApiValidationSecurityLevel
|| ApiRequire != (Model?.RequireDMApiValidation ?? true)),
CompilerCommand.Compile => !Refreshing && CanCompile,
Expand Down Expand Up @@ -356,11 +371,11 @@ public async Task RunCommand(CompilerCommand command, CancellationToken cancella
break;
case CompilerCommand.LastPage:
--selectedPage;
await LoadPage(cancellationToken).ConfigureAwait(true);
await LoadPage().ConfigureAwait(true);
break;
case CompilerCommand.NextPage:
++selectedPage;
await LoadPage(cancellationToken).ConfigureAwait(true);
await LoadPage().ConfigureAwait(true);
break;
case CompilerCommand.Refresh:
await DoRefresh(cancellationToken).ConfigureAwait(true);
Expand All @@ -382,6 +397,9 @@ public async Task RunCommand(CompilerCommand command, CancellationToken cancella
if (CanPort && NewPort != 0)
newModel.ApiValidationPort = (ushort)NewPort;

if (CanTimeout && newTimeout.HasValue)
newModel.Timeout = TimeSpan.FromMinutes(NewTimeout);

if (CanSecurity && newSecurityLevel != Model.ApiValidationSecurityLevel)
newModel.ApiValidationSecurityLevel = newSecurityLevel;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ public DreamDaemonResponse Model
this.RaisePropertyChanged(nameof(HasRevision));
this.RaisePropertyChanged(nameof(HasStagedRevision));
this.RaisePropertyChanged(nameof(NewAdditionalParams));
this.RaisePropertyChanged(nameof(CurrentVisibility));
if (model != null)
{
SoftRestart = model.SoftRestart.Value;
Expand All @@ -72,7 +73,24 @@ public DreamDaemonResponse Model
public string Port => (Model?.CurrentPort ?? Model?.Port)?.ToString(CultureInfo.InvariantCulture) ?? "Unknown";
public string Graceful => Model == null || !CanRevision ? "Unknown" : Model.SoftRestart.Value ? "Restart" : Model.SoftShutdown.Value ? "Stop" : "None";

public string CurrentSecurity => !(Model?.CurrentSecurity ?? Model?.SecurityLevel).HasValue ? "Unknown" : Model.CurrentSecurity == DreamDaemonSecurity.Safe ? "Safe" : Model.CurrentSecurity == DreamDaemonSecurity.Ultrasafe ? "Ultrasafe" : "Trusted";
public string CurrentSecurity
{
get
{
var currentSecurity = Model?.CurrentSecurity ?? Model?.SecurityLevel;
return !currentSecurity.HasValue ? "Unknown" : currentSecurity == DreamDaemonSecurity.Safe ? "Safe" : currentSecurity == DreamDaemonSecurity.Ultrasafe ? "Ultrasafe" : "Trusted";
}
}

public string CurrentVisibility
{
get
{
var currentVisibility = Model?.CurrentVisibility ?? Model?.Visibility;
var result = !currentVisibility.HasValue ? "Unknown" : currentVisibility == DreamDaemonVisibility.Private ? "Private" : currentVisibility == DreamDaemonVisibility.Public ? "Public" : "Invisible";
return result;
}
}
public string StatusString => !(Model?.Status).HasValue ? "Unknown" : Model.Status.ToString();

public IBrush StatusColour => new SolidColorBrush(!(Model?.Status).HasValue ? Colors.Black :
Expand Down Expand Up @@ -136,6 +154,24 @@ public bool Trusted
set => Model.SecurityLevel = value ? DreamDaemonSecurity.Trusted : null;
}

public bool PublicVis
{
get => Model?.Visibility == DreamDaemonVisibility.Public;
set => Model.Visibility = value ? DreamDaemonVisibility.Public : null;
}

public bool PrivateVis
{
get => Model?.Visibility == DreamDaemonVisibility.Private;
set => Model.Visibility = value ? DreamDaemonVisibility.Private : null;
}

public bool InvisiVis
{
get => Model?.Visibility == DreamDaemonVisibility.Invisible;
set => Model.Visibility = value ? DreamDaemonVisibility.Invisible : null;
}

public uint NewStartupTimeout
{
get => newStartupTimeout;
Expand Down Expand Up @@ -198,6 +234,7 @@ public bool NewAutoStart
public bool CanHeartbeat => rightsProvider.DreamDaemonRights.HasFlag(DreamDaemonRights.SetHeartbeatInterval);
public bool CanDump => rightsProvider.DreamDaemonRights.HasFlag(DreamDaemonRights.CreateDump);
public bool CanAdditionalParams => rightsProvider.DreamDaemonRights.HasFlag(DreamDaemonRights.SetAdditionalParameters);
public bool CanVisibility => rightsProvider.DreamDaemonRights.HasFlag(DreamDaemonRights.SetVisibility);

public EnumCommand<DreamDaemonCommand> Close { get; }
public EnumCommand<DreamDaemonCommand> Refresh { get; }
Expand All @@ -219,6 +256,7 @@ public bool NewAutoStart
DreamDaemonResponse model;

DreamDaemonSecurity? initalSecurityLevel;
DreamDaemonVisibility? initalVisibility;

uint newStartupTimeout;
uint newHeartbeatSeconds;
Expand Down Expand Up @@ -307,6 +345,7 @@ void LoadModel(DreamDaemonResponse model)
NewAllowWebClient = Model.AllowWebClient ?? false;
NewAdditionalParams = Model.AdditionalParameters ?? string.Empty;
initalSecurityLevel = Model.SecurityLevel;
initalVisibility = Model.Visibility;

ClearSoft = true;
if (CanMetadata)
Expand Down Expand Up @@ -353,7 +392,7 @@ public bool CanRunCommand(DreamDaemonCommand command)
DreamDaemonCommand.Start => !Refreshing && rightsProvider.DreamDaemonRights.HasFlag(DreamDaemonRights.Start) && Model?.Status.Value == WatchdogStatus.Offline,
DreamDaemonCommand.Stop => !Refreshing && rightsProvider.DreamDaemonRights.HasFlag(DreamDaemonRights.Shutdown) && Model?.Status.Value != WatchdogStatus.Offline,
DreamDaemonCommand.Restart => !Refreshing && rightsProvider.DreamDaemonRights.HasFlag(DreamDaemonRights.Restart) && Model?.Status.Value != WatchdogStatus.Offline,
DreamDaemonCommand.Update => !Refreshing && (CanAutoStart || CanPort || CanWebClient || CanSecurity || CanSoftRestart || CanSoftStop || CanTimeout || CanTopic || CanAdditionalParams) && NewPrimaryPort != 0,
DreamDaemonCommand.Update => !Refreshing && (CanAutoStart || CanPort || CanWebClient || CanSecurity || CanSoftRestart || CanSoftStop || CanTimeout || CanVisibility || CanTopic || CanAdditionalParams) && NewPrimaryPort != 0,
DreamDaemonCommand.Dump => !Refreshing && Model?.Status.Value != WatchdogStatus.Offline && CanDump,
DreamDaemonCommand.Join => !Refreshing && Model?.Status.Value == WatchdogStatus.Online,
_ => throw new ArgumentOutOfRangeException(nameof(command), command, "Invalid command!"),
Expand Down Expand Up @@ -415,6 +454,7 @@ async void ResetShutdown()
TopicRequestTimeout = CanTopic && Model.TopicRequestTimeout != NewTopicTimeout ? (uint?)NewTopicTimeout : null,
HeartbeatSeconds = CanHeartbeat && Model.HeartbeatSeconds != NewHeartbeatSeconds ? (uint?)NewHeartbeatSeconds : null,
AdditionalParameters = CanAdditionalParams && Model.AdditionalParameters != NewAdditionalParams ? NewAdditionalParams : null,
Visibility = CanVisibility && Model.Visibility != initalVisibility ? Model.Visibility : null,
};

if (CanSoftRestart)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,18 @@ public bool RepoOrigin
newRepositoryRights &= ~right;
}
}
public bool RepoSubmodule
{
get => newRepositoryRights.HasFlag(RepositoryRights.ChangeSubmoduleUpdate);
set
{
var right = RepositoryRights.ChangeSubmoduleUpdate;
if (value)
newRepositoryRights |= right;
else
newRepositoryRights &= ~right;
}
}
public bool RepoSha
{
get => newRepositoryRights.HasFlag(RepositoryRights.SetSha);
Expand Down Expand Up @@ -346,6 +358,18 @@ public bool CompDme
newDreamMakerRights &= ~right;
}
}
public bool CompTimeout
{
get => newDreamMakerRights.HasFlag(DreamMakerRights.SetTimeout);
set
{
var right = DreamMakerRights.SetTimeout;
if (value)
newDreamMakerRights |= right;
else
newDreamMakerRights &= ~right;
}
}
public bool CompVali
{
get => newDreamMakerRights.HasFlag(DreamMakerRights.SetApiValidationPort);
Expand Down Expand Up @@ -431,6 +455,18 @@ public bool DDAuto
newDreamDaemonRights &= ~right;
}
}
public bool DDVisibility
{
get => newDreamDaemonRights.HasFlag(DreamDaemonRights.SetVisibility);
set
{
var right = DreamDaemonRights.SetVisibility;
if (value)
newDreamDaemonRights |= right;
else
newDreamDaemonRights &= ~right;
}
}
public bool DDSec
{
get => newDreamDaemonRights.HasFlag(DreamDaemonRights.SetSecurity);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ public bool NewGitHubDeployments
set => this.RaiseAndSetIfChanged(ref newGitHubDeployments, value);
}

public bool UpdateSubmodules { get; set; } = true;
public bool UpdateSubmodules { get; set; }

public string DeleteText => confirmingDelete ? "Confirm?" : "Delete Repository";

Expand All @@ -200,6 +200,7 @@ public bool NewGitHubDeployments
public bool CanSetRef => !Refreshing && rightsProvider.RepositoryRights.HasFlag(RepositoryRights.SetReference) && string.IsNullOrEmpty(NewSha) && !UpdateHard;
public bool CanSetSha => !Refreshing && rightsProvider.RepositoryRights.HasFlag(RepositoryRights.SetSha) && string.IsNullOrEmpty(NewReference);
public bool CanShowTMCommitters => !Refreshing && rightsProvider.RepositoryRights.HasFlag(RepositoryRights.ChangeTestMergeCommits);
public bool CanUpdateSubmodules => !Refreshing && rightsProvider.RepositoryRights.HasFlag(RepositoryRights.ChangeSubmoduleUpdate);
public bool CanChangeCommitter => !Refreshing && rightsProvider.RepositoryRights.HasFlag(RepositoryRights.ChangeCommitter);
public bool CanAccess => !Refreshing && rightsProvider.RepositoryRights.HasFlag(RepositoryRights.ChangeCredentials);
public bool CanAutoUpdate => !Refreshing && rightsProvider.RepositoryRights.HasFlag(RepositoryRights.ChangeAutoUpdateSettings);
Expand Down Expand Up @@ -394,6 +395,7 @@ void RecheckCommands()
this.RaisePropertyChanged(nameof(CanUpdate));
this.RaisePropertyChanged(nameof(CanDelete));
this.RaisePropertyChanged(nameof(CanClone));
this.RaisePropertyChanged(nameof(CanUpdateSubmodules));
}

async Task<JobResponse> Refresh(RepositoryUpdateRequest update, RepositoryCreateRequest clone, bool delete, CancellationToken cancellationToken)
Expand Down Expand Up @@ -440,6 +442,7 @@ async Task<JobResponse> Refresh(RepositoryUpdateRequest update, RepositoryCreate
NewCommitterName = string.Empty;
NewAccessUser = string.Empty;
NewAccessToken = string.Empty;
UpdateSubmodules = newRepo.UpdateSubmodules.Value;

UpdateHard = false;
UpdateMerge = false;
Expand Down Expand Up @@ -764,7 +767,7 @@ public async Task RunCommand(RepositoryCommand command, CancellationToken cancel

CommitterEmail = !string.IsNullOrEmpty(NewCommitterEmail) ? NewCommitterEmail : null,
CommitterName = !string.IsNullOrEmpty(NewCommitterName) ? NewCommitterName : null,
UpdateSubmodules = UpdateSubmodules,
UpdateSubmodules = CanUpdateSubmodules ? UpdateSubmodules : null,
};

if (modifiedPRList || UpdateHard)
Expand Down Expand Up @@ -815,7 +818,7 @@ async void ResetDelete()
Reference = string.IsNullOrEmpty(NewReference) ? null : NewReference,
AccessToken = string.IsNullOrEmpty(NewAccessToken) || !CanAccess ? null : NewAccessToken,
AccessUser = string.IsNullOrEmpty(NewAccessUser) || !CanAccess ? null : NewAccessUser,
RecurseSubmodules = RecurseSubmodules
UpdateSubmodules = RecurseSubmodules
};
await Refresh(null, clone, false, cancellationToken).ConfigureAwait(true);
break;
Expand Down
6 changes: 4 additions & 2 deletions src/Tgstation.Server.ControlPanel/Views/Pages/DreamMaker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,10 @@
<CheckBox Background="White" ToolTip.Tip="The DMAPI facilitates communication between DreamDaemon and TGS. It enables features such as heartbeats, custom chat commands/messages, and graceful actions such as changing security levels or enabling and disabling the web client among other things. Without it, the server will need to be manually rebooted from TGS when such changes are made." IsChecked="{Binding ApiRequire}" IsEnabled="{Binding CanRequire}" DockPanel.Dock="Left"/>
<TextBlock Text="Require DMAPI for deployments to succeed (Reccommended)" ToolTip.Tip="The DMAPI facilitates communication between DreamDaemon and TGS. It enables features such as heartbeats, custom chat commands/messages, and graceful actions such as changing security levels or enabling and disabling the web client among other things. Without it, the server will need to be manually rebooted from TGS when such changes are made." Margin="5,0,0,0" DockPanel.Dock="Right"/>
</DockPanel>
<TextBlock Text="Port Used For TGS DMAPI Validation (should be private, 0 doesn't change):" Grid.Row="3" Grid.Column="0" Margin="0,5,0,0"/>
<NumericUpDown Minimum="0" Maximum="65535" Value="{Binding NewPort}" IsEnabled="{Binding CanPortView}" Margin="5,0,0,0" Grid.Row="3" Grid.Column="1"/>
<TextBlock Text="Port Used For TGS DMAPI Validation (should be private, 0 doesn't change):" Grid.Row="3" Grid.Column="0" Margin="0,5,0,0"/>
<NumericUpDown Minimum="0" Maximum="65535" Value="{Binding NewPort}" IsEnabled="{Binding CanPortView}" Margin="5,0,0,0" Grid.Row="3" Grid.Column="1"/>
<TextBlock Text="Deployment Timeout (Minutes):" Grid.Row="4" Grid.Column="0" Margin="0,5,0,0"/>
<NumericUpDown Minimum="1" Value="{Binding NewTimeout}" IsEnabled="{Binding CanTimeout}" Margin="5,0,0,0" Grid.Row="4" Grid.Column="1"/>
</Grid>
<Grid IsEnabled="{Binding CanSecurityView}">
<Grid.RowDefinitions>
Expand Down
26 changes: 20 additions & 6 deletions src/Tgstation.Server.ControlPanel/Views/Pages/InstanceUser.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,14 @@
<CheckBox Background="White" IsChecked="{Binding RepoCancelClone, Mode=TwoWay}"/>
<TextBlock DockPanel.Dock="Right" Text="Cancel Clone Jobs" Margin="5,4,0,0" />
</DockPanel>
<DockPanel Grid.Column="0" Grid.Row="6" Margin="2">
<CheckBox Background="White" IsChecked="{Binding RepoCancelUpdate, Mode=TwoWay}"/>
<TextBlock DockPanel.Dock="Right" Text="Cancel Update Jobs" Margin="5,4,0,0" />
</DockPanel>
<DockPanel Grid.Column="0" Grid.Row="6" Margin="2">
<CheckBox Background="White" IsChecked="{Binding RepoCancelUpdate, Mode=TwoWay}"/>
<TextBlock DockPanel.Dock="Right" Text="Cancel Update Jobs" Margin="5,4,0,0" />
</DockPanel>
<DockPanel Grid.Column="1" Grid.Row="6" Margin="2">
<CheckBox Background="White" IsChecked="{Binding RepoSubmodule, Mode=TwoWay}"/>
<TextBlock DockPanel.Dock="Right" Text="Change Submodule Update Settings" Margin="5,4,0,0" />
</DockPanel>
</Grid>
</StackPanel>
<Rectangle HorizontalAlignment="Stretch" Fill="#A0A0A0" Height="1" Margin="0,5,0,0"/>
Expand Down Expand Up @@ -163,7 +167,8 @@
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
Expand Down Expand Up @@ -200,6 +205,10 @@
<CheckBox Background="White" IsChecked="{Binding CompReq, Mode=TwoWay}"/>
<TextBlock DockPanel.Dock="Right" Text="Change DMAPI Requirement for Deployments" Margin="5,4,0,0" />
</DockPanel>
<DockPanel Grid.Column="0" Grid.Row="4" Margin="2">
<CheckBox Background="White" IsChecked="{Binding CompTimeout, Mode=TwoWay}"/>
<TextBlock DockPanel.Dock="Right" Text="Change Deployment Timeout" Margin="5,4,0,0" />
</DockPanel>
</Grid>
<Rectangle HorizontalAlignment="Stretch" Fill="#A0A0A0" Height="1" Margin="0,5,0,0"/>
<Rectangle HorizontalAlignment="Stretch" Fill="#FFFFFF" Height="1" Margin="0,0,0,5"/>
Expand All @@ -210,7 +219,8 @@
<ColumnDefinition Width="1*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
<RowDefinition Height="1*"/>
Expand Down Expand Up @@ -283,6 +293,10 @@
<CheckBox Background="White" IsChecked="{Binding DDAdditionalParams, Mode=TwoWay}"/>
<TextBlock DockPanel.Dock="Right" Text="Set Additional DreamDaemon Params" Margin="5,4,0,0" />
</DockPanel>
<DockPanel Grid.Column="0" Grid.Row="8" Margin="2">
<CheckBox Background="White" IsChecked="{Binding DDVisibility, Mode=TwoWay}"/>
<TextBlock DockPanel.Dock="Right" Text="Set Visibilty Level" Margin="5,4,0,0" />
</DockPanel>
</Grid>
<Rectangle HorizontalAlignment="Stretch" Fill="#A0A0A0" Height="1" Margin="0,5,0,0"/>
<Rectangle HorizontalAlignment="Stretch" Fill="#FFFFFF" Height="1" Margin="0,0,0,5"/>
Expand Down
Loading

0 comments on commit c861a24

Please sign in to comment.