Skip to content

Commit

Permalink
SAK-50440 Rubrics remove sharing of public rubrics from other sites (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Aniii10 authored Oct 14, 2024
1 parent 8de22b0 commit 96f2dba
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 7 deletions.
1 change: 1 addition & 0 deletions rubrics/api/src/main/bundle/rubrics.properties
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ save=Save
done=Done
total=Total
confirm_remove=Are you sure you want to remove "{}" ?
confirm_remove_shared=Are you sure you want to remove "{}" both from shared rubrics and from its source site?
is_locked=is locked: Only titles, descriptions and criterion order can be modified
locked_warning=Rubric in use. Editable content will be updated on all previously associated items.
points=Points
Expand Down
2 changes: 1 addition & 1 deletion rubrics/api/src/main/bundle/rubrics_ca.properties
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ save=Desa
done=Fet
total=Total
confirm_remove=Esteu segur de voler-ho eliminar
is_locked=est\u00e0 bloquejada\: Nom\u00e9s es poden modificar els t\u00edtols, les descripcions i l\u2019ordre dels criteris
confirm_remove_shared=Esteu segur que voleu eliminar "{}" tant de les r\u00fabriques compartides p\u00fablicament com del seu origen del lloc?is_locked=est\u00e0 bloquejada\: Nom\u00e9s es poden modificar els t\u00edtols, les descripcions i l\u2019ordre dels criteris
locked_warning=La r\u00fabrica s\u2019est\u00e0 usant. El contingut editable s\u2019actualitzar\u00e0 a tots els elements pr\u00e8viament associats.
points=Punts
weight=Pes
Expand Down
2 changes: 1 addition & 1 deletion rubrics/api/src/main/bundle/rubrics_es.properties
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ save=Guardar
done=Aceptar
total=Total
confirm_remove=\u00bfEst\u00e1s seguro de que deseas borrar "{}"?
is_locked=bloqueada\: Solo los t\u00edtulos, descripciones y el orden de los criterios pueden ser modificados
confirm_remove_shared=\u00bfEst\u00e1s seguro de que deseas borrar "{}", tanto de las r\u00fabricas compartidas p\u00fablicamente como del sitio de origen?is_locked=bloqueada\: Solo los t\u00edtulos, descripciones y el orden de los criterios pueden ser modificados
locked_warning=R\u00fabrica en uso. El contenido editable se actualizar\u00e1 en todos los elementos asociados previamente.
points=Puntos
weight=Peso
Expand Down
2 changes: 1 addition & 1 deletion rubrics/api/src/main/bundle/rubrics_eu.properties
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ save=Gorde
done=Egina
total=Guztira
confirm_remove=Ziur zaude kendu egin nahi duzula?
is_locked=blokeatuta dago\: tituluak, deskripzioak eta irizpideen ordena bakarrik alda daitezke
confirm_remove_shared=Ziur "{}" publikoki partekatutako errubriketatik eta webgunearen jatorritik kendu nahi duzula?is_locked=blokeatuta dago\: tituluak, deskripzioak eta irizpideen ordena bakarrik alda daitezke
locked_warning=Erabiltzen ari den errubrika. Eduki editagarria aldez aurretik lotutako item guztietan eguneratuko da.
points=Puntuak
weight=Haztapena
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public String index(ModelMap model) {
model.addAttribute("siteId", siteId);
model.addAttribute("sakaiSessionId", sessionManager.getCurrentSession().getId());
model.addAttribute("cdnQuery", PortalUtils.getCDNQuery());
model.addAttribute("isSuperUser", securityService.isSuperUser());

String currentUserId = sessionManager.getCurrentSessionUserId();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
<script th:inline="javascript">
var sakaiSessionId = /*[[${sakaiSessionId}]]*/ null;
</script>
<sakai-rubrics-manager th:attr="site-id=${siteId}, enable-pdf-export=${enablePdfExport}"></sakai-rubrics-manager>
<sakai-rubrics-manager th:attr="site-id=${siteId}, enable-pdf-export=${enablePdfExport} ? 'true' : null, is-super-user=${isSuperUser} ? 'true' : null"></sakai-rubrics-manager>
</div>
</body>
</html>
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package org.sakaiproject.webapi.controllers;

import lombok.extern.slf4j.Slf4j;
import org.sakaiproject.authz.api.SecurityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

@RestController
@Slf4j
public class UserController extends AbstractSakaiApiController{

@Autowired
private SecurityService securityService;

@GetMapping("/user/roles")
public ResponseEntity<Map<String, Boolean>> checkSuperUser() {

return ResponseEntity.ok()
.contentType(MediaType.APPLICATION_JSON)
.body(Map.of("isSuperUser", securityService.isSuperUser()));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ export class SakaiRubricReadonly extends SakaiRubric {
static properties = {

rubric: { type: Object },
isSuperUser: { attribute: "is-super-user", type: Boolean },
enablePdfExport: { attribute: "enable-pdf-export", type: Boolean },
};

constructor() {

super();

this.enablePdfExport = false;
}

Expand Down Expand Up @@ -54,6 +54,12 @@ export class SakaiRubricReadonly extends SakaiRubric {
<div class="d-none d-sm-block">${this.rubric.formattedModifiedDate}</div>
<div class="actions">
${this.isSuperUser ? html`
<div class="action-container">
<span class="d-none d-sm-none d-md-block visually-hidden">${this._i18n.delete_rubric}</span>
<span role="button" title="${this._i18n.revoke.replace("{}", this.rubric.title)}" tabindex="0" class="fa fa-users" @click="${this.revokeShareRubric}"></span>
</div>
` : ""}
<div class="action-container">
<span class="d-none d-sm-none d-md-block visually-hidden">${this._i18n.copy}</span>
<span role="button" title="${this._i18n.copy_to_site.replace("{}", this.rubric.title)}" tabindex="0" class="clone fa fa-copy" @click="${this.copyToSite}"></span>
Expand All @@ -67,6 +73,12 @@ export class SakaiRubricReadonly extends SakaiRubric {
</sakai-rubric-pdf>
</div>
` : ""}
${this.isSuperUser ? html`
<div class="action-container">
<span class="d-none d-sm-none d-md-block visually-hidden">${this._i18n.delete_rubric}</span>
<span role="button" title="${this._i18n.remove.replace("{}", this.rubric.title)}" tabindex="0" class="fa fa-times" @click="${this.deleteRubric}"></span>
</div>
` : ""}
</div>
</div>
Expand All @@ -83,4 +95,16 @@ export class SakaiRubricReadonly extends SakaiRubric {
e.stopPropagation();
this.dispatchEvent(new CustomEvent("copy-to-site", { detail: this.rubric.id }));
}

deleteRubric(e) {

e.stopPropagation();
this.dispatchEvent(new CustomEvent("delete-rubric", { detail: { id: this.rubric.id, title: this.rubric.title }, bubbles: true, composed: true, }));
}

revokeShareRubric(e) {

e.stopPropagation();
this.dispatchEvent(new CustomEvent("revoke-shared-rubric", { detail: { id: this.rubric.id, title: this.rubric.title, shared: this.rubric.shared }, bubbles: true, composed: true, }));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export class SakaiRubricsManager extends RubricsElement {

siteId: { attribute: "site-id", type: String },
enablePdfExport: { attribute: "enable-pdf-export", type: Boolean },
isSuperUser: { attribute: "is-super-user", type: Boolean },
};

constructor() {
Expand All @@ -19,6 +20,7 @@ export class SakaiRubricsManager extends RubricsElement {
this.siteRubricsExpanded = "true";
this.sharedRubricsExpanded = "false";
this.enablePdfExport = false;
this.isSuperUser = false;
}

firstUpdated() {
Expand Down Expand Up @@ -172,7 +174,7 @@ export class SakaiRubricsManager extends RubricsElement {
<div class="actions">${this.tr("actions")}</div>
</div>
<br>
<sakai-rubrics-shared-list id="sakai-rubrics-shared-list" site-id="${this.siteId}" @copy-share-site="${this.copyShareSite}" ?enable-pdf-export=${this.enablePdfExport}></sakai-rubrics-shared-list>
<sakai-rubrics-shared-list id="sakai-rubrics-shared-list" site-id="${this.siteId}" @copy-share-site="${this.copyShareSite}" @update-rubric-list="${this.handleRubricList}" ?enable-pdf-export=${this.enablePdfExport} ?is-super-user=${this.isSuperUser}></sakai-rubrics-shared-list>
</div>
<br>
</div>
Expand All @@ -181,10 +183,17 @@ export class SakaiRubricsManager extends RubricsElement {
}

handleSharingChange() {

document.getElementById("sakai-rubrics-shared-list").refresh();
}

copyShareSite() {

this.querySelector("sakai-rubrics-list").refresh();
}

handleRubricList() {

this.querySelector("sakai-rubrics-list").refresh();
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { html } from "lit";
import "../sakai-rubric-readonly.js";
import "../sakai-rubrics-list.js";
import { SakaiRubricsHelpers } from "./SakaiRubricsHelpers.js";
import { SakaiRubricsList } from "./SakaiRubricsList.js";
import { SharingChangeEvent } from "./SharingChangeEvent.js";

const rubricName = "name";
const rubricTitle = "title";
Expand All @@ -10,10 +12,13 @@ const rubricModified = "modified";

export class SakaiRubricsSharedList extends SakaiRubricsList {

rubricIdToDelete = null;
rubricTitleToDelete = null;
static properties = {

siteId: { attribute: "site-id", type: String },
enablePdfExport: { attribute: "enable-pdf-export", type: Boolean },
isSuperUser: { attribute: "is-super-user", type: Boolean },

_rubrics: { state: true },
};
Expand All @@ -22,6 +27,11 @@ export class SakaiRubricsSharedList extends SakaiRubricsList {

super();

this.updateRubricOptions = {
method: "PATCH",
credentials: "include",
headers: { "Content-Type": "application/json-patch+json" },
};
this.getSharedRubrics();
}

Expand All @@ -34,13 +44,37 @@ export class SakaiRubricsSharedList extends SakaiRubricsList {
return html`
<div role="tablist">
${this._rubrics.map(r => html`
<sakai-rubric-readonly .rubric=${r} @copy-to-site=${this.copyToSite} ?enablePdfExport=${this.enablePdfExport}></sakai-rubric-readonly>
<sakai-rubric-readonly .rubric=${r}
@copy-to-site=${this.copyToSite}
@delete-rubric=${this.showDeleteModal}
@revoke-shared-rubric=${this.sharingChange}
?enablePdfExport=${this.enablePdfExport}
?is-super-user=${this.isSuperUser}>
</sakai-rubric-readonly>
`)}
</div>
<div class="modal fade" id="delete-modal" tabindex="-1" aria-labelledby="delete-modal-label" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="delete-modal-label">${this._i18n.delete_item_title.replace("{}", this.rubricTitleToDelete || "")}</h5>
<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<p>${this._i18n.confirm_remove_shared.replace("{}", this.rubricTitleToDelete || "")}</p>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-danger" @click="${this.confirmDelete}">${this._i18n.remove_label}</button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">${this._i18n.cancel}</button>
</div>
</div>
</div>
</div>
`;
}

refresh() {

this.getSharedRubrics();
}

Expand All @@ -59,12 +93,63 @@ export class SakaiRubricsSharedList extends SakaiRubricsList {
.catch (error => console.error(error));
}

showDeleteModal(e) {

e.stopPropagation();
this.rubricIdToDelete = e.detail.id;
this.rubricTitleToDelete = e.detail.title;
this.requestUpdate();
const modal = new bootstrap.Modal(document.getElementById("delete-modal"));
modal.show();
}

copyToSite(e) {

SakaiRubricsHelpers.get(`/api/sites/${this.siteId}/rubrics/${e.detail}/copyToSite`, {})
.then(() => this.dispatchEvent(new CustomEvent("copy-share-site")));
}

confirmDelete(e) {

e.stopPropagation();
const url = `/api/sites/${this.siteId}/rubrics/${this.rubricIdToDelete}`;
fetch(url, {
method: "DELETE",
credentials: "include",
headers: { "Content-Type": "application/json" }
})
.then(r => {
if (!r.ok) {
throw new Error(`Failed to delete shared rubric with id ${this.rubricIdToDelete}`);
}
this._rubrics = this._rubrics.filter(rubric => rubric.id !== this.rubricIdToDelete);
this.requestUpdate();
bootstrap.Modal.getOrCreateInstance(this.querySelector(".modal")).hide();
this.dispatchEvent(new CustomEvent("update-rubric-list")); })
.catch(error => console.error(error));
}

sharingChange(e) {

e.stopPropagation();
e.detail.shared = !e.detail.shared;

this.updateRubricOptions.body = JSON.stringify([ { "op": "replace", "path": "/shared", "value": e.detail.shared } ]);
const url = `/api/sites/${e.detail.ownerId}/rubrics/${e.detail.id}`;
fetch(url, this.updateRubricOptions)
.then(r => {

if (r.ok) {
this.dispatchEvent(new SharingChangeEvent());
this.refresh();
this.dispatchEvent(new CustomEvent("update-rubric-list"));
} else {
throw new Error("Network error while updating rubric");
}
})
.catch (error => console.error(error));
}

sortRubrics(rubricType, ascending) {

switch (rubricType) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ save=Save
done=Done
total=Total
confirm_remove=Are you sure you want to remove
confirm_remove_shared=Are you sure you want to remove {} both from shared rubrics and from its source site?
is_locked=is locked: Only titles, descriptions and criterion order can be modified
locked_warning=Rubric in use. Editable content will be updated on all previously associated items.
points=Points
Expand Down

0 comments on commit 96f2dba

Please sign in to comment.