processsAclItems.ts 805 B

1234567891011121314151617181920212223242526272829303132
  1. import { DashboardAcl, DashboardAclDTO } from 'app/types/acl';
  2. export function processAclItems(items: DashboardAclDTO[]): DashboardAcl[] {
  3. return items.map(processAclItem).sort((a, b) => b.sortRank! - a.sortRank! || a.name!.localeCompare(b.name!));
  4. }
  5. function processAclItem(dto: DashboardAclDTO): DashboardAcl {
  6. const item = dto as DashboardAcl;
  7. item.sortRank = 0;
  8. if (item.userId! > 0) {
  9. item.name = item.userLogin;
  10. item.sortRank = 10;
  11. } else if (item.teamId! > 0) {
  12. item.name = item.team;
  13. item.sortRank = 20;
  14. } else if (item.role) {
  15. item.icon = 'fa fa-fw fa-street-view';
  16. item.name = item.role;
  17. item.sortRank = 30;
  18. if (item.role === 'Editor') {
  19. item.sortRank += 1;
  20. }
  21. }
  22. if (item.inherited) {
  23. item.sortRank += 100;
  24. }
  25. return item;
  26. }