Skip to content

Commit 2e0df54

Browse files
authored
Allow self identified and system user in action controller (#1158)
* allows system and selfidentified users to use user actions * changes double equals to is
1 parent 198b2e8 commit 2e0df54

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

src/Altinn.App.Api/Controllers/ActionsController.cs

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public async Task<ActionResult<UserActionResponse>> Perform(
8080
)
8181
{
8282
string? action = actionRequest.Action;
83-
if (action == null)
83+
if (action is null)
8484
{
8585
return new BadRequestObjectResult(
8686
new ProblemDetails()
@@ -94,7 +94,7 @@ public async Task<ActionResult<UserActionResponse>> Perform(
9494
}
9595

9696
Instance instance = await _instanceClient.GetInstance(app, org, instanceOwnerPartyId, instanceGuid);
97-
if (instance?.Process == null)
97+
if (instance?.Process is null)
9898
{
9999
return Conflict($"Process is not started.");
100100
}
@@ -105,8 +105,16 @@ public async Task<ActionResult<UserActionResponse>> Perform(
105105
}
106106

107107
var currentAuth = _authenticationContext.Current;
108-
if (currentAuth is not Authenticated.User user)
109-
return Unauthorized();
108+
109+
switch (currentAuth)
110+
{
111+
case Authenticated.User:
112+
case Authenticated.SystemUser:
113+
case Authenticated.SelfIdentifiedUser:
114+
break;
115+
default:
116+
return Unauthorized();
117+
}
110118

111119
bool authorized = await _authorization.AuthorizeAction(
112120
new AppIdentifier(org, app),
@@ -124,14 +132,14 @@ public async Task<ActionResult<UserActionResponse>> Perform(
124132

125133
UserActionContext userActionContext = new(
126134
dataMutator,
127-
user.UserId,
135+
null, // let userId be derived from currentAuth
128136
actionRequest.ButtonId,
129137
actionRequest.Metadata,
130138
language,
131139
currentAuth
132140
);
133141
IUserAction? actionHandler = _userActionService.GetActionHandler(action);
134-
if (actionHandler == null)
142+
if (actionHandler is null)
135143
{
136144
return new NotFoundObjectResult(
137145
new UserActionResponse()
@@ -148,7 +156,7 @@ public async Task<ActionResult<UserActionResponse>> Perform(
148156

149157
UserActionResult result = await actionHandler.HandleAction(userActionContext);
150158

151-
if (result.ResultType == ResultType.Failure)
159+
if (result.ResultType is ResultType.Failure)
152160
{
153161
return StatusCode(
154162
statusCode: result.ErrorType switch

src/Altinn.App.Core/Features/Action/UniqueSignatureAuthorizer.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ public async Task<bool> AuthorizeAction(UserActionAuthorizerContext context)
8585
Authenticated.User a => a.UserId.ToString(CultureInfo.InvariantCulture) == signee?.UserId,
8686
Authenticated.SelfIdentifiedUser a => a.UserId.ToString(CultureInfo.InvariantCulture)
8787
== signee?.UserId,
88-
Authenticated.SystemUser a => a.SystemUserId[0].ToString() == signee?.UserId, // TODO: wait for systemuserid
88+
Authenticated.SystemUser a => a.SystemUserId[0] == signee?.SystemUserId,
8989
_ => false,
9090
};
9191
if (unauthorized)

0 commit comments

Comments
 (0)