-
Notifications
You must be signed in to change notification settings - Fork 76
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into subform-table-manually-editing-column-name
- Loading branch information
Showing
16 changed files
with
315 additions
and
29 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,23 @@ | ||
using Altinn.Studio.Designer.Helpers; | ||
|
||
namespace Altinn.Studio.Designer.Models; | ||
|
||
public class AltinnOrgContext | ||
{ | ||
public string Org { get; } | ||
public string DeveloperName { get; } | ||
|
||
private AltinnOrgContext(string org, string developerName) | ||
{ | ||
Guard.AssertValidateOrganization(org); | ||
Org = org; | ||
|
||
Guard.AssertArgumentNotNullOrWhiteSpace(developerName, nameof(developerName)); | ||
DeveloperName = developerName; | ||
} | ||
|
||
public static AltinnOrgContext FromOrg(string org, string developerName) | ||
{ | ||
return new AltinnOrgContext(org, developerName); | ||
} | ||
} |
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,6 @@ | ||
namespace Altinn.Studio.Designer.Models.Dto; | ||
|
||
public class UserOrgPermission | ||
{ | ||
public bool CanCreateOrgRepo { get; set; } | ||
} |
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
42 changes: 42 additions & 0 deletions
42
backend/src/Designer/Services/Implementation/UserService.cs
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,42 @@ | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Altinn.Studio.Designer.Models; | ||
using Altinn.Studio.Designer.Models.Dto; | ||
using Altinn.Studio.Designer.RepositoryClient.Model; | ||
using Altinn.Studio.Designer.Services.Interfaces; | ||
|
||
namespace Altinn.Studio.Designer.Services.Implementation; | ||
|
||
public class UserService : IUserService | ||
{ | ||
private readonly IGitea _giteaApi; | ||
|
||
public UserService(IGitea giteaApi) | ||
{ | ||
_giteaApi = giteaApi; | ||
} | ||
|
||
public async Task<UserOrgPermission> GetUserOrgPermission(AltinnOrgContext altinnOrgContext) | ||
{ | ||
bool canCreateOrgRepo = await HasPermissionToCreateOrgRepo(altinnOrgContext); | ||
return new UserOrgPermission() { CanCreateOrgRepo = canCreateOrgRepo }; | ||
} | ||
|
||
private bool IsUserSelfOrg(string developerName, string org) | ||
{ | ||
return developerName == org; | ||
} | ||
|
||
private async Task<bool> HasPermissionToCreateOrgRepo(AltinnOrgContext altinnOrgContext) | ||
{ | ||
List<Team> teams = await _giteaApi.GetTeams(); | ||
return IsUserSelfOrg(altinnOrgContext.DeveloperName, altinnOrgContext.Org) || | ||
teams.Any(team => CheckPermissionToCreateOrgRepo(team, altinnOrgContext.Org)); | ||
} | ||
|
||
private static bool CheckPermissionToCreateOrgRepo(Team team, string org) | ||
{ | ||
return team.CanCreateOrgRepo && team.Organization.Username == org; | ||
} | ||
} |
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,10 @@ | ||
using System.Threading.Tasks; | ||
using Altinn.Studio.Designer.Models; | ||
using Altinn.Studio.Designer.Models.Dto; | ||
|
||
namespace Altinn.Studio.Designer.Services.Interfaces; | ||
|
||
public interface IUserService | ||
{ | ||
public Task<UserOrgPermission> GetUserOrgPermission(AltinnOrgContext altinnOrgContext); | ||
} |
24 changes: 24 additions & 0 deletions
24
...end/src/Designer/TypedHttpClients/DelegatingHandlers/AzureDevOpsTokenDelegatingHandler.cs
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,24 @@ | ||
using System.Net; | ||
using System.Net.Http; | ||
using System.Threading; | ||
using System.Threading.Tasks; | ||
|
||
namespace Altinn.Studio.Designer.TypedHttpClients.DelegatingHandlers; | ||
|
||
public class AzureDevOpsTokenDelegatingHandler : DelegatingHandler | ||
{ | ||
protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken) | ||
{ | ||
HttpResponseMessage response = await base.SendAsync(request, cancellationToken); | ||
|
||
if (response.StatusCode == HttpStatusCode.Unauthorized) | ||
{ | ||
return new HttpResponseMessage(HttpStatusCode.InternalServerError) | ||
{ | ||
Content = new StringContent("Failed to interact with Azure DevOps. Contact system support.") | ||
}; | ||
} | ||
|
||
return response; | ||
} | ||
} |
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
Oops, something went wrong.