Skip to content

Commit

Permalink
Remove ShareEnabled from C#
Browse files Browse the repository at this point in the history
  • Loading branch information
pmachapman committed Nov 18, 2024
1 parent 48a6572 commit f3c3da0
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 99 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ public async Task<IRpcMethodResult> UpdateSettings(string projectId, SFProjectSe
{ "AdditionalTrainingSourceEnabled", settings?.AdditionalTrainingSourceEnabled?.ToString() },
{ "AdditionalTrainingSourceParatextId", settings?.AdditionalTrainingSourceParatextId },
{ "CheckingEnabled", settings?.CheckingEnabled?.ToString() },
{ "CheckingShareEnabled", settings?.CheckingShareEnabled?.ToString() },
{ "TranslateShareEnabled", settings?.TranslateShareEnabled?.ToString() },
{ "TranslationSuggestionsEnabled", settings?.TranslationSuggestionsEnabled?.ToString() },
{ "UsersSeeEachOthersResponses", settings?.UsersSeeEachOthersResponses?.ToString() },
{ "HideCommunityCheckingText", settings?.HideCommunityCheckingText?.ToString() },
Expand Down
1 change: 0 additions & 1 deletion src/SIL.XForge.Scripture/Models/CheckingConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public class CheckingConfig
{
public bool CheckingEnabled { get; set; }
public bool UsersSeeEachOthersResponses { get; set; } = true;
public bool ShareEnabled { get; set; } = false;
public string AnswerExportMethod { get; set; } = CheckingAnswerExport.All;
public int? NoteTagId { get; set; }

Expand Down
6 changes: 6 additions & 0 deletions src/SIL.XForge.Scripture/Models/SFProjectSettings.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System;

namespace SIL.XForge.Scripture.Models;

/// <summary>
Expand All @@ -10,6 +12,8 @@ public class SFProjectSettings
public bool? TranslationSuggestionsEnabled { get; set; }
public string? SourceParatextId { get; set; }
public bool? BiblicalTermsEnabled { get; set; }

[Obsolete("For backwards compatibility with older frontend clients. Deprecated November 2024.")]
public bool? TranslateShareEnabled { get; set; }

// pre-translation settings
Expand All @@ -24,6 +28,8 @@ public class SFProjectSettings
// checking settings
public bool? CheckingEnabled { get; set; }
public bool? UsersSeeEachOthersResponses { get; set; }

[Obsolete("For backwards compatibility with older frontend clients. Deprecated November 2024.")]
public bool? CheckingShareEnabled { get; set; }
public string? CheckingAnswerExport { get; set; }
public bool? HideCommunityCheckingText { get; set; }
Expand Down
1 change: 0 additions & 1 deletion src/SIL.XForge.Scripture/Models/TranslateConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ public class TranslateConfig
{
public bool TranslationSuggestionsEnabled { get; set; }
public TranslateSource? Source { get; set; }
public bool ShareEnabled { get; set; }
public int? DefaultNoteTagId { get; set; }
public bool PreTranslate { get; set; }
public DraftConfig DraftConfig { get; set; } = new DraftConfig();
Expand Down
91 changes: 45 additions & 46 deletions src/SIL.XForge.Scripture/Services/SFProjectService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,6 @@ await projectDoc.SubmitJson0OpAsync(op =>
);
UpdateSetting(op, p => p.BiblicalTermsConfig.BiblicalTermsEnabled, settings.BiblicalTermsEnabled);
UpdateSetting(op, p => p.TranslateConfig.Source, source, unsetSourceProject);
UpdateSetting(op, p => p.TranslateConfig.ShareEnabled, settings.TranslateShareEnabled);
UpdateSetting(
op,
p => p.TranslateConfig.DraftConfig.AlternateSourceEnabled,
Expand Down Expand Up @@ -466,7 +465,6 @@ await projectDoc.SubmitJson0OpAsync(op =>
UpdateSetting(op, p => p.CheckingConfig.CheckingEnabled, settings.CheckingEnabled);
UpdateSetting(op, p => p.CheckingConfig.UsersSeeEachOthersResponses, settings.UsersSeeEachOthersResponses);
UpdateSetting(op, p => p.CheckingConfig.ShareEnabled, settings.CheckingShareEnabled);
UpdateSetting(op, p => p.CheckingConfig.AnswerExportMethod, settings.CheckingAnswerExport);
UpdateSetting(op, p => p.CheckingConfig.HideCommunityCheckingText, settings.HideCommunityCheckingText);
});
Expand Down Expand Up @@ -632,19 +630,8 @@ await RealtimeService
}
SiteOptions siteOptions = SiteOptions.Value;

bool isAdmin = IsProjectAdmin(project, curUserId);
string[] availableRoles = new Dictionary<string, bool>
{
{
SFProjectRole.CommunityChecker,
project.CheckingConfig.CheckingEnabled && (isAdmin || project.CheckingConfig.ShareEnabled)
},
{ SFProjectRole.Viewer, project.TranslateConfig.ShareEnabled || isAdmin },
{ SFProjectRole.Commenter, project.TranslateConfig.ShareEnabled || isAdmin }
}
.Where(entry => entry.Value)
.Select(entry => entry.Key)
.ToArray();
bool isProjectAdmin = IsProjectAdmin(project, curUserId);
string[] availableRoles = GetAvailableRoles(project, isProjectAdmin);

if (!availableRoles.Contains(role))
throw new ForbiddenException();
Expand All @@ -670,7 +657,7 @@ await ProjectSecrets.UpdateAsync(
ExpirationTime = expTime,
ProjectRole = role,
ShareLinkType = ShareLinkType.Recipient,
CreatedByAdmin = isAdmin
CreatedByAdmin = isProjectAdmin
}
)
);
Expand Down Expand Up @@ -723,20 +710,7 @@ int daysBeforeExpiration
throw new ForbiddenException();

bool isProjectAdmin = IsProjectAdmin(project, curUserId);

string[] availableRoles = new Dictionary<string, bool>
{
{
SFProjectRole.CommunityChecker,
project.CheckingConfig.CheckingEnabled && (isProjectAdmin || project.CheckingConfig.ShareEnabled)
},
{ SFProjectRole.Viewer, isProjectAdmin || project.TranslateConfig.ShareEnabled },
{ SFProjectRole.Commenter, isProjectAdmin || project.TranslateConfig.ShareEnabled }
}
.Where(entry => entry.Value)
.Select(entry => entry.Key)
.ToArray();

string[] availableRoles = GetAvailableRoles(project, isProjectAdmin);
if (!availableRoles.Contains(role))
throw new ForbiddenException();

Expand All @@ -754,7 +728,7 @@ await ProjectSecrets.UpdateAsync(
ProjectRole = role,
ShareLinkType = shareLinkType,
ExpirationTime = DateTime.UtcNow.AddDays(daysBeforeExpiration),
CreatedByAdmin = isProjectAdmin
CreatedByAdmin = isProjectAdmin,
}
)
);
Expand Down Expand Up @@ -816,12 +790,12 @@ await ProjectSecrets.UpdateAsync(
}

/// <summary>Is there already a pending invitation to the project for the specified email address?</summary>
public async Task<bool> IsAlreadyInvitedAsync(string curUserId, string projectId, string email)
public async Task<bool> IsAlreadyInvitedAsync(string curUserId, string projectId, string? email)
{
SFProject project = await GetProjectAsync(projectId);
string[] availableRoles = GetAvailableRoles(project, isProjectAdmin: false);
bool sharingEnabled =
project.TranslateConfig.ShareEnabled
|| (project.CheckingConfig.CheckingEnabled && project.CheckingConfig.ShareEnabled);
availableRoles.Contains(SFProjectRole.Viewer) || availableRoles.Contains(SFProjectRole.CommunityChecker);
if (!IsProjectAdmin(project, curUserId) && !(IsOnProject(project, curUserId) && sharingEnabled))
throw new ForbiddenException();

Expand Down Expand Up @@ -849,7 +823,7 @@ public async Task<IReadOnlyList<InviteeStatus>> InvitedUsersAsync(string curUser
{
Email = sk.Email,
Role = sk.ProjectRole,
Expired = sk.ExpirationTime < now
Expired = sk.ExpirationTime < now,
})
.ToArray();
}
Expand Down Expand Up @@ -945,23 +919,14 @@ public async Task<ValidShareKey> CheckShareKeyValidity(string shareKey)
// If the link was sent by a non-admin and an admin has since disabled non-admin sharing
if (!projectSecretShareKey.CreatedByAdmin)
{
string[] availableRoles = new Dictionary<string, bool>
{
{ SFProjectRole.CommunityChecker, project.CheckingConfig.ShareEnabled },
{ SFProjectRole.Viewer, project.TranslateConfig.ShareEnabled },
{ SFProjectRole.Commenter, project.TranslateConfig.ShareEnabled },
}
.Where(entry => entry.Value)
.Select(entry => entry.Key)
.ToArray();

string[] availableRoles = GetAvailableRoles(project, isProjectAdmin: false);
if (!availableRoles.Contains(projectSecretShareKey.ProjectRole))
{
throw new DataNotFoundException("role_not_found");
}
}

return new ValidShareKey()
return new ValidShareKey
{
Project = project,
ProjectSecret = projectSecret,
Expand Down Expand Up @@ -1841,4 +1806,38 @@ await projectDoc.SubmitJson0OpAsync(op =>
}
}
}

// TODO: User similar role checking system to node backend/frontend
private static string[] GetAvailableRoles(SFProject project, bool isProjectAdmin) =>
new Dictionary<string, bool>
{
{
SFProjectRole.CommunityChecker,
project.CheckingConfig.CheckingEnabled
&& (
isProjectAdmin
|| (
project.RolePermissions.ContainsKey(SFProjectRole.CommunityChecker)
&& project.RolePermissions[SFProjectRole.CommunityChecker].Contains("user_invites.create")
)
)
},
{
SFProjectRole.Viewer,
(
project.RolePermissions.ContainsKey(SFProjectRole.Viewer)
&& project.RolePermissions[SFProjectRole.Viewer].Contains("user_invites.create")
) || isProjectAdmin
},
{
SFProjectRole.Commenter,
(
project.RolePermissions.ContainsKey(SFProjectRole.Commenter)
&& project.RolePermissions[SFProjectRole.Commenter].Contains("user_invites.create")
) || isProjectAdmin
},
}
.Where(entry => entry.Value)
.Select(entry => entry.Key)
.ToArray();
}
Original file line number Diff line number Diff line change
Expand Up @@ -775,14 +775,12 @@ public void UpdateSettings_UnknownError()
BiblicalTermsEnabled = true,
CheckingAnswerExport = string.Empty,
CheckingEnabled = true,
CheckingShareEnabled = true,
HideCommunityCheckingText = true,
SourceParatextId = string.Empty,
AlternateTrainingSourceEnabled = true,
AlternateTrainingSourceParatextId = string.Empty,
AdditionalTrainingSourceEnabled = true,
AdditionalTrainingSourceParatextId = string.Empty,
TranslateShareEnabled = true,
TranslationSuggestionsEnabled = true,
UsersSeeEachOthersResponses = true,
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2519,7 +2519,7 @@ public TestEnvironment(TestEnvironmentOptions? options = null)
Name = "project01",
ShortName = "P01",
ParatextId = Paratext01,
CheckingConfig = new CheckingConfig { ShareEnabled = false },
CheckingConfig = new CheckingConfig(),
UserRoles = [],
TranslateConfig = new TranslateConfig
{
Expand All @@ -2540,7 +2540,7 @@ public TestEnvironment(TestEnvironmentOptions? options = null)
Name = "project02",
ShortName = "P02",
ParatextId = Paratext02,
CheckingConfig = new CheckingConfig { ShareEnabled = false },
CheckingConfig = new CheckingConfig(),
UserRoles = [],
TranslateConfig = new TranslateConfig
{
Expand Down Expand Up @@ -2585,7 +2585,7 @@ public TestEnvironment(TestEnvironmentOptions? options = null)
Name = "project03",
ShortName = "P03",
ParatextId = Paratext03,
CheckingConfig = new CheckingConfig { ShareEnabled = false },
CheckingConfig = new CheckingConfig(),
UserRoles = [],
TranslateConfig = new TranslateConfig
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6259,7 +6259,7 @@ public SFProject NewSFProject() =>
WritingSystem = new WritingSystem { Tag = "qaa" },
},
},
CheckingConfig = new CheckingConfig { ShareEnabled = false },
CheckingConfig = new CheckingConfig(),
UserRoles = new Dictionary<string, string>
{
{ User01, SFProjectRole.Administrator },
Expand Down
Loading

0 comments on commit f3c3da0

Please sign in to comment.