Feature #24227
closedAdd hosts_count, can_edit/delete/create in Models API response
Description
The motivation behind this is to get necessary data from API instead Rails helpers.
Background:
Currently when Hardware Model is rendered on the server side it uses the following helpers:
1) link_to_if_authorized
2) display_delete_if_authorized
3) hosts_count
(1) and (2) are used to provide actions to the user according to its permissions
and (3) is to allow to see hosts that are using a given model.
Any action done on the client side: changing the per_page selector, searching or sorting a column sends an HTTP request that returns some HTML rendered by Rails.
Moving this page to a React component changes the way the page is rendered. Instead of getting HTML from Rails, JSON is returned which is rendered back to HTML using React and Redux.
In order to render the HTML similarly to how it is done nowadays, hosts_count and the permissions are required to be shown in the API.
Thus, this ticket. The Models API should have "can_edit" and "can_delete" per model to determine whether the user is allowed to edit or to delete respectively. In addition, "hosts_count" for each model to display this information in the table.
The "can_create" attribute will be displayed only once and tells if the current user can create a new model or not.