You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. import { Avatar, ContentCell, Note, TableRowInteractive } from 'design-system';
  21. import * as React from 'react';
  22. import { translate } from '../../helpers/l10n';
  23. import { isPermissionDefinitionGroup } from '../../helpers/permissions';
  24. import { isDefined } from '../../helpers/types';
  25. import { PermissionDefinitions, PermissionUser } from '../../types/types';
  26. import { Image } from '../common/Image';
  27. import PermissionCell from './PermissionCell';
  28. import usePermissionChange from './usePermissionChange';
  29. interface Props {
  30. onToggle: (user: PermissionUser, permission: string) => Promise<void>;
  31. permissions: PermissionDefinitions;
  32. selectedPermission?: string;
  33. user: PermissionUser;
  34. disabled?: boolean;
  35. removeOnly?: boolean;
  36. }
  37. export default function UserHolder(props: Props) {
  38. const { user, disabled, removeOnly, permissions, selectedPermission } = props;
  39. const { loading, handleCheck, modal } = usePermissionChange({
  40. holder: user,
  41. onToggle: props.onToggle,
  42. permissions,
  43. removeOnly,
  44. });
  45. const permissionCells = permissions.map((permission) => (
  46. <PermissionCell
  47. key={isPermissionDefinitionGroup(permission) ? permission.category : permission.key}
  48. loading={loading}
  49. onCheck={handleCheck}
  50. permission={permission}
  51. disabled={disabled}
  52. removeOnly={removeOnly}
  53. permissionItem={user}
  54. prefixID={user.login}
  55. selectedPermission={selectedPermission}
  56. />
  57. ));
  58. if (user.login === '<creator>') {
  59. return (
  60. <TableRowInteractive>
  61. <ContentCell>
  62. <div className="sw-max-w-abs-800">
  63. <div className="sw-flex sw-flex-col sw-w-fit sw-max-w-full">
  64. <strong className="sw-text-ellipsis sw-whitespace-nowrap sw-overflow-hidden">
  65. {user.name}
  66. </strong>
  67. <p className="sw-mt-2">
  68. {translate('permission_templates.project_creators.explanation')}
  69. </p>
  70. </div>
  71. </div>
  72. </ContentCell>
  73. {permissionCells}
  74. </TableRowInteractive>
  75. );
  76. }
  77. return (
  78. <TableRowInteractive>
  79. <ContentCell>
  80. <div className="sw-flex sw-items-center">
  81. <Avatar className="sw-mr-4" hash={user.avatar} name={user.name} size="md" />
  82. <div className="sw-max-w-abs-800">
  83. <div className="sw-flex sw-w-fit sw-max-w-full">
  84. <div className="sw-flex-1 sw-text-ellipsis sw-whitespace-nowrap sw-overflow-hidden">
  85. <strong>{user.name}</strong>
  86. <Note className="sw-ml-2">{user.login}</Note>
  87. </div>
  88. {disabled && (
  89. <Image
  90. alt="github"
  91. className="sw-ml-2"
  92. height={16}
  93. aria-label={translate('project_permission.github_managed')}
  94. src="/images/alm/github.svg"
  95. />
  96. )}
  97. </div>
  98. {isDefined(user.email) && (
  99. <div className="sw-mt-2 sw-max-w-100 sw-text-ellipsis sw-whitespace-nowrap sw-overflow-hidden">
  100. {user.email}
  101. </div>
  102. )}
  103. </div>
  104. </div>
  105. </ContentCell>
  106. {permissionCells}
  107. {modal}
  108. </TableRowInteractive>
  109. );
  110. }