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

Bug/hide username in schedule #2847

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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
9 changes: 8 additions & 1 deletion src/JoinRpg.Blazor.Client/UriLocatorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,14 @@ public static class UriLocatorExtensions
private class UriLocator : IUriLocator<UserLinkViewModel>, IUriLocator<CharacterGroupLinkSlimViewModel>
{
Uri IUriLocator<UserLinkViewModel>.GetUri(UserLinkViewModel target)
=> new($"/user/{target.UserId}");
{
if (target.ViewMode == ViewMode.Hide)
{
throw new InvalidOperationException("Should not have url of hidden");
}
return new($"/user/{target.UserId}");
}

Uri IUriLocator<CharacterGroupLinkSlimViewModel>.GetUri(CharacterGroupLinkSlimViewModel target)
=> throw new NotImplementedException();
// TODO implement for Blazor. Added so we will have nice exception instead of bla-bla not resolved.
Expand Down
21 changes: 7 additions & 14 deletions src/JoinRpg.Domain/Schedules/ScheduleModels.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,15 @@

namespace JoinRpg.Domain.Schedules;

public class ProgramItem
public class ProgramItem(Character character)
{
public int Id { get; internal set; }
public string Name { get; internal set; }
public MarkdownString Description { get; internal set; }
public User[] Authors { get; internal set; }
public int ProjectId { get; set; }
public int Id { get; } = character.CharacterId;
public string Name { get; } = character.CharacterName;
public MarkdownString Description { get; } = character.Description;
public User[] Authors { get; } = new[] { character.ApprovedClaim?.Player }.WhereNotNull().ToArray();
public int ProjectId { get; } = character.ProjectId;

public ProgramItem(Character character)
{
Id = character.CharacterId;
Name = character.CharacterName;
Description = character.Description;
Authors = new[] { character.ApprovedClaim?.Player }.WhereNotNull().ToArray();
ProjectId = character.ProjectId;
}
public bool ShowAuthors { get; } = !character.HidePlayerForCharacter;
}

public class ProgramItemPlaced
Expand Down
6 changes: 3 additions & 3 deletions src/JoinRpg.Portal/Controllers/GameGroupsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -217,9 +217,9 @@ private object ConvertCharacterToJson(CharacterViewModel ch)
ch.IsFirstCopy,
ch.CharacterName,
Description = ch.Description?.ToHtmlString(),
PlayerName = ch.HidePlayer ? "скрыто" : ch.PlayerLink?.DisplayName,
PlayerId = ch.HidePlayer ? null : ch.PlayerLink?.UserId, //TODO Remove
PlayerLink = (ch.HidePlayer || ch.PlayerLink is null) ? null : userLinkLocator.GetUri(ch.PlayerLink).AbsoluteUri,
PlayerName = ch.PlayerLink?.DisplayName,
PlayerId = ch.PlayerLink?.UserId,
PlayerLink = (ch.PlayerLink is null || ch.PlayerLink.ViewMode == ViewMode.Hide) ? null : userLinkLocator.GetUri(ch.PlayerLink).AbsoluteUri,
ch.ActiveClaimsCount,
ClaimLink =
ch.IsAvailable
Expand Down
2 changes: 1 addition & 1 deletion src/JoinRpg.Portal/Views/Character/Details.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

}
<dt>Игрок</dt>
<dd>@Html.DisplayFor(model => model, "IPlayerCharacter")</dd>
<dd>@Html.DisplayFor(model => model.PlayerLink)</dd>
@if (Model.ParentGroups.HasAnyGroups)
{
<dt>@Html.DisplayNameFor(model => model.ParentGroups)</dt>
Expand Down
6 changes: 2 additions & 4 deletions src/JoinRpg.Portal/Views/GameGroups/_CharacterPartial.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@
}
<div class="@hideClassName">
<strong>@Html.ActionLink(Model.CharacterName ?? Model.CharacterId.ToString(), "Details", "Character", new { Model.ProjectId, Model.CharacterId }, null) </strong>
@if (Model.PlayerLink != null)
{
@Html.DisplayFor(model => model, "IPlayerCharacter")
}

@Html.DisplayFor(model => model.PlayerLink)
else if (Model.ActiveClaimsCount > 0)
{
@Html.DisplayCount_OfX(Model.ActiveClaimsCount, "заявка", "заявки", "заявок")
Expand Down

This file was deleted.

3 changes: 3 additions & 0 deletions src/JoinRpg.Web.ProjectCommon/MasterViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
using JoinRpg.PrimitiveTypes;
using JoinRpg.WebComponents;

namespace JoinRpg.Web.ProjectCommon;

public record MasterViewModel(int MasterId, UserDisplayName DisplayName)
{
public static MasterViewModel Empty(string label)
=> new(-1, new UserDisplayName(DisplayName: label, FullName: null));

public UserLinkViewModel ToUserLinkViewModel() => new UserLinkViewModel(MasterId, DisplayName.DisplayName, ViewMode.Show);
}
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
new ResponsibleMasterRuleViewModel(
model.Group.CharacterGroupId,
model.Group.Name,
new UserLinkViewModel(model.Master.MasterId, model.Master.DisplayName.DisplayName)
model.Master.ToUserLinkViewModel()
));

try
Expand Down
12 changes: 12 additions & 0 deletions src/JoinRpg.WebComponents/UserLink.razor
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
@inject IUriLocator<UserLinkViewModel> userLinkLocator
@switch (Model.ViewMode)
{
case JoinRpg.WebComponents.ViewMode.Show:
<a class="join-user" href="@ProfileUri"><i class="glyphicon glyphicon-user"></i>@Model.DisplayName</a>
break;
case JoinRpg.WebComponents.ViewMode.ShowAsPrivate:
<a class="join-user world-object-hidden" href="@ProfileUri"><i class="glyphicon glyphicon-user"></i>@Model.DisplayName</a>
break;
case JoinRpg.WebComponents.ViewMode.Hide:
<span class="glyphicon glyphicon-user"></span><i>занято</i>
break;
}
<a class="join-user" href="@ProfileUri"><i class="glyphicon glyphicon-user"></i>@Model.DisplayName</a>

@code {
Expand Down
11 changes: 10 additions & 1 deletion src/JoinRpg.WebComponents/UserLinkViewModel.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,12 @@
namespace JoinRpg.WebComponents;

public record UserLinkViewModel(int UserId, string DisplayName);
public enum ViewMode
{
Show,
ShowAsPrivate,
Hide
}
public record UserLinkViewModel(int UserId, string DisplayName, ViewMode ViewMode)
{
public static UserLinkViewModel Hidden = new(-1, "скрыто", ViewMode.Hide);
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,16 @@ IProjectMetadataRepository projectMetadataRepository
public async Task<SchedulePageViewModel> GetSchedule()
{
(var project, var result) = await GetCompiledSchedule();
var hasMasterAccess = project.HasMasterAccess(CurrentUserAccessor);
var viewModel = new SchedulePageViewModel()
{
ProjectId = CurrentProject.ProjectId,
DisplayName = project.ProjectName,
NotScheduledProgramItems = result.NotScheduled.ToViewModel(),
NotScheduledProgramItems = result.NotScheduled.ToViewModel(hasMasterAccess),
Columns = result.Rooms.ToViewModel(),
Rows = result.TimeSlots.ToViewModel(),
ConflictedProgramItems = result.Conflicted.ToViewModel(),
Slots = result.Slots.Select2DList(x => x.ToViewModel())
ConflictedProgramItems = result.Conflicted.ToViewModel(hasMasterAccess),
Slots = result.Slots.Select2DList(x => x.ToViewModel(hasMasterAccess)),
};

MergeSlots(viewModel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
using JoinRpg.Helpers.Web;
using JoinRpg.Markdown;
using JoinRpg.Web.Models.Schedules;
using JoinRpg.Web.Models.UserProfile;
using JoinRpg.WebComponents;

namespace JoinRpg.WebPortal.Managers.Schedule;

internal static class SchedulePageViewModelBuilder
{
public static IReadOnlyList<ProgramItemViewModel> ToViewModel(this IEnumerable<ProgramItem> items)
=> items.Select(item => item.ToViewModel()).ToList();
public static IReadOnlyList<ProgramItemViewModel> ToViewModel(this IEnumerable<ProgramItem> items, bool hasMasterAccess)
=> items.Select(item => item.ToViewModel(hasMasterAccess)).ToList();

public static IReadOnlyList<TableHeaderViewModel> ToViewModel(this IEnumerable<ScheduleItemAttribute> items)
=> items.Select(item => item.ToViewModel()).ToList();

public static ProgramItemViewModel ToViewModel(this ProgramItem? item)
public static ProgramItemViewModel ToViewModel(this ProgramItem? item, bool hasMasterAccess)
{
if (item == null)
{
Expand All @@ -25,10 +27,23 @@ public static ProgramItemViewModel ToViewModel(this ProgramItem? item)
Name = item.Name,
Description = item.Description,
ProjectId = item.ProjectId,
Users = item.Authors,
Users = GetAuthors(item, hasMasterAccess),
};
}

public static UserLinkViewModel[] GetAuthors(ProgramItem item, bool hasMasterAccess)
{
if (item.Authors.Length == 0)
{
return [];
}
if (!item.ShowAuthors && !hasMasterAccess)
{
return [UserLinkViewModel.Hidden];
}
return [.. item.Authors.Select(x => UserLinks.Create(x, ViewMode.Show))];
}

public static TableHeaderViewModel ToViewModel(this ScheduleItemAttribute scheduleItem)
{
if (scheduleItem is TimeSlot slot)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using JoinRpg.PrimitiveTypes.ProjectMetadata;
using JoinRpg.Services.Interfaces;
using JoinRpg.Web.Models.Plot;
using JoinRpg.Web.Models.UserProfile;
using JoinRpg.WebComponents;

namespace JoinRpg.Web.Models.Characters;
Expand All @@ -30,15 +29,7 @@ public CharacterParentGroupsViewModel(Character character, bool hasMasterAccess)
}
}

//TODO merge everything into UserLinkViewModel and remove this interface
public interface ICharacterWithPlayerViewModel
{
UserLinkViewModel? PlayerLink { get; }
bool HidePlayer { get; }
bool HasAccess { get; }
}

public class CharacterDetailsViewModel : ICharacterWithPlayerViewModel, ICreatedUpdatedTracked
public class CharacterDetailsViewModel : ICreatedUpdatedTracked
{
[ReadOnly(true), DisplayName("Входит в группы")]
public CharacterParentGroupsViewModel ParentGroups { get; }
Expand All @@ -47,9 +38,6 @@ public class CharacterDetailsViewModel : ICharacterWithPlayerViewModel, ICreated

public PlotDisplayViewModel Plot { get; }

public bool HidePlayer { get; }
public bool HasAccess { get; }

public CustomFieldsViewModel Fields { get; }

public CharacterNavigationViewModel Navigation { get; }
Expand All @@ -62,10 +50,9 @@ public CharacterDetailsViewModel(
IUriService uriService,
ProjectInfo projectInfo)
{
PlayerLink = UserLinks.Create(character.ApprovedClaim?.Player);
HasAccess = character.HasAnyAccess(currentUserIdOrDefault);

PlayerLink = character.GetCharacterPlayerLinkViewModel(currentUserIdOrDefault);
ParentGroups = new CharacterParentGroupsViewModel(character, character.HasMasterAccess(currentUserIdOrDefault));
HidePlayer = character.HidePlayerForCharacter;
Navigation =
CharacterNavigationViewModel.FromCharacter(character, CharacterNavigationPage.Character,
currentUserIdOrDefault);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
using JoinRpg.Helpers;
using JoinRpg.Markdown;
using JoinRpg.Web.Models.CommonTypes;
using JoinRpg.Web.Models.UserProfile;

namespace JoinRpg.Web.Models.Characters;

Expand Down Expand Up @@ -129,10 +128,8 @@ private CharacterViewModel GenerateCharacter(Character arg, CharacterGroup group
Description = arg.Description.ToHtmlString(),
IsPublic = arg.IsPublic,
IsActive = arg.IsActive,
HidePlayer = arg.HidePlayerForCharacter && !arg.Project.Details.PublishPlot,
ActiveClaimsCount = arg.Claims.Count(claim => claim.ClaimStatus.IsActive()),
PlayerLink = UserLinks.Create(arg.ApprovedClaim?.Player),
HasMasterAccess = HasMasterAccess,
PlayerLink = arg.GetCharacterPlayerLinkViewModel(CurrentUserId),
HasEditRolesAccess = HasEditRolesAccess,
ProjectId = arg.ProjectId,
FirstInGroup = siblings[0] == arg,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using JoinRpg.DataModel;
using JoinRpg.Domain;
using JoinRpg.Web.Models.UserProfile;
using JoinRpg.WebComponents;


namespace JoinRpg.Web.Models.Characters;
public static class CharacterViewModeExtensions
{
public static ViewMode GetViewModeForCharacter(this Character character, int? currentUserIdOrDefault)
{
var hasAccess = character.HasAnyAccess(currentUserIdOrDefault);
return (character.HidePlayerForCharacter, hasAccess, character.Project.Details.PublishPlot)
switch
{
(false, _, _) => ViewMode.Show,
(true, false, false) => ViewMode.Hide,
(true, _, true) => ViewMode.ShowAsPrivate,
(true, true, _) => ViewMode.ShowAsPrivate,
};
}

public static UserLinkViewModel? GetCharacterPlayerLinkViewModel(this Character character, int? currentUserIdOrDefault)
{
return UserLinks.Create(character.ApprovedClaim?.Player, character.GetViewModeForCharacter(currentUserIdOrDefault));
}
}
5 changes: 0 additions & 5 deletions src/JoinRpg.WebPortal.Models/Characters/CharacterViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
namespace JoinRpg.Web.Models.Characters;

public class CharacterViewModel :
ICharacterWithPlayerViewModel,
IEquatable<CharacterViewModel>,
ILinkable
{
Expand All @@ -26,12 +25,8 @@ public class CharacterViewModel :
public bool IsActive { get; set; }

public UserLinkViewModel? PlayerLink { get; set; }
public bool HidePlayer { get; set; }
public bool HasAccess => HasMasterAccess;
public int ActiveClaimsCount { get; set; }

public bool HasMasterAccess { get; set; }

public bool FirstInGroup { get; set; }
public bool LastInGroup { get; set; }

Expand Down
8 changes: 2 additions & 6 deletions src/JoinRpg.WebPortal.Models/Claims/ClaimViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

namespace JoinRpg.Web.Models;

public class ClaimViewModel : ICharacterWithPlayerViewModel, IEntityWithCommentsViewModel
public class ClaimViewModel : IEntityWithCommentsViewModel
{
public int ClaimId { get; set; }
public int ProjectId { get; set; }
Expand Down Expand Up @@ -66,10 +66,6 @@ public class ClaimViewModel : ICharacterWithPlayerViewModel, IEntityWithComments
[ReadOnly(true)]
public IList<JoinSelectListItem> PotentialCharactersToMove { get; }

public bool HidePlayer => false;

public bool HasAccess => true;

public CustomFieldsViewModel Fields { get; }

public CharacterNavigationViewModel Navigation { get; }
Expand Down Expand Up @@ -138,7 +134,7 @@ public ClaimViewModel(User currentUser,
ExtraAccessReason.PlayerOrResponsible);
IsMyClaim = claim.PlayerUserId == currentUser.UserId;
Player = claim.Player;
PlayerLink = UserLinks.Create(claim.Player);
PlayerLink = UserLinks.Create(claim.Player, ViewMode.Show);
ProjectId = claim.ProjectId;
ProjectName = claim.Project.ProjectName;
Status = new ClaimFullStatusView(claim, AccessArgumentsFactory.Create(claim, currentUser.UserId));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using System.ComponentModel.DataAnnotations;
using JoinRpg.DataModel;
using JoinRpg.Helpers.Web;
using JoinRpg.WebComponents;

namespace JoinRpg.Web.Models.Schedules;

Expand All @@ -25,7 +25,7 @@ public class AppointmentBaseViewModel
public string DisplayName { get; set; }
public int ProjectId { get; set; }
public int CharacterId { get; set; }
public IReadOnlyCollection<User> Users { get; set; }
public required IReadOnlyCollection<UserLinkViewModel> Users { get; set; }
public JoinHtmlString Description { get; set; }
}

Expand Down
Loading
Loading