Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions app/dashboard/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ export default class Dashboard extends Controller {
popular!: QueryHasManyResult<Node>;
useSimplePage: boolean = simplePage;
useSearch: string = useSearch ? 'true' : 'false';
canCreateNewProject: boolean = true;

@task({ restartable: true })
setupTask = task(function *(this: Dashboard) {
Expand All @@ -66,6 +67,7 @@ export default class Dashboard extends Controller {
this.findNodes.perform(),
this.getPopularAndNoteworthy.perform(popularNode, 'popular'),
this.getPopularAndNoteworthy.perform(noteworthyNode, 'noteworthy'),
this.checkCreateProjectPermission.perform(),
]);

this.set('institutions', institutions.toArray());
Expand Down Expand Up @@ -119,6 +121,20 @@ export default class Dashboard extends Controller {
}
});

@task({ restartable: true })
checkCreateProjectPermission = task(function *(this: Dashboard) {
const user = yield this.currentUser.user;
const url: string = `${config.OSF.apiUrl}/v2/users/${user.id}/settings/create-project-permission/`;
try {
const response = yield this.currentUser.authenticatedAJAX({ url });
if (response) {
this.set('canCreateNewProject', response.can_create_new_project);
}
} catch (e) {
this.set('canCreateNewProject', true);
}
});

@alias('currentUser.user') user!: User;

@or('nodes.length', 'filter', 'findNodes.isRunning') hasNodes!: boolean;
Expand Down
1 change: 1 addition & 0 deletions app/dashboard/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
@onClick={{action this.openModal}}
@type='success'
@class='m-t-md f-w-xl'
@disabled={{not this.canCreateNewProject}}
>
{{t 'dashboard.create_new_project_button'}}
</OsfButton>
Expand Down
11 changes: 11 additions & 0 deletions lib/osf-components/addon/components/new-project-modal/component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ export default class NewProjectModal extends Component {
regions: Region[] = [];
running: boolean = false;
createError: boolean = false;
createErrorMessage?: string;

makeProjectAffiliate: boolean = projectAffiliate;

Expand Down Expand Up @@ -147,6 +148,16 @@ export default class NewProjectModal extends Component {
this.afterProjectCreated(node);
} catch (error) {
this.toast.error(this.intl.t('new_project.create_failed_header'));
let errorMessage = this.intl.t('new_project.create_failed_msg');
const errorObj = error.errors.firstObject;
if (errorObj && errorObj.status) {
if (errorObj.status === 403) {
errorMessage = this.intl.t('new_project.forbidden');
} else if (errorObj.status === 400 && errorObj.type === 1) {
errorMessage = this.intl.t('new_project.limited');
}
}
this.set('createErrorMessage', errorMessage);
this.set('createError', true);
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<h3 data-test-create-project-header class='modal-title'>{{t 'new_project.create_failed_header'}}</h3>
</modal.header>
<modal.body>
<div class='text-left'>{{t 'new_project.create_failed_msg'}}</div>
<div class='text-left'>{{this.createErrorMessage}}</div>
</modal.body>
<modal.footer data-analytics-scope='New project modal footer'>
<OsfButton
Expand Down
2 changes: 2 additions & 0 deletions translations/en-us.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ new_project:
creating: 'Saving your project...'
create_failed_header: 'Couldn''t create your project'
create_failed_msg: 'There was an unknown error. Please try again later.'
forbidden: 'You do not have permission to operate a project.'
limited: 'The new project cannot be created due to the created project number is greater than or equal the project number can create.'
banners:
prereg:
description: 'Improve your next study. Enter the Prereg Challenge and you could win $1,000.'
Expand Down
2 changes: 2 additions & 0 deletions translations/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,8 @@ new_project:
creating: プロジェクトを保存中...
create_failed_header: プロジェクトを作成できませんでした
create_failed_msg: '不明なエラーが発生しました。 後でもう一度やり直してください。'
forbidden: 'プロジェクトに対する操作権限がありません。'
limited: '作成したプロジェクト数が作成可能なプロジェクトの数以上であるために、新規プロジェクトを作成できません。'
banners:
prereg:
description: 'あなたの次の研究を改善してください。 Prereg Challengeに参加すれば$ 1,000を獲得できます。'
Expand Down