Skip to content

Commit

Permalink
customize user image url template per theme
Browse files Browse the repository at this point in the history
  • Loading branch information
hoseinzadehashraf committed Feb 12, 2024
1 parent 6c8316f commit 645580c
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Controllers/Modules/Components/UserProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public async Task<IViewComponentResult> InvokeAsync(vm.UserProfile info)
info = new vm.UserProfile()
{
Email = email,
UserImage = user?.ImageUrl,
UserImage = await _themeProvider.GetUserImage(user),
PrimaryDISCColour = user?.PrimaryDISCColour.Or("transparent"),
SecondaryDISCColour = user?.SecondaryDISCColour.Or("transparent"),
ProfileUrl = sidebarProfileUrl,
Expand Down
2 changes: 2 additions & 0 deletions Domain/Theme/Contracts/IThemeProvider.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using PeopleService;

namespace Olive.Microservices.Hub.Domain.Theme.Contracts;

Expand All @@ -10,6 +11,7 @@ public interface IThemeProvider
Task<string> GetPrimaryColor();
Task<string> GetHomePageUrl();
Task<string> GetSidebarProfileUrl(string[] userRoles, Dictionary<string, string> parameters);
Task<string> GetUserImage(UserInfo user);
Task<string?> GetLoginUrl();
Task<string> ExtraStylesTag();
string AppResourceVersion { get; }
Expand Down
10 changes: 10 additions & 0 deletions Domain/Theme/ThemeProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Hosting;
using PeopleService;

namespace Olive.Microservices.Hub.Domain.Theme
{
Expand Down Expand Up @@ -76,6 +77,15 @@ public async Task<string> GetPrimaryColor()
return theme.PrimaryColor;
}

public async Task<string?> GetUserImage(UserInfo? user)
{
if (user is null) return null;
var theme = await GetCurrentTheme();
return theme.UserImageUrlTemplate.HasValue()
? theme.UserImageUrlTemplate?.Replace("%USER_ID%", user.ID.ToString())
: user.ImageUrl;
}

public async Task<string?> GetLoginUrl()
{
if (!_initialized) await GetCurrentTheme();
Expand Down
1 change: 1 addition & 0 deletions Domain/Theme/Types/Theme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public class Theme
public string? LoginTitle { get; set; }
public string? Copyright { get; set; }
public bool HideEveryThingMenuItem { get; set; }
public string? UserImageUrlTemplate { get; set; }


public override string ToString()
Expand Down
2 changes: 1 addition & 1 deletion Olive.Microservices.Hub.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<Authors>Geeks Ltd</Authors>
<RepositoryUrl>https://github.com/Geeksltd/Olive.Microservices.Hub/tree/master/Olive.Microservices.Hub</RepositoryUrl>
<PackageIcon>icon.png</PackageIcon>
<Version>1.5.39</Version>
<Version>1.5.40</Version>
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
<GenerateTargetFrameworkAttribute>false</GenerateTargetFrameworkAttribute>
<Nullable>warnings</Nullable>
Expand Down

0 comments on commit 645580c

Please sign in to comment.