Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 46 additions & 0 deletions packages/client/src/tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,52 @@ export default class Tools {
return Array.from(conflicts);
}

/**
* Checks if a profile meets the minimum requirements defined by a venue.
*
* @param {object} profile - The profile object.
* @param {object} profileReqs - An object defining the required profile fields and conditions.
* @returns {boolean} - Returns true if the profile satisfies all requirements, false otherwise.
*/
isProfileComplete(profile, profileReqs) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Could you add a test to see what profileReqs looks like?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It's located here right?: packages/client/test/test.js

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Yes, that's the right spot.

// If no profile or no requirements, skip check
if (!profile.id.startsWith('~') || !profileReqs) {
Comment thread
enrubio marked this conversation as resolved.
Outdated
return true;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Shouldn't you throw an error if a profile object is not passed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Decided to not check profile.id because the other tools functions that handle profiles don't do this and I think it should be handled at the call site.

}

for (const [profilePath, expectedValue] of Object.entries(profileReqs)) {
const pathItems = profilePath.split('.');
let actualValue = profile;

// Resolve actual value from the profile
for (const item of pathItems) {
if (actualValue && typeof actualValue === 'object') {
actualValue = actualValue?.[item];
} else {
actualValue = null;
}

if (actualValue === null || actualValue === undefined) {
break;
}
}

// Check number of entries
if (typeof expectedValue === 'number') {
if (actualValue?.length < expectedValue) {
return false;
}
// Check if field exists in profile (e.g. links)
} else if (expectedValue === true && !actualValue) {
return false;
} else {
console.log(`Invalid path: ${profilePath}`);
Comment thread
enrubio marked this conversation as resolved.
Outdated
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Should we throw an error here instead of logging it?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

The logic was simplified so that PCs aren't allowed to require random parts of the profile. Now I ignore incorrect input from PCs by returning true (e.g. if they set "dblp": true) so that a person isn't wrongly marked as incomplete.

}
}

return true;
}

/**
* Get the profile information for a given profile that includes the domains, emails, relations and publications.
*
Expand Down