Add real name col / citizen name prop (#12)

Still need to work on allowing the column to be edited
This commit is contained in:
Daniel J. Summers 2021-02-06 21:43:16 -05:00
parent 21ba35408e
commit 1b2540e5d2
10 changed files with 31 additions and 19 deletions

View File

@ -11,6 +11,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "JobsJobsJobs.Shared", "Jobs
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{50B51580-9F09-41E2-BC78-DAD38C37B583}"
ProjectSection(SolutionItems) = preProject
database\12-add-real-name.sql = database\12-add-real-name.sql
JobsJobsJobs\Directory.Build.props = JobsJobsJobs\Directory.Build.props
database\tables.sql = database\tables.sql
EndProjectSection

View File

@ -3,8 +3,8 @@
@inject AppState state
<Loading OnLoad=@RetrieveProfile>
<PageTitle Title=@($"Employment Profile for {Citizen.DisplayName}") />
<h2><a href="@Citizen.ProfileUrl" target="_blank">@Citizen.DisplayName</a></h2>
<PageTitle Title=@($"Employment Profile for {Citizen.CitizenName}") />
<h2><a href="@Citizen.ProfileUrl" target="_blank">@Citizen.CitizenName</a></h2>
<h4>@Profile.Continent!.Name, @Profile.Region</h4>
<p>@WorkTypes</p>

View File

@ -5,7 +5,7 @@
<PageTitle Title="Success Story" />
<Loading OnLoad=@RetrieveStory>
<h3>@Citizen.DisplayName&rsquo;s Success Story</h3>
<h3>@Citizen.CitizenName&rsquo;s Success Story</h3>
<h4><FullDateTime TheDate=@Story.RecordedOn /></h4>
@if (Story.FromHere)
{

View File

@ -65,7 +65,8 @@ namespace JobsJobsJobs.Server.Areas.Api.Controllers
var citizen = await _db.FindCitizenByNAUser(account.Username);
if (citizen == null)
{
citizen = new Citizen(await CitizenId.Create(), account.Username, account.DisplayName, account.Url,
citizen = new Citizen(await CitizenId.Create(), account.Username,
string.IsNullOrWhiteSpace(account.DisplayName) ? null : account.DisplayName, null, account.Url,
now, now);
await _db.AddCitizen(citizen);
}
@ -73,7 +74,7 @@ namespace JobsJobsJobs.Server.Areas.Api.Controllers
{
citizen = citizen with
{
DisplayName = account.DisplayName,
DisplayName = string.IsNullOrWhiteSpace(account.DisplayName) ? null : account.DisplayName,
LastSeenOn = now
};
_db.UpdateCitizen(citizen);
@ -83,7 +84,7 @@ namespace JobsJobsJobs.Server.Areas.Api.Controllers
// Step 3 - Generate JWT
var jwt = Auth.CreateJwt(citizen, _config);
return new JsonResult(new LogOnSuccess(jwt, citizen.Id.ToString(), citizen.DisplayName));
return new JsonResult(new LogOnSuccess(jwt, citizen.Id.ToString(), citizen.CitizenName));
}
[Authorize]

View File

@ -80,13 +80,6 @@ namespace JobsJobsJobs.Server
$"Profiles must be from noagendasocial.com; yours is {profileResponse.AccountName}");
}
// If the user hasn't filled in a display name, use the username as the display name.
// (this is what Mastodon does)
if (string.IsNullOrWhiteSpace(profileResponse.DisplayName))
{
profileResponse.DisplayName = profileResponse.Username;
}
return Result<MastodonAccount>.AsOk(profileResponse);
}
@ -104,7 +97,7 @@ namespace JobsJobsJobs.Server
Subject = new ClaimsIdentity(new[]
{
new Claim(ClaimTypes.NameIdentifier, citizen.Id.ToString()),
new Claim(ClaimTypes.Name, citizen.DisplayName),
new Claim(ClaimTypes.Name, citizen.CitizenName),
}),
Expires = DateTime.UtcNow.AddHours(2),
Issuer = "https://noagendacareers.com",

View File

@ -49,11 +49,13 @@ namespace JobsJobsJobs.Server.Data
m.Property(e => e.Id).HasColumnName("id").IsRequired().HasMaxLength(12)
.HasConversion(Converters.CitizenIdConverter);
m.Property(e => e.NaUser).HasColumnName("na_user").IsRequired().HasMaxLength(50);
m.Property(e => e.DisplayName).HasColumnName("display_name").IsRequired().HasMaxLength(255);
m.Property(e => e.DisplayName).HasColumnName("display_name").HasMaxLength(255);
m.Property(e => e.ProfileUrl).HasColumnName("profile_url").IsRequired().HasMaxLength(1_024);
m.Property(e => e.JoinedOn).HasColumnName("joined_on").IsRequired();
m.Property(e => e.LastSeenOn).HasColumnName("last_seen_on").IsRequired();
m.Property(e => e.RealName).HasColumnName("real_name").HasMaxLength(255);
m.HasIndex(e => e.NaUser).IsUnique();
m.Ignore(e => e.CitizenName);
});
modelBuilder.Entity<Continent>(m =>

View File

@ -156,7 +156,7 @@ namespace JobsJobsJobs.Server.Data
query = query.Where(it => citizenIds.Contains(it.Citizen.Id));
}
return await query.Select(x => new ProfileSearchResult(x.Citizen.Id, x.Citizen.DisplayName,
return await query.Select(x => new ProfileSearchResult(x.Citizen.Id, x.Citizen.CitizenName,
x.Profile.SeekingEmployment, x.Profile.RemoteWork, x.Profile.FullTime, x.Profile.LastUpdatedOn))
.ToListAsync().ConfigureAwait(false);
}

View File

@ -28,7 +28,7 @@ namespace JobsJobsJobs.Server.Data
await db.Successes
.Join(db.Citizens, s => s.CitizenId, c => c.Id, (s, c) => new { Success = s, Citizen = c })
.OrderByDescending(it => it.Success.RecordedOn)
.Select(it => new StoryEntry(it.Success.Id, it.Citizen.Id, it.Citizen.DisplayName,
.Select(it => new StoryEntry(it.Success.Id, it.Citizen.Id, it.Citizen.CitizenName,
it.Success.RecordedOn, it.Success.FromHere, it.Success.Story != null))
.ToListAsync().ConfigureAwait(false);
}

View File

@ -8,8 +8,15 @@ namespace JobsJobsJobs.Shared
public record Citizen(
CitizenId Id,
string NaUser,
string DisplayName,
string? DisplayName,
string? RealName,
string ProfileUrl,
Instant JoinedOn,
Instant LastSeenOn);
Instant LastSeenOn)
{
/// <summary>
/// The user's name by which they should be known
/// </summary>
public string CitizenName => RealName ?? DisplayName ?? NaUser;
}
}

View File

@ -0,0 +1,8 @@
ALTER TABLE jjj.citizen ALTER COLUMN display_name DROP NOT NULL;
ALTER TABLE jjj.citizen ADD COLUMN real_name VARCHAR(255);
COMMENT ON COLUMN jjj.citizen.real_name
IS 'The real name of the user';
-- This can be run as often as needed
UPDATE jjj.citizen SET display_name = NULL WHERE display_name = na_user;