Skip to content
Merged
Changes from 2 commits
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
17 changes: 16 additions & 1 deletion src/form-builder/components/FormPrivilegeTable.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,30 @@ export default class FormPrivilegeTable extends Component {
this.setState({ loading: false });
});
}

fetchPrivileges() {
let initialPrivileges = [];
let privileges = [];
const queryParams = '?=';
const optionsUrl = `${formBuilderConstants.formPrivilegeUrl}${queryParams}`;
httpInterceptor.get(optionsUrl)
.then((initialPrivileges) => {
this.setState({ availablePrivileges: this.arrangePrivileges(initialPrivileges.results), loading: false });
this.collectAllPrivileges(initialPrivileges, privileges);
});
}

collectAllPrivileges(initialPrivileges, allPrivileges) {
allPrivileges.push(...initialPrivileges.results);
if (initialPrivileges.links.length > 0 && initialPrivileges.links.find(link => link.rel === "next") !== undefined) {
httpInterceptor.get(initialPrivileges.links[0].uri)

Choose a reason for hiding this comment

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

What happens if the API has a bug? If the API incorrectly keeps returning a "next" link indefinitely, this function never stops calling itself. Could introducing a limit be a safer option?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can introduce a limit but its like we are not trusting our systems.

Choose a reason for hiding this comment

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

It's always a good practice to introduce a limit. It's not that we are not trusting our systems but it's defensive programming to avoid rare but critical issues. Logic wise, it's all good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, I'll go ahead and add a limit

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@arshiyaTW2021 I have added the limit.

.then((privileges) => {
return this.collectAllPrivileges(privileges, allPrivileges)
});
} else {
this.setState({ availablePrivileges: this.arrangePrivileges(allPrivileges), loading: false });
}
}

fetchFormPrivilegesFromDB() {
let initialPrivilegesFromDB = [];
const queryParams = '?=';
Expand Down