Skip to content

Commit

Permalink
Fix messaging on Tempo login failure
Browse files Browse the repository at this point in the history
  • Loading branch information
BlythMeister committed Jul 13, 2020
1 parent 329e0ba commit d154de6
Show file tree
Hide file tree
Showing 11 changed files with 154 additions and 33 deletions.
30 changes: 30 additions & 0 deletions src/Gallifrey.Jira/ConnectionError.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;

namespace Gallifrey.Jira
{
public class ConnectionError : Exception
{
public Type ConnectionType { get; }

public enum Type
{
Jira,
Tempo
}

public ConnectionError(Type connectionType)
{
ConnectionType = connectionType;
}

public ConnectionError(Type connectionType, string message) : base(message)
{
ConnectionType = connectionType;
}

public ConnectionError(Type connectionType, string message, Exception innerException) : base(message, innerException)
{
ConnectionType = connectionType;
}
}
}
3 changes: 2 additions & 1 deletion src/Gallifrey.Jira/Gallifrey.Jira.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="ConnectionError.cs" />
<Compile Include="Enum\WorkLogStrategy.cs" />
<Compile Include="IJiraClient.cs" />
<Compile Include="JiraClientFactory.cs" />
<Compile Include="JiraRestClient.cs" />
<Compile Include="JiraClient.cs" />
<Compile Include="Model\Error.cs" />
<Compile Include="Model\Fields.cs" />
<Compile Include="Model\Filter.cs" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,39 @@

namespace Gallifrey.Jira
{
public class JiraRestClient : IJiraClient
public class JiraClient : IJiraClient
{
private readonly ISimpleRestClient jiraClient;
private readonly ISimpleRestClient tempoClient;
private readonly User myUser;

public JiraRestClient(string baseUrl, string username, string password, bool useTempo, string tempoToken)
public JiraClient(string baseUrl, string username, string password, bool useTempo, string tempoToken)
{
var url = baseUrl + (baseUrl.EndsWith("/") ? "" : "/") + "rest/api/2";
jiraClient = SimpleRestClient.WithBasicAuthentication(url, username, password, GetErrorMessages);

myUser = GetCurrentUser();
try
{
myUser = GetCurrentUser();
}
catch (Exception e)
{
throw new ConnectionError(ConnectionError.Type.Jira, "Error connecting to jira", e);
}

if (useTempo)
{
tempoClient = SimpleRestClient.WithBearerAuthentication("https://api.tempo.io/core/3", tempoToken, null);

var queryDate = DateTime.UtcNow;
tempoClient.Get<TempoWorkLogSearch>(HttpStatusCode.OK, $"worklogs/user/{myUser.accountId}?from={queryDate:yyyy-MM-dd}&to={queryDate:yyyy-MM-dd}");
try
{
var queryDate = DateTime.UtcNow;
tempoClient.Get<TempoWorkLogSearch>(HttpStatusCode.OK, $"worklogs/user/{myUser.accountId}?from={queryDate:yyyy-MM-dd}&to={queryDate:yyyy-MM-dd}");
}
catch (Exception e)
{
throw new ConnectionError(ConnectionError.Type.Tempo, "Error connecting to tempo", e);
}
}
else
{
Expand Down
6 changes: 5 additions & 1 deletion src/Gallifrey.Jira/JiraClientFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,11 @@ public static IJiraClient BuildJiraClient(string jiraUrl, string username, strin

try
{
return new JiraRestClient(jiraUrl, username, password, useTempo, tempoToken);
return new JiraClient(jiraUrl, username, password, useTempo, tempoToken);
}
catch (ConnectionError)
{
throw;
}
catch (System.Exception e)
{
Expand Down
7 changes: 7 additions & 0 deletions src/Gallifrey.UI.Modern/ChangeLog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -695,6 +695,13 @@
<Other>Branding Update</Other>
</Others>
</Version>
<Version Number="0.0.0.0" Name="Pre-Release">
<Features />
<Bugs>
<Bug>Fix messaging on Tempo login failure</Bug>
</Bugs>
<Others />
</Version>
<!--
Template for VNext if not present above
<Version Number="0.0.0.0" Name="Pre-Release">
Expand Down
6 changes: 3 additions & 3 deletions src/Gallifrey.UI.Modern/Flyouts/Settings.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -205,16 +205,16 @@
<TextBox Grid.Row="1" Grid.Column="1" Margin="5" VerticalAlignment="Center" Text="{Binding JiraUsername, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

<TextBlock Grid.Row="2" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Right" ToolTip="Your Jira Password">Jira Password/API Token</TextBlock>
<PasswordBox Grid.Row="2" Grid.Column="1" Margin="5" VerticalAlignment="Center" helpers:PasswordBoxHelper.BindPassword="true" helpers:PasswordBoxHelper.BoundPassword="{Binding JiraPassword, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
<PasswordBox Grid.Row="2" Grid.Column="1" Margin="5" VerticalAlignment="Center" Style="{StaticResource MahApps.Styles.PasswordBox.Button.Revealed}" helpers:PasswordBoxHelper.BindPassword="true" helpers:PasswordBoxHelper.BoundPassword="{Binding JiraPassword, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

<TextBlock Grid.Row="3" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Right" ToolTip="Use Tempo If The Jira Instance Has It">Use Tempo</TextBlock>
<controls:ToggleSwitch OnContent="" OffContent="" Grid.Row="3" Grid.Column="1" Margin="5,0" HorizontalAlignment="Left" VerticalAlignment="Center" IsOn="{Binding UseTempo, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

<TextBlock Grid.Row="4" Grid.Column="0" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Right" ToolTip="Your Tempo API Token Found Under 'API Integration'" Visibility="{Binding UseTempo, Converter={StaticResource BoolToVis}}">Tempo API Token</TextBlock>
<TextBox Grid.Row="4" Grid.Column="1" Margin="5" VerticalAlignment="Center" Text="{Binding TempoToken, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding UseTempo, Converter={StaticResource BoolToVis}}" />
<PasswordBox Grid.Row="4" Grid.Column="1" Margin="5" VerticalAlignment="Center" Style="{StaticResource MahApps.Styles.PasswordBox.Button.Revealed}" helpers:PasswordBoxHelper.BindPassword="true" helpers:PasswordBoxHelper.BoundPassword="{Binding TempoToken, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Visibility="{Binding UseTempo, Converter={StaticResource BoolToVis}}" />

<TextBlock Grid.Row="5" Grid.Column="0" Grid.ColumnSpan="2" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" TextWrapping="Wrap">NOTE: On Jira Cloud Instances You Should Generate An API Key From Your Atlassian ID Profile (Under Security Settings) And Use This As Your Password.</TextBlock>
<TextBlock Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" TextWrapping="Wrap" Visibility="{Binding UseTempo, Converter={StaticResource BoolToVis}}">The Tempo API Token Can Be Found In Your Tempo Settings Under API Integration. This Page States Its For Temporary Access, But This Token Does NOT Expire</TextBlock>
<TextBlock Grid.Row="6" Grid.Column="0" Grid.ColumnSpan="2" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" TextWrapping="Wrap" Visibility="{Binding UseTempo, Converter={StaticResource BoolToVis}}">The Tempo API Token Can Be Found In Your Tempo Settings Under API Integration. Tokens Can Have A 5000 Day Expiration. Only Worklog And Approval Scope Required, But Full Access Also Works.</TextBlock>
</Grid>
</TabItem>
</controls:MetroAnimatedSingleRowTabControl>
Expand Down
14 changes: 13 additions & 1 deletion src/Gallifrey.UI.Modern/Flyouts/Settings.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ private async void SaveSettings(object sender, RoutedEventArgs e)
{
successfulSave = false;
}
catch (TempoConnectionException)
{
successfulSave = false;
}

if (successfulSave)
{
Expand All @@ -53,7 +57,15 @@ private async void SaveSettings(object sender, RoutedEventArgs e)
}
else
{
await modelHelpers.ShowMessageAsync("Invalid Jira Configuration", "You Cannot Save With Invalid Jira Configuration.\nTo Save You Have To Have A Valid Connection To Jira");
if (DataModel.UseTempo)
{
await modelHelpers.ShowMessageAsync("Invalid Jira Or Tempo Configuration", "You Cannot Save With Invalid Jira Or Tempo Configuration.\nTo Save You Have To Have A Valid Connection To Jira And Tempo");
}
else
{
await modelHelpers.ShowMessageAsync("Invalid Jira Configuration", "You Cannot Save With Invalid Jira Configuration.\nTo Save You Have To Have A Valid Connection To Jira");
}

Focus();
}
}
Expand Down
Loading

0 comments on commit d154de6

Please sign in to comment.