MOBILE-2788 assign: Check if the user can view their own submission
parent
1fcc4dbfd5
commit
4b944cec7e
|
@ -31,7 +31,7 @@
|
|||
</div>
|
||||
|
||||
<!-- User can view all submissions (teacher). -->
|
||||
<ion-card *ngIf="assign && canViewSubmissions" class="core-list-align-detail-right">
|
||||
<ion-card *ngIf="assign && canViewAllSubmissions" class="core-list-align-detail-right">
|
||||
<ion-item text-wrap *ngIf="timeRemaining">
|
||||
<h2>{{ 'addon.mod_assign.timeremaining' | translate }}</h2>
|
||||
<p>{{ timeRemaining }}</p>
|
||||
|
@ -82,6 +82,6 @@
|
|||
</ion-card>
|
||||
|
||||
<!-- If it's a student, display his submission. -->
|
||||
<addon-mod-assign-submission *ngIf="loaded && !canViewSubmissions" [courseId]="courseId" [moduleId]="module.id"></addon-mod-assign-submission>
|
||||
<addon-mod-assign-submission *ngIf="loaded && !canViewAllSubmissions && canViewOwnSubmission" [courseId]="courseId" [moduleId]="module.id"></addon-mod-assign-submission>
|
||||
|
||||
</core-loading>
|
||||
|
|
|
@ -38,7 +38,8 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo
|
|||
moduleName = 'assign';
|
||||
|
||||
assign: any; // The assign object.
|
||||
canViewSubmissions: boolean; // Whether the user can view all submissions.
|
||||
canViewAllSubmissions: boolean; // Whether the user can view all submissions.
|
||||
canViewOwnSubmission: boolean; // Whether the user can view their own submission.
|
||||
timeRemaining: string; // Message about time remaining to submit.
|
||||
lateSubmissions: string; // Message about late submissions.
|
||||
showNumbers = true; // Whether to show number of submissions with each status.
|
||||
|
@ -80,16 +81,16 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo
|
|||
// Ignore errors.
|
||||
});
|
||||
|
||||
if (!this.canViewSubmissions) {
|
||||
// User can only see his submission, log view the user submission.
|
||||
this.assignProvider.logSubmissionView(this.assign.id).catch(() => {
|
||||
// Ignore errors.
|
||||
});
|
||||
} else {
|
||||
if (this.canViewAllSubmissions) {
|
||||
// User can see all submissions, log grading view.
|
||||
this.assignProvider.logGradingView(this.assign.id).catch(() => {
|
||||
// Ignore errors.
|
||||
});
|
||||
} else if (this.canViewOwnSubmission) {
|
||||
// User can only see their own submission, log view the user submission.
|
||||
this.assignProvider.logSubmissionView(this.assign.id).catch(() => {
|
||||
// Ignore errors.
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -165,7 +166,7 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo
|
|||
return this.assignProvider.getSubmissions(this.assign.id).then((data) => {
|
||||
const time = this.timeUtils.timestamp();
|
||||
|
||||
this.canViewSubmissions = data.canviewsubmissions;
|
||||
this.canViewAllSubmissions = data.canviewsubmissions;
|
||||
|
||||
if (data.canviewsubmissions) {
|
||||
|
||||
|
@ -206,6 +207,17 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo
|
|||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Check if the user can view their own submission.
|
||||
return this.assignProvider.getSubmissionStatus(this.assign.id).then(() => {
|
||||
this.canViewOwnSubmission = true;
|
||||
}).catch((error) => {
|
||||
this.canViewOwnSubmission = false;
|
||||
|
||||
if (error.errorcode !== 'nopermission') {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
});
|
||||
});
|
||||
}).then(() => {
|
||||
// All data obtained, now fill the context menu.
|
||||
|
@ -263,7 +275,7 @@ export class AddonModAssignIndexComponent extends CoreCourseModuleMainActivityCo
|
|||
if (this.assign) {
|
||||
promises.push(this.assignProvider.invalidateAllSubmissionData(this.assign.id));
|
||||
|
||||
if (this.canViewSubmissions) {
|
||||
if (this.canViewAllSubmissions) {
|
||||
promises.push(this.assignProvider.invalidateSubmissionStatusData(this.assign.id));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -64,9 +64,16 @@ export class AddonModAssignPrefetchHandler extends CoreCourseActivityPrefetchHan
|
|||
canUseCheckUpdates(module: any, courseId: number): boolean | Promise<boolean> {
|
||||
// Teachers cannot use the WS because it doesn't check student submissions.
|
||||
return this.assignProvider.getAssignment(courseId, module.id).then((assign) => {
|
||||
return this.assignProvider.getSubmissions(assign.id);
|
||||
}).then((data) => {
|
||||
return !data.canviewsubmissions;
|
||||
return this.assignProvider.getSubmissions(assign.id).then((data) => {
|
||||
if (data.canviewsubmissions) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if the user can view their own submission.
|
||||
return this.assignProvider.getSubmissionStatus(assign.id).then(() => {
|
||||
return true;
|
||||
});
|
||||
});
|
||||
}).catch(() => {
|
||||
return false;
|
||||
});
|
||||
|
@ -322,10 +329,16 @@ export class AddonModAssignPrefetchHandler extends CoreCourseActivityPrefetchHan
|
|||
}));
|
||||
} else {
|
||||
// Student.
|
||||
promises.push(this.assignProvider.getSubmissionStatus(assign.id, userId, false, true, false, siteId)
|
||||
.then((subm) => {
|
||||
return this.prefetchSubmission(assign, courseId, moduleId, subm, userId, siteId);
|
||||
}));
|
||||
promises.push(
|
||||
this.assignProvider.getSubmissionStatus(assign.id, userId, false, true, false, siteId).then((subm) => {
|
||||
return this.prefetchSubmission(assign, courseId, moduleId, subm, userId, siteId);
|
||||
}).catch((error) => {
|
||||
// Ignore if the user can't view their own submission.
|
||||
if (error.errorcode != 'nopermission') {
|
||||
return Promise.reject(error);
|
||||
}
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
promises.push(this.groupsProvider.activityHasGroups(assign.cmid));
|
||||
|
|
Loading…
Reference in New Issue