attachmentUrl.tsx 915 B

12345678910111213141516171819202122232425262728293031
  1. import * as React from 'react';
  2. import Role from 'app/components/acl/role';
  3. import {EventAttachment, Organization} from 'app/types';
  4. import withOrganization from 'app/utils/withOrganization';
  5. type Props = {
  6. organization: Organization;
  7. projectId: string;
  8. eventId: string;
  9. attachment: EventAttachment;
  10. children: (downloadUrl: string | null) => React.ReactNode;
  11. };
  12. class AttachmentUrl extends React.PureComponent<Props> {
  13. getDownloadUrl() {
  14. const {attachment, organization, eventId, projectId} = this.props;
  15. return `/api/0/projects/${organization.slug}/${projectId}/events/${eventId}/attachments/${attachment.id}/`;
  16. }
  17. render() {
  18. const {children, organization} = this.props;
  19. return (
  20. <Role role={organization.attachmentsRole}>
  21. {({hasRole}) => children(hasRole ? this.getDownloadUrl() : null)}
  22. </Role>
  23. );
  24. }
  25. }
  26. export default withOrganization(AttachmentUrl);