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 ...@@ -29,7 +29,8 @@ class StructuralElementsCopy extends NonJsonApiController
$sourceElement = StructuralElement::find($args['id']); $sourceElement = StructuralElement::find($args['id']);
$newParent = StructuralElement::find($data['parent_id']); $newParent = StructuralElement::find($data['parent_id']);
$user = $this->getUser($request); $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(); throw new AuthorizationFailedException();
} }
......
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
:items="getTaskMenuItems(task, status, element)" :items="getTaskMenuItems(task, status, element)"
@submitTask="displaySubmitDialog(task)" @submitTask="displaySubmitDialog(task)"
@renewalRequest="renewalRequest(task)" @renewalRequest="renewalRequest(task)"
@copyContent="copyContent(element)" @copyContent="copyContent(taskGroup, element)"
/> />
</td> </td>
</tr> </tr>
...@@ -147,6 +147,7 @@ export default { ...@@ -147,6 +147,7 @@ export default {
getElementById: 'courseware-structural-elements/byId', getElementById: 'courseware-structural-elements/byId',
getFeedbackById: 'courseware-task-feedback/byId', getFeedbackById: 'courseware-task-feedback/byId',
getTaskGroupById: 'courseware-task-groups/byId', getTaskGroupById: 'courseware-task-groups/byId',
lastCreateCoursewareUnit: 'courseware-units/lastCreated',
}), }),
tasks() { tasks() {
return this.allTasks.map((task) => { return this.allTasks.map((task) => {
...@@ -173,6 +174,7 @@ export default { ...@@ -173,6 +174,7 @@ export default {
copyStructuralElement: 'copyStructuralElement', copyStructuralElement: 'copyStructuralElement',
companionSuccess: 'companionSuccess', companionSuccess: 'companionSuccess',
companionError: 'companionError', companionError: 'companionError',
createCoursewareUnit: 'courseware-units/create',
}), }),
getTaskMenuItems(task, status, element) { getTaskMenuItems(task, status, element) {
let menuItems = []; let menuItems = [];
...@@ -195,7 +197,7 @@ export default { ...@@ -195,7 +197,7 @@ export default {
}); });
} }
if (task.attributes.submitted) { 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; return menuItems;
...@@ -233,28 +235,43 @@ export default { ...@@ -233,28 +235,43 @@ export default {
}); });
this.currentTask = null; this.currentTask = null;
}, },
async copyContent(element) { async copyContent(taskGroup, element) {
let ownCoursewareInstance = await this.loadRemoteCoursewareStructure({ const unit = {
rangeId: this.userId, attributes: {
rangeType: 'users', 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) { displayFeedback(feedback) {
this.showFeedbackDialog = true; 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