Skip to content
Snippets Groups Projects
Commit f580ad7d authored by Ron Lucke's avatar Ron Lucke
Browse files

Aktion "Inhalt kopieren" bei einer abgegebenen Aufgabe funktioniert nicht

Closes #2805

Merge request studip/studip!3312
parent 81080a23
No related branches found
No related tags found
No related merge requests found
......@@ -29,7 +29,8 @@ class StructuralElementsCopy extends NonJsonApiController
$sourceElement = StructuralElement::find($args['id']);
$newParent = StructuralElement::find($data['parent_id']);
$user = $this->getUser($request);
if (!Authority::canCreateStructuralElement($user, $newParent) || !Authority::canUpdateStructuralElement($user, $sourceElement)) {
$sourceAuthorityFunction = $sourceElement->isTask() ? 'canShowStructuralElement' : 'canUpdateStructuralElement';
if (!Authority::canCreateStructuralElement($user, $newParent) || !Authority::$sourceAuthorityFunction($user, $sourceElement)) {
throw new AuthorizationFailedException();
}
......
......@@ -69,7 +69,7 @@
:items="getTaskMenuItems(task, status, element)"
@submitTask="displaySubmitDialog(task)"
@renewalRequest="renewalRequest(task)"
@copyContent="copyContent(element)"
@copyContent="copyContent(taskGroup, element)"
/>
</td>
</tr>
......@@ -147,6 +147,7 @@ export default {
getElementById: 'courseware-structural-elements/byId',
getFeedbackById: 'courseware-task-feedback/byId',
getTaskGroupById: 'courseware-task-groups/byId',
lastCreateCoursewareUnit: 'courseware-units/lastCreated',
}),
tasks() {
return this.allTasks.map((task) => {
......@@ -173,6 +174,7 @@ export default {
copyStructuralElement: 'copyStructuralElement',
companionSuccess: 'companionSuccess',
companionError: 'companionError',
createCoursewareUnit: 'courseware-units/create',
}),
getTaskMenuItems(task, status, element) {
let menuItems = [];
......@@ -195,7 +197,7 @@ export default {
});
}
if (task.attributes.submitted) {
menuItems.push({ id: 4, label: this.$gettext('Inhalt kopieren'), icon: 'export', emit: 'copyContent' });
menuItems.push({ id: 4, label: this.$gettext('Inhalt auf Arbeitsplatz kopieren'), icon: 'export', emit: 'copyContent' });
}
return menuItems;
......@@ -233,28 +235,43 @@ export default {
});
this.currentTask = null;
},
async copyContent(element) {
let ownCoursewareInstance = await this.loadRemoteCoursewareStructure({
rangeId: this.userId,
rangeType: 'users',
async copyContent(taskGroup, element) {
const unit = {
attributes: {
title: taskGroup.attributes.title,
purpose: 'content',
payload: {
description: '',
color: 'studip-blue',
license_type: '',
required_time: '',
difficulty_start: '',
difficulty_end: ''
},
settings: {
'root-layout': 'classic'
}
},
relationships: {
range: {
data: {
type: 'users',
id: this.userId
}
}
}
};
await this.createCoursewareUnit(unit, { root: true });
const newElementId = this.lastCreateCoursewareUnit.relationships['structural-element'].data.id
await this.copyStructuralElement({
parentId: newElementId,
elementId: element.id,
removeType: false,
migrate: true,
});
this.companionSuccess({
info: this.$gettext('Die Inhalte wurden zu Ihren persönlichen Lernmaterialien hinzugefügt.'),
});
if (ownCoursewareInstance !== null) {
await this.copyStructuralElement({
parentId: ownCoursewareInstance.relationships.root.data.id,
elementId: element.id,
removeType: true,
migrate: false,
});
this.companionSuccess({
info: this.$gettext('Die Inhalte wurden zu Ihren persönlichen Lernmaterialien hinzugefügt.'),
});
} else {
this.companionError({
info: this.$gettext(
'Die Inhalte konnten nicht zu Ihren persönlichen Lernmaterialien hinzugefügt werden.'
),
});
}
},
displayFeedback(feedback) {
this.showFeedbackDialog = true;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment