Skip to content

Commit d3a5190

Browse files
authored
Merge branch 'main' into epic-role
2 parents c05d42a + 5f7aa00 commit d3a5190

38 files changed

+1162
-216
lines changed

Refresh.Database/GameDatabaseContext.Levels.cs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public GameLevel AddLevel(ISerializedPublishLevel createInfo, TokenGame game, Ga
5252
EnforceMinMaxPlayers = createInfo.EnforceMinMaxPlayers,
5353
SameScreenGame = createInfo.SameScreenGame,
5454
BackgroundGuid = createInfo.BackgroundGuid,
55-
Publisher = publisher,
55+
PublisherUserId = publisher.UserId,
5656
GameVersion = game,
5757
PublishDate = timestamp,
5858
UpdateDate = timestamp,
@@ -63,22 +63,19 @@ public GameLevel AddLevel(ISerializedPublishLevel createInfo, TokenGame game, Ga
6363

6464
this.SaveChanges();
6565

66-
this.CreateRevisionForLevel(level, level.Publisher);
67-
this.GameLevelStatistics.Add(level.Statistics = new GameLevelStatistics
68-
{
69-
LevelId = level.LevelId,
70-
});
71-
72-
this.SaveChanges();
73-
74-
if (level.Publisher != null)
66+
this.WriteEnsuringStatistics(publisher, () =>
7567
{
76-
this.WriteEnsuringStatistics(level.Publisher, () =>
68+
this.GameLevelStatistics.Add(level.Statistics = new GameLevelStatistics
7769
{
78-
level.Publisher.Statistics!.LevelCount++;
70+
LevelId = level.LevelId,
7971
});
80-
}
8172

73+
this.CreateRevisionForLevel(level, level.Publisher);
74+
publisher.Statistics!.LevelCount++;
75+
});
76+
77+
level.Publisher = publisher;
78+
this.Entry(level.Publisher).State = EntityState.Unchanged;
8279
return level;
8380
}
8481

Refresh.Database/GameDatabaseContext.Photos.cs

Lines changed: 14 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -119,67 +119,20 @@ public GamePhoto UploadPhoto(IPhotoUpload photo, IEnumerable<IPhotoUploadSubject
119119
return newPhoto;
120120
}
121121

122-
/// <remarks>
123-
/// Migration only!!
124-
/// </remarks>
125-
public void MigratePhotoSubjects(GamePhoto photo, bool saveChanges)
122+
public GamePhotoSubject AddSubjectForPhoto(GamePhoto photo, int playerId, string displayName, GameUser? user, List<float> bounds, bool save = true)
126123
{
127-
List<GamePhotoSubject> subjects = [];
128-
129-
#pragma warning disable CS0618 // obsoletion
130-
131-
// If DisplayName is not null, there is a subject in that spot
132-
if (photo.Subject1DisplayName != null)
133-
{
134-
subjects.Add(new()
135-
{
136-
Photo = photo,
137-
PlayerId = 1,
138-
DisplayName = photo.Subject1DisplayName,
139-
User = photo.Subject1User,
140-
Bounds = photo.Subject1Bounds,
141-
});
142-
}
143-
144-
if (photo.Subject2DisplayName != null)
145-
{
146-
subjects.Add(new()
147-
{
148-
Photo = photo,
149-
PlayerId = 2,
150-
DisplayName = photo.Subject2DisplayName,
151-
User = photo.Subject2User,
152-
Bounds = photo.Subject2Bounds,
153-
});
154-
}
155-
156-
if (photo.Subject3DisplayName != null)
157-
{
158-
subjects.Add(new()
159-
{
160-
Photo = photo,
161-
PlayerId = 3,
162-
DisplayName = photo.Subject3DisplayName,
163-
User = photo.Subject3User,
164-
Bounds = photo.Subject3Bounds,
165-
});
166-
}
167-
168-
if (photo.Subject4DisplayName != null)
124+
GamePhotoSubject subject = new()
169125
{
170-
subjects.Add(new()
171-
{
172-
Photo = photo,
173-
PlayerId = 4,
174-
DisplayName = photo.Subject4DisplayName,
175-
User = photo.Subject4User,
176-
Bounds = photo.Subject4Bounds,
177-
});
178-
}
179-
#pragma warning restore CS0618
126+
Photo = photo,
127+
PlayerId = playerId,
128+
DisplayName = displayName,
129+
User = user,
130+
Bounds = bounds,
131+
};
180132

181-
this.GamePhotoSubjects.AddRange(subjects);
182-
if (saveChanges) this.SaveChanges();
133+
this.GamePhotoSubjects.Add(subject);
134+
if (save) this.SaveChanges();
135+
return subject;
183136
}
184137

185138
public void RemovePhoto(GamePhoto photo)
@@ -227,6 +180,9 @@ public IQueryable<GamePhotoSubject> GetSubjectsInPhoto(GamePhoto photo)
227180
.Where(s => s.PhotoId == photo.PhotoId)
228181
.OrderBy(s => s.PlayerId);
229182

183+
public int GetTotalSubjectsInPhoto(GamePhoto photo)
184+
=> this.GamePhotoSubjects.Count(s => s.PhotoId == photo.PhotoId);
185+
230186
public IQueryable<GameUser> GetUsersInPhoto(GamePhoto photo)
231187
=> this.GetSubjectsInPhoto(photo)
232188
.Where(s => s.User != null)

Refresh.Database/GameDatabaseContext.Pins.cs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,9 @@ private IEnumerable<PinProgressRelation> GetPinProgressesByUser(GameUser user, b
169169
public DatabaseList<PinProgressRelation> GetPinProgressesByUser(GameUser user, bool isBeta, TokenPlatform platform, int skip, int count)
170170
=> new(this.GetPinProgressesByUser(user, isBeta, platform), skip, count);
171171

172+
public IQueryable<PinProgressRelation> GetAllPinProgressesByUserAndId(GameUser user, long pinId)
173+
=> this.PinProgressRelations.Where(p => p.PublisherId == user.UserId && p.PinId == pinId);
174+
172175
public PinProgressRelation? GetUserPinProgress(long pinId, GameUser user, bool isBeta, TokenPlatform platform)
173176
=> this.PinProgressRelations.FirstOrDefault(p => p.PinId == pinId && p.PublisherId == user.UserId
174177
&& (p.IsBeta == isBeta && p.Platform == platform || p.Platform == TokenPlatform.Website));
@@ -180,20 +183,19 @@ private IEnumerable<ProfilePinRelation> GetProfilePinsByUser(GameUser user, Toke
180183

181184
public DatabaseList<ProfilePinRelation> GetProfilePinsByUser(GameUser user, TokenGame game, TokenPlatform platform, int skip, int count)
182185
=> new(this.GetProfilePinsByUser(user, game, platform), skip, count);
183-
184-
#region Migration Methods
185186

186187
public void AddPinProgress(PinProgressRelation relation, bool save)
187188
{
188189
this.PinProgressRelations.Add(relation);
189190
if (save) this.SaveChanges();
190191
}
191192

192-
public void RemoveAllPinProgressesByIdAndUser(long pinId, ObjectId userId, bool save)
193+
public void RemovePinProgress(PinProgressRelation relation, bool save)
193194
{
194-
this.PinProgressRelations.RemoveRange(p => p.PinId == pinId && p.PublisherId == userId);
195+
this.PinProgressRelations.Remove(relation);
195196
if (save) this.SaveChanges();
196197
}
197198

198-
#endregion
199+
public int GetTotalPinProgresses()
200+
=> this.PinProgressRelations.Count();
199201
}

Refresh.Database/GameDatabaseContext.Registration.cs

Lines changed: 48 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ public bool IsEmailTaken(string emailAddress)
115115
{
116116
return this.GameUsers.Any(u => u.EmailAddress == emailAddress) ||
117117
this.QueuedRegistrations.Any(r => r.EmailAddress == emailAddress) ||
118-
this.IsEmailDisallowed(emailAddress);
118+
this.IsEmailAddressDisallowed(emailAddress);
119119
}
120120

121121
public void AddRegistrationToQueue(string username, string emailAddress, string passwordBcrypt)
@@ -253,34 +253,71 @@ public bool IsUserDisallowed(string username)
253253
return this.DisallowedUsers.FirstOrDefault(u => u.Username == username) != null;
254254
}
255255

256-
public bool DisallowEmail(string email)
256+
public bool DisallowEmailAddress(string emailAddress)
257257
{
258-
if (this.IsEmailDisallowed(email))
258+
if (this.IsEmailAddressDisallowed(emailAddress))
259259
return false;
260260

261-
this.DisallowedEmails.Add(new()
261+
this.DisallowedEmailAddresses.Add(new()
262262
{
263-
Email = email,
263+
Address = emailAddress,
264264
});
265265
this.SaveChanges();
266266

267267
return true;
268268
}
269269

270-
public bool ReallowEmail(string email)
270+
public bool ReallowEmailAddress(string emailAddress)
271271
{
272-
DisallowedEmail? disallowedEmail = this.DisallowedEmails.FirstOrDefault(u => u.Email == email);
273-
if (disallowedEmail == null)
272+
DisallowedEmailAddress? DisallowedEmailAddress = this.DisallowedEmailAddresses.FirstOrDefault(u => u.Address == emailAddress);
273+
if (DisallowedEmailAddress == null)
274274
return false;
275275

276-
this.DisallowedEmails.Remove(disallowedEmail);
276+
this.DisallowedEmailAddresses.Remove(DisallowedEmailAddress);
277277
this.SaveChanges();
278278

279279
return true;
280280
}
281281

282-
public bool IsEmailDisallowed(string email)
282+
public bool IsEmailAddressDisallowed(string emailAddress)
283283
{
284-
return this.DisallowedEmails.Any(u => u.Email == email);
284+
return this.DisallowedEmailAddresses.Any(u => u.Address == emailAddress);
285+
}
286+
287+
private string GetEmailDomainFromAddress(string emailAddress)
288+
=> emailAddress.Split('@').Last();
289+
290+
public bool DisallowEmailDomain(string emailAddress)
291+
{
292+
string emailDomain = this.GetEmailDomainFromAddress(emailAddress);
293+
if (this.IsEmailDomainDisallowed(emailDomain))
294+
return false;
295+
296+
this.DisallowedEmailDomains.Add(new()
297+
{
298+
Domain = emailDomain,
299+
});
300+
this.SaveChanges();
301+
302+
return true;
303+
}
304+
305+
public bool ReallowEmailDomain(string emailAddress)
306+
{
307+
string emailDomain = this.GetEmailDomainFromAddress(emailAddress);
308+
DisallowedEmailDomain? disallowedDomain = this.DisallowedEmailDomains.FirstOrDefault(u => u.Domain == emailDomain);
309+
if (disallowedDomain == null)
310+
return false;
311+
312+
this.DisallowedEmailDomains.Remove(disallowedDomain);
313+
this.SaveChanges();
314+
315+
return true;
316+
}
317+
318+
public bool IsEmailDomainDisallowed(string emailAddress)
319+
{
320+
string emailDomain = this.GetEmailDomainFromAddress(emailAddress);
321+
return this.DisallowedEmailDomains.Any(u => u.Domain == emailDomain);
285322
}
286323
}

Refresh.Database/GameDatabaseContext.Relations.cs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -477,20 +477,6 @@ public GameReview UpdateReview(ISubmitReviewRequest updateInfo, GameReview revie
477477
this.SaveChanges();
478478
return review;
479479
}
480-
481-
public void MigrateReviewLabels(IEnumerable<GameReview> reviews)
482-
{
483-
foreach (GameReview review in reviews)
484-
{
485-
#pragma warning disable CS0618 // LabelsString is obsolete
486-
if (string.IsNullOrWhiteSpace(review.LabelsString)) continue;
487-
488-
review.Labels = LabelExtensions.FromLbpCommaList(review.LabelsString).ToList();
489-
#pragma warning restore CS0618
490-
}
491-
492-
this.SaveChanges();
493-
}
494480

495481
public void DeleteReviewsPostedByUser(GameUser user)
496482
{

Refresh.Database/GameDatabaseContext.Workers.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ public bool MarkWorkerContacted(int id)
5050
return JsonConvert.DeserializeObject(state.State, type);
5151
}
5252

53+
public IQueryable<string> GetAllJobIds(WorkerClass? workerClass)
54+
{
55+
IQueryable<PersistentJobState> states = this.JobStates;
56+
if (workerClass != null) states = states.Where(s => s.Class == workerClass);
57+
return states.Select(s => s.JobId);
58+
}
59+
5360
public void UpdateOrCreateJobState(string jobId, object state, WorkerClass workerClass)
5461
{
5562
PersistentJobState? jobState = this.JobStates.FirstOrDefault(s => s.JobId == jobId && s.Class == workerClass);
@@ -58,6 +65,7 @@ public void UpdateOrCreateJobState(string jobId, object state, WorkerClass worke
5865
jobState = new PersistentJobState
5966
{
6067
JobId = jobId,
68+
Class = workerClass,
6169
};
6270

6371
this.JobStates.Add(jobState);
@@ -66,4 +74,10 @@ public void UpdateOrCreateJobState(string jobId, object state, WorkerClass worke
6674
jobState.State = JsonConvert.SerializeObject(state, Formatting.None);
6775
this.SaveChanges();
6876
}
77+
78+
public void RemoveJobState(string jobId, bool save = true)
79+
{
80+
this.JobStates.RemoveRange(s => s.JobId == jobId);
81+
if (save) this.SaveChanges();
82+
}
6983
}

Refresh.Database/GameDatabaseContext.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ public partial class GameDatabaseContext : DbContext, IDatabaseContext
6464
internal DbSet<AssetDependencyRelation> AssetDependencyRelations { get; set; }
6565
internal DbSet<GameReview> GameReviews { get; set; }
6666
internal DbSet<DisallowedUser> DisallowedUsers { get; set; }
67-
internal DbSet<DisallowedEmail> DisallowedEmails { get; set; }
67+
internal DbSet<DisallowedEmailAddress> DisallowedEmailAddresses { get; set; }
68+
internal DbSet<DisallowedEmailDomain> DisallowedEmailDomains { get; set; }
6869
internal DbSet<RateReviewRelation> RateReviewRelations { get; set; }
6970
internal DbSet<TagLevelRelation> TagLevelRelations { get; set; }
7071
internal DbSet<GamePlaylist> GamePlaylists { get; set; }
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
using Microsoft.EntityFrameworkCore.Infrastructure;
2+
using Microsoft.EntityFrameworkCore.Migrations;
3+
4+
#nullable disable
5+
6+
namespace Refresh.Database.Migrations
7+
{
8+
/// <inheritdoc />
9+
[DbContext(typeof(GameDatabaseContext))]
10+
[Migration("20260331143640_AddAbilityToDisallowEmailDomains")]
11+
public partial class AddAbilityToDisallowEmailDomains : Migration
12+
{
13+
/// <inheritdoc />
14+
protected override void Up(MigrationBuilder migrationBuilder)
15+
{
16+
migrationBuilder.RenameTable(name: "DisallowedEmails", newName: "DisallowedEmailAddresses");
17+
migrationBuilder.DropPrimaryKey(name: "PK_DisallowedEmails", table: "DisallowedEmailAddresses");
18+
migrationBuilder.RenameColumn(name: "Email", table: "DisallowedEmailAddresses", newName: "Address");
19+
migrationBuilder.AddPrimaryKey(name: "PK_DisallowedEmailAddresses", table: "DisallowedEmailAddresses", column: "Address");
20+
21+
migrationBuilder.CreateTable(
22+
name: "DisallowedEmailDomains",
23+
columns: table => new
24+
{
25+
Domain = table.Column<string>(type: "text", nullable: false)
26+
},
27+
constraints: table =>
28+
{
29+
table.PrimaryKey("PK_DisallowedEmailDomains", x => x.Domain);
30+
});
31+
}
32+
33+
/// <inheritdoc />
34+
protected override void Down(MigrationBuilder migrationBuilder)
35+
{
36+
migrationBuilder.DropTable(
37+
name: "DisallowedEmailDomains");
38+
39+
migrationBuilder.RenameTable(name: "DisallowedEmailAddresses", newName: "DisallowedEmails");
40+
migrationBuilder.DropPrimaryKey(name: "PK_DisallowedEmailAddresses", table: "DisallowedEmails");
41+
migrationBuilder.RenameColumn(name: "Address", table: "DisallowedEmails", newName: "Email");
42+
migrationBuilder.AddPrimaryKey(name: "PK_DisallowedEmails", table: "DisallowedEmails", column: "Email");
43+
}
44+
}
45+
}

Refresh.Database/Migrations/GameDatabaseContextModelSnapshot.cs

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,14 +1510,24 @@ protected override void BuildModel(ModelBuilder modelBuilder)
15101510
b.ToTable("RequestStatistics");
15111511
});
15121512

1513-
modelBuilder.Entity("Refresh.Database.Models.Users.DisallowedEmail", b =>
1513+
modelBuilder.Entity("Refresh.Database.Models.Users.DisallowedEmailAddress", b =>
15141514
{
1515-
b.Property<string>("Email")
1515+
b.Property<string>("Address")
15161516
.HasColumnType("text");
15171517

1518-
b.HasKey("Email");
1518+
b.HasKey("Address");
15191519

1520-
b.ToTable("DisallowedEmails");
1520+
b.ToTable("DisallowedEmailAddresses");
1521+
});
1522+
1523+
modelBuilder.Entity("Refresh.Database.Models.Users.DisallowedEmailDomain", b =>
1524+
{
1525+
b.Property<string>("Domain")
1526+
.HasColumnType("text");
1527+
1528+
b.HasKey("Domain");
1529+
1530+
b.ToTable("DisallowedEmailDomains");
15211531
});
15221532

15231533
modelBuilder.Entity("Refresh.Database.Models.Users.DisallowedUser", b =>

0 commit comments

Comments
 (0)