Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implements default signing task validator #1046

Open
wants to merge 6 commits into
base: feature/signing
Choose a base branch
from

Conversation

cammiida
Copy link
Contributor

@cammiida cammiida commented Jan 20, 2025

Description

Default validator for all signing tasks. Runs by default if not runDefaultValidator="false" in process.bpmn.

Should it be called runDefaultValidations instead? 🤷‍♀️

Verification

  • Your code builds clean without any errors or warnings
  • Manual testing done (required)
  • Relevant automated test added (if you find this hard, leave it and we'll help out)
  • All tests run green

Documentation

  • User documentation is updated with a separate linked PR in altinn-studio-docs. (if applicable)

@cammiida cammiida added the feature Label Pull requests with new features. Used when generation releasenotes label Jan 20, 2025
@cammiida
Copy link
Contributor Author

/publish

@cammiida cammiida marked this pull request as ready for review January 21, 2025 11:04
@cammiida
Copy link
Contributor Author

/publish

Copy link

github-actions bot commented Jan 21, 2025

PR release:

⚙️ Building...
✅ Done!

@cammiida cammiida linked an issue Jan 21, 2025 that may be closed by this pull request
Copy link
Contributor

@danielskovli danielskovli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🥇

Copy link
Contributor

@HauklandJ HauklandJ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🙌

_processReader.GetAltinnTaskExtension(taskId)?.SignatureConfiguration
);

if (signingConfiguration == null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (signingConfiguration == null)
if (signingConfiguration is null)

}

var (getAppMetadataError, appMetadata) = await CatchError(_appMetadata.GetApplicationMetadata());
if (getAppMetadataError != null || appMetadata == null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (getAppMetadataError != null || appMetadata == null)
if (getAppMetadataError is not null || appMetadata is null)

var (getSigneeContextsError, signeeContexts) = await CatchError(
_signingService.GetSigneeContexts(cachedDataMutator, signingConfiguration)
);
if (getSigneeContextsError != null || signeeContexts == null)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (getSigneeContextsError != null || signeeContexts == null)
if (getSigneeContextsError is not null || signeeContexts is null)

return [];
}

var allHaveSigned = signeeContexts.All(signeeContext => signeeContext.SignDocument != null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
var allHaveSigned = signeeContexts.All(signeeContext => signeeContext.SignDocument != null);
var allHaveSigned = signeeContexts.All(signeeContext => signeeContext.SignDocument is not null);

/// <summary>
/// Catch exceptions from a task and return them as a tuple with the result.
/// </summary>
private static async Task<Tuple<Exception?, T?>> CatchError<T>(Task<T> task)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be an internal utility?


AltinnSignatureConfiguration? signingConfiguration = taskConfig?.SignatureConfiguration;

return signingConfiguration?.RunDefaultValidator == true && taskConfig?.TaskType == "signing";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have a "TaskTypeConst" similar to LanguageConst, but I consider it outside the scope of this pr. I will create and issue for it.

}
catch (Exception ex)
{
_logger.LogError(ex, $"Error while fetching signing configuration for task {taskId}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This log message will be noisy and confusing if a ProcessElement is missing the TaskExtension tag, because this ShouldRunForTask runs on all tasks (also those that are not signature tasks)

/// </summary>
public Task<bool> HasRelevantChanges(IInstanceDataAccessor dataAccessor, string taskId, DataElementChanges changes)
{
throw new NotImplementedException();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can add the documentation as a message, so that it is easier to understand why this is not implemented.

Suggested change
throw new NotImplementedException();
throw new UnreachableException("HasRelevantChanges should never be called because NoIncrementalValidation is true.");

This might need to import using System.Diagnostics;

if (signingConfiguration == null)
{
_logger.LogError($"No signing configuration found for task {taskId}");
return [];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was checked by ShouldRunForTask, so throw here as well.

);

var (getSigneeContextsError, signeeContexts) = await CatchError(
_signingService.GetSigneeContexts(cachedDataMutator, signingConfiguration)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should be able to get the signeeContexts from the dataAccessor instead of instantiating a Mutator in a validator.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You would need to update the signatures in the signing service to use IInstanceDataAccessor

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature Label Pull requests with new features. Used when generation releasenotes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Standard implementation of signing task validator
5 participants