-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
User typeahead enabled for non-admin project managers (#1237)
Add a new usersICanSee GQL query, which looks for: * All users in one of my orgs * All users in one of the projects I manage * All users in one of the non-confidential projects I'm a member of Note that projects with `isConfidential = null` are treated as public (non-confidential) by this query. The "Add Project Member" typeahead is now updated to use that query, which allows project managers who aren't site admins to use it to find users whose email address they don't know. E.g. if Test Manager has Test Editor as part of project A, and he also manages project B, then when he clicks on "Add Members" in project B, he can type Test Editor's name and select him to add, without knowing his email address. --------- Co-authored-by: Tim Haasdyk <[email protected]>
- Loading branch information
Showing
13 changed files
with
468 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
using System.Text.Json.Nodes; | ||
using Shouldly; | ||
Check failure on line 2 in backend/Testing/ApiTests/UsersICanSeeQueryTests.cs GitHub Actions / Build API / publish-api
|
||
using Testing.Services; | ||
|
||
namespace Testing.ApiTests; | ||
|
||
[Trait("Category", "Integration")] | ||
public class UsersICanSeeQueryTests : ApiTestBase | ||
{ | ||
private async Task<JsonObject> QueryUsersICanSee(bool expectGqlError = false) | ||
{ | ||
var json = await ExecuteGql( | ||
$$""" | ||
query { | ||
usersICanSee(take: 10) { | ||
totalCount | ||
items { | ||
id | ||
name | ||
} | ||
} | ||
} | ||
""", | ||
expectGqlError, expectSuccessCode: false); | ||
return json; | ||
} | ||
|
||
private async Task AddUserToProject(Guid projectId, string username) | ||
{ | ||
await ExecuteGql( | ||
$$""" | ||
mutation { | ||
addProjectMember(input: { | ||
projectId: "{{projectId}}", | ||
usernameOrEmail: "{{username}}", | ||
role: EDITOR, | ||
canInvite: false | ||
}) { | ||
project { | ||
id | ||
} | ||
errors { | ||
__typename | ||
... on Error { | ||
message | ||
} | ||
} | ||
} | ||
} | ||
"""); | ||
} | ||
|
||
private JsonArray GetUsers(JsonObject json) | ||
{ | ||
var users = json["data"]!["usersICanSee"]!["items"]!.AsArray(); | ||
users.ShouldNotBeNull(); | ||
return users; | ||
} | ||
|
||
private void MustHaveUser(JsonArray users, string userName) | ||
{ | ||
users.ShouldNotBeNull().ShouldNotBeEmpty(); | ||
users.ShouldContain(node => node!["name"]!.GetValue<string>() == userName, | ||
"user list " + users.ToJsonString()); | ||
} | ||
|
||
private void MustNotHaveUser(JsonArray users, string userName) | ||
{ | ||
users.ShouldNotBeNull().ShouldNotBeEmpty(); | ||
users.ShouldNotContain(node => node!["name"]!.GetValue<string>() == userName, | ||
"user list " + users.ToJsonString()); | ||
} | ||
|
||
[Fact] | ||
public async Task ManagerCanSeeProjectMembersOfAllProjects() | ||
{ | ||
await LoginAs("manager"); | ||
await using var project = await this.RegisterProjectInLexBox(Utils.GetNewProjectConfig(isConfidential: true)); | ||
//refresh jwt | ||
await LoginAs("manager"); | ||
await AddUserToProject(project.Id, "[email protected]"); | ||
var json = GetUsers(await QueryUsersICanSee()); | ||
MustHaveUser(json, "Qa Admin"); | ||
} | ||
|
||
[Fact] | ||
public async Task MemberCanSeeNotProjectMembersOfConfidentialProjects() | ||
{ | ||
await LoginAs("manager"); | ||
await using var project = await this.RegisterProjectInLexBox(Utils.GetNewProjectConfig(isConfidential: true)); | ||
//refresh jwt | ||
await LoginAs("manager"); | ||
await AddUserToProject(project.Id, "[email protected]"); | ||
await LoginAs("editor"); | ||
var json = GetUsers(await QueryUsersICanSee()); | ||
MustNotHaveUser(json, "Qa Admin"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
using LexCore.Entities; | ||
using LexData; | ||
using Testing.Services; | ||
|
||
namespace Testing.Fixtures; | ||
|
||
public class TempProjectWithoutRepo(LexBoxDbContext dbContext, Project project) : IAsyncDisposable | ||
{ | ||
public Project Project => project; | ||
public static async Task<TempProjectWithoutRepo> Create(LexBoxDbContext dbContext, bool isConfidential = false, Guid? managerId = null) | ||
{ | ||
var config = Utils.GetNewProjectConfig(isConfidential: isConfidential); | ||
var project = new Project | ||
{ | ||
Name = config.Name, | ||
Code = config.Code, | ||
IsConfidential = config.IsConfidential, | ||
LastCommit = null, | ||
Organizations = [], | ||
Users = [], | ||
RetentionPolicy = RetentionPolicy.Test, | ||
Type = ProjectType.FLEx, | ||
Id = config.Id, | ||
}; | ||
if (managerId is Guid id) | ||
{ | ||
project.Users.Add(new ProjectUsers { ProjectId = project.Id, UserId = id, Role = ProjectRole.Manager }); | ||
} | ||
dbContext.Add(project); | ||
await dbContext.SaveChangesAsync(); | ||
return new TempProjectWithoutRepo(dbContext, project); | ||
} | ||
|
||
public async ValueTask DisposeAsync() | ||
{ | ||
dbContext.Remove(project); | ||
await dbContext.SaveChangesAsync(); | ||
} | ||
} |
Oops, something went wrong.