Merge pull request #13618 from overleaf/tw-reference-manager-access

Tw reference manager access

GitOrigin-RevId: e4554f2fcfd0aa9193497daae3ac1da18629d0de
This commit is contained in:
Tyna William 2023-07-06 16:43:13 -04:00 committed by Copybot
parent a16f168e54
commit 840f56f330
4 changed files with 87 additions and 14 deletions

View file

@ -15,7 +15,6 @@
"about_to_trash_projects": "",
"accept": "",
"accepted_invite": "",
"access_denied": "",
"account_has_been_link_to_institution_account": "",
"account_has_past_due_invoice_change_plan_warning": "",
"account_not_linked_to_dropbox": "",
@ -664,6 +663,7 @@
"ok": "",
"on": "",
"on_free_plan_upgrade_to_access_features": "",
"only_importer_can_refresh": "",
"open_project": "",
"optional": "",
"or": "",
@ -914,6 +914,7 @@
"showing_x_out_of_n_projects": "",
"showing_x_results": "",
"showing_x_results_of_total": "",
"something_not_right": "",
"something_went_wrong_loading_pdf_viewer": "",
"something_went_wrong_processing_the_request": "",
"something_went_wrong_rendering_pdf": "",

View file

@ -7,6 +7,8 @@ import { formatTime, relativeDate } from '../../utils/format-date'
import { postJSON } from '../../../infrastructure/fetch-json'
import { useEditorContext } from '../../../shared/context/editor-context'
import { useProjectContext } from '../../../shared/context/project-context'
import { useUserContext } from '../../../shared/context/user-context'
import { capitalize } from 'lodash'
import importOverleafModules from '../../../../macros/import-overleaf-module.macro'
import useAbortController from '../../../shared/hooks/use-abort-controller'
@ -40,6 +42,7 @@ export default function FileViewHeader({ file, storeReferencesKeys }) {
const { permissionsLevel } = useEditorContext({
permissionsLevel: PropTypes.string,
})
const { id: userId } = useUserContext()
const { t } = useTranslation()
const [refreshing, setRefreshing] = useState(false)
@ -48,7 +51,9 @@ export default function FileViewHeader({ file, storeReferencesKeys }) {
const { signal } = useAbortController()
let fileInfo
let isImporter
if (file.linkedFileData) {
isImporter = file.linkedFileData.importer_id === userId
if (file.linkedFileData.provider === 'url') {
fileInfo = (
<div>
@ -117,9 +122,9 @@ export default function FileViewHeader({ file, storeReferencesKeys }) {
))}
{file.linkedFileData && permissionsLevel !== 'readOnly' && (
<button
className="btn btn-primary"
className={`btn ${isImporter ? 'btn-primary' : 'btn-secondary'}`}
onClick={refreshFile}
disabled={refreshing}
disabled={refreshing || !isImporter}
>
<Icon type="refresh" spin={refreshing} fw />
<span>{refreshing ? t('refreshing') + '...' : t('refresh')}</span>
@ -135,16 +140,41 @@ export default function FileViewHeader({ file, storeReferencesKeys }) {
&nbsp;
<span>{t('download')}</span>
</a>
{!isImporter && (
<div className="row">
<div className="alert">
{t('only_importer_can_refresh', {
provider: capitalize(file.linkedFileData.provider),
})}
</div>
</div>
)}
{refreshError && (
<div className="row">
<br />
<div className="alert alert-danger col-md-6 col-md-offset-3">
{t('access_denied')}: {refreshError}
{tprLinkedFileRefreshError.map(
({ import: { LinkedFileRefreshError }, path }) => (
<LinkedFileRefreshError key={path} file={file} />
)
)}
<div
className="alert alert-danger col-md-10 col-md-offset-1"
style={{ display: 'flex', alignItems: 'center', gap: '10px' }}
>
<div>
{t('something_not_right')}!&nbsp;
{tprLinkedFileRefreshError.map(
({ import: { LinkedFileRefreshError }, path }) => (
<LinkedFileRefreshError key={path} file={file} />
)
)}
</div>
<div className="text-center">
<button className="btn btn-danger">
<a
href="/user/settings"
target="_blank"
style={{ fontWeight: 'bold', textDecoration: 'none' }}
>
{t('go_to_settings')}
</a>
</button>
</div>
</div>
</div>
)}

View file

@ -730,7 +730,7 @@
"hundreds_templates_info": "Produce beautiful documents starting from our gallery of LaTeX templates for journals, conferences, theses, reports, CVs and much more.",
"i_confirm_that_i_am_a_student": "I confirm that I am a student",
"i_want_to_stay": "I want to stay",
"if_error_persists_try_relinking_provider": "If this error persists, try re-linking your __provider__ account here",
"if_error_persists_try_relinking_provider": "It looks like you need to re-link your __provider__ account.",
"if_have_existing_can_link": "If you have an existing <b>__appName__</b> account on another email, you can link it to your <b>__institutionName__</b> account by clicking <b>__clickText__</b>.",
"if_owner_can_link": "If you own the <b>__appName__</b> account with <b>__email__</b>, you will be allowed to link it to your <b>__institutionName__</b> institutional account.",
"ignore_and_continue_institution_linking": "You can also ignore this and <a href=\"__link__\">continue to __appName__ with your <b>__email__</b> account</a>.",
@ -1085,6 +1085,7 @@
"one_collaborator": "Only one collaborator",
"one_free_collab": "One free collaborator",
"online_latex_editor": "Online LaTeX Editor",
"only_importer_can_refresh": "Only the person who originally imported this __provider__ file can refresh it.",
"open_a_file_on_the_left": "Open a file on the left",
"open_as_template": "Open as Template",
"open_project": "Open Project",
@ -1464,6 +1465,7 @@
"skip_to_content": "Skip to content",
"sl_gives_you_free_stuff_see_progress_below": "When someone starts using __appName__ after your recommendation well give you some <strong>free stuff</strong> to say thanks! Check your progress below.",
"sl_included_history_of_changes_blurb": "__appName__ includes a history of all of your changes so you can see exactly who changed what, and when. This makes it extremely easy to keep up to date with any progress made by your collaborators and allows you to review recent work.",
"something_not_right": "Somethings not right",
"something_went_wrong_canceling_your_subscription": "Something went wrong canceling your subscription. Please contact support.",
"something_went_wrong_loading_pdf_viewer": "Something went wrong loading the PDF viewer. This might be caused by issues like <0>temporary network problems</0> or an <0>outdated web browser</0>. Please follow the <1>troubleshooting steps for access, loading and display problems</1>. If the issue persists, please <2>let us know</2>.",
"something_went_wrong_processing_the_request": "Something went wrong processing the request",

View file

@ -27,6 +27,19 @@ describe('<FileViewHeader/>', function () {
source_project_id: 'source-project-id',
source_entity_path: '/source-entity-path.ext',
provider: 'project_file',
importer_id: '123abd',
},
created: new Date(2021, 1, 17, 3, 24).toISOString(),
}
const notOrignalImporterFile = {
name: 'references.bib',
linkedFileData: {
v1_source_doc_id: 'v1-source-id',
source_project_id: 'source-project-id',
source_entity_path: '/source-entity-path.ext',
provider: 'project_file',
importer_id: '123abc',
},
created: new Date(2021, 1, 17, 3, 24).toISOString(),
}
@ -45,6 +58,7 @@ describe('<FileViewHeader/>', function () {
name: 'example.tex',
linkedFileData: {
provider: 'zotero',
importer_id: '123abd',
},
created: new Date(2021, 1, 17, 3, 24).toISOString(),
}
@ -103,11 +117,13 @@ describe('<FileViewHeader/>', function () {
<FileViewHeader file={projectFile} storeReferencesKeys={() => {}} />
)
fireEvent.click(screen.getByRole('button', { name: 'Refresh' }))
const refreshButton = screen.getByRole('button', { name: 'Refresh' })
fireEvent.click(refreshButton)
await waitForElementToBeRemoved(() =>
screen.getByText('Refreshing', { exact: false })
)
await screen.findByText('Refresh')
})
@ -137,14 +153,38 @@ describe('<FileViewHeader/>', function () {
/>
)
fireEvent.click(screen.getByRole('button', { name: 'Refresh' }))
const refreshButton = screen.getByRole('button', { name: 'Refresh' })
fireEvent.click(refreshButton)
await waitForElementToBeRemoved(() =>
screen.getByText('Refreshing', { exact: false })
)
expect(fetchMock.done()).to.be.true
expect(storeReferencesKeys).to.be.calledWith(reindexResponse.keys)
expect(storeReferencesKeys).to.have.been.calledWith(reindexResponse.keys)
})
it('Displays message when user is not original importer', function () {
renderWithEditorContext(
<FileViewHeader
file={notOrignalImporterFile}
storeReferencesKeys={() => {}}
/>
)
const refreshButton = screen.getByRole('button', { name: 'Refresh' })
if (refreshButton.disabled) {
const textBefore = screen.getByText(
'Only the person who originally imported this',
{ exact: false }
)
expect(textBefore).to.exist
const textAfter = screen.getByText('file can refresh it', {
exact: false,
})
expect(textAfter).to.exist
}
})
})