Skip to content

Commit

Permalink
Add right holder to scheme rights, #151
Browse files Browse the repository at this point in the history
  • Loading branch information
njkim committed Dec 20, 2024
1 parent 1becfe3 commit 6685e40
Show file tree
Hide file tree
Showing 8 changed files with 222 additions and 7 deletions.
22 changes: 22 additions & 0 deletions arches_lingo/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@ class Meta:
nodegroups = ["creation"]
fields = "__all__"

class SchemeRightsSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = "scheme"
nodegroups = ["rights"]
fields = "__all__"

class TextualWorkRdmSystemSerializer(ArchesModelSerializer):
class Meta:
Expand All @@ -42,6 +48,22 @@ class Meta:
fields = "__all__"


class GroupRdmSystemSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = "group"
nodegroups = "__all__"
fields = "__all__"


class PersonRdmSystemSerializer(ArchesModelSerializer):
class Meta:
model = ResourceInstance
graph_slug = "person"
nodegroups = "__all__"
fields = "__all__"


class ConceptStatementSerializer(ArchesTileSerializer):
class Meta:
model = TileModel
Expand Down
39 changes: 39 additions & 0 deletions arches_lingo/src/arches_lingo/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,13 +52,34 @@ export const fetchTextualWorkRdmSystemList = async () => {
return parsed;
};

export const fetchPersonRdmSystemList = async () => {
const response = await fetch(arches.urls.api_person_list);
const parsed = await response.json();
if (!response.ok) throw new Error(parsed.message || response.statusText);
return parsed;
};

export const fetchGroupRdmSystemList = async () => {
const response = await fetch(arches.urls.api_group_list);
const parsed = await response.json();
if (!response.ok) throw new Error(parsed.message || response.statusText);
return parsed;
};

export const fetchSchemeCreation = async (schemeId: string) => {
const response = await fetch(arches.urls.api_scheme_creation(schemeId));
const parsed = await response.json();
if (!response.ok) throw new Error(parsed.message || response.statusText);
return parsed;
};

export const fetchSchemeRights = async (schemeId: string) => {
const response = await fetch(arches.urls.api_scheme_rights(schemeId));
const parsed = await response.json();
if (!response.ok) throw new Error(parsed.message || response.statusText);
return parsed;
};

export const updateSchemeCreation = async (
schemeId: string,
schemeInstance: SchemeInstance,
Expand Down Expand Up @@ -93,6 +114,24 @@ export const updateSchemeNamespace = async (
return parsed;
};

export const updateSchemeRights = async (
schemeId: string,
schemeRights: SchemeInstance,
) => {
const response = await fetch(arches.urls.api_scheme_rights(schemeId), {
method: "PATCH",
headers: {
"X-CSRFTOKEN": getToken(),
"Content-Type": "application/json",
},
body: JSON.stringify(schemeRights),
});
const parsed = await response.json();
console.log(parsed);
if (!response.ok) throw new Error(parsed.message || response.statusText);
return parsed;
};

export const fetchSearchResults = async (
searchTerm: string,
items: number,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import TabPanel from "primevue/tabpanel";
import SchemeNamespace from "../report/SchemeNamespace.vue";
import { onBeforeUpdate, onUpdated, ref } from "vue";
import SchemeStandard from "../report/SchemeStandard.vue";
import SchemeLicense from "../report/SchemeLicense.vue";
type sectionTypes = typeof SchemeNamespace;
const { $gettext } = useGettext();
Expand All @@ -30,6 +31,11 @@ const schemeComponents = [
id: "standard",
editorTabName: $gettext("Scheme Standards Followed"),
},
{
component: SchemeLicense,
id: "rights",
editorTabName: $gettext("Scheme Rights"),
},
];
const emit = defineEmits(["maximize", "side", "close", "updated"]);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,124 @@
<script setup lang="ts">
import { inject, onMounted, ref, type Ref } from "vue";
import { useRoute } from "vue-router";
import { useGettext } from "vue3-gettext";
import SchemeReportSection from "@/arches_lingo/components/scheme/report/SchemeSection.vue";
const save = () => {
console.log("save");
import {
fetchSchemeRights,
updateSchemeRights,
fetchPersonRdmSystemList,
fetchGroupRdmSystemList,
} from "@/arches_lingo/api.ts";
import type {
DataComponentMode,
ResourceInstanceReference,
ResourceInstanceResult,
SchemeInstance,
} from "@/arches_lingo/types";
import { selectedLanguageKey, VIEW, EDIT } from "@/arches_lingo/constants.ts";
import ResourceInstanceRelationships from "../../generic/ResourceInstanceRelationships.vue";
import type { Language } from "@/arches_vue_utils/types.ts";
onMounted(async () => {
getSectionValue();
});
defineEmits(["openEditor"]);
defineProps<{
mode?: DataComponentMode;
}>();
const schemeRights = ref<SchemeInstance>();
const route = useRoute();
const actorRdmOptions = ref<ResourceInstanceReference[]>();
const selectedLanguage = inject(selectedLanguageKey) as Ref<Language>;
async function getOptions(): Promise<ResourceInstanceReference[]> {
const options_person = await fetchPersonRdmSystemList();
const options_group = await fetchGroupRdmSystemList();
const options = options_person.concat(options_group);
const results = options.map((option: ResourceInstanceResult) => {
const result: ResourceInstanceReference = {
display_value: option.descriptors[selectedLanguage.value.code].name,
resourceId: option.resourceinstanceid,
ontologyProperty: "ac41d9be-79db-4256-b368-2f4559cfbe55",
inverseOntologyProperty: "ac41d9be-79db-4256-b368-2f4559cfbe55",
};
return result;
});
return results;
};
function onSchemeRightsUpdate(val: string[]) {
const schemeRightsValue = schemeRights.value!;
console.log(schemeRightsValue);
if (actorRdmOptions.value) {
const options = actorRdmOptions.value?.filter((option) =>
val.includes(option.resourceId),
);
if (!schemeRightsValue?.rights) {
schemeRightsValue.rights = {
right_holder: options,
};
} else {
schemeRightsValue.rights.right_holder = options;
}
}
};
const getSectionValue = async () => {
console.log("update");
async function save() {
await updateSchemeRights(
route.params.id as string,
schemeRights.value as SchemeInstance,
);
};
async function getSectionValue() {
const options = !actorRdmOptions.value
? await getOptions()
: actorRdmOptions.value;
const scheme = await fetchSchemeRights(route.params.id as string);
const hydratedResults = options.map((option) => {
const savedSource = scheme.rights?.right_holder.find(
(source: ResourceInstanceReference) =>
source.resourceId === option.resourceId,
);
if (savedSource) {
return savedSource;
} else {
return option;
}
});
actorRdmOptions.value = hydratedResults;
schemeRights.value = scheme;
};
defineExpose({ save, getSectionValue });
const { $gettext } = useGettext();
</script>

<template>
<SchemeReportSection :title-text="$gettext('License')">
abc
</SchemeReportSection>
<div>
<div v-if="!mode || mode === VIEW">
<SchemeReportSection
:title-text="$gettext('Scheme Rights')"
@open-editor="$emit('openEditor')"
>
<h4>{{ $gettext('Rights Holders') }}</h4>
<ResourceInstanceRelationships
:value="schemeRights?.rights?.right_holder"
:mode="VIEW"
/>
</SchemeReportSection>
</div>
<div v-if="mode === EDIT">
<h4>{{ $gettext('Rights Holders') }}</h4>
<ResourceInstanceRelationships
:value="schemeRights?.rights?.right_holder"
:options="actorRdmOptions"
:mode="EDIT"
@update="onSchemeRightsUpdate"
/>
</div>
</div>
</template>
3 changes: 3 additions & 0 deletions arches_lingo/src/arches_lingo/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ export interface SchemeInstance {
creation?: {
creation_sources: ResourceInstanceReference[];
};
rights?: {
right_holder: ResourceInstanceReference[];
};
}

export interface SchemeResource {
Expand Down
3 changes: 3 additions & 0 deletions arches_lingo/templates/arches_urls.htm
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,8 @@
api_schemes="{% url 'schemes-list-create' %}"
api_scheme_creation='(pluginid)=>{return "{% url "api-scheme-creation" "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" %}".replace("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", pluginid)}'
api_textualwork_list="{% url 'api-textualwork-list' %}"
api_person_list="{% url 'api-person-list' %}"
api_group_list="{% url 'api-group-list' %}"
api_scheme_rights='(pluginid)=>{return "{% url "api-scheme-rights" "aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" %}".replace("aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa", pluginid)}'
></div>
{% endblock arches_urls %}
18 changes: 18 additions & 0 deletions arches_lingo/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,15 @@
ConceptStatementDetailView,
ConceptStatementListCreateView,
SchemeCreationView,
SchemeRightsView,
SchemeDetailView,
SchemeListCreateView,
SchemeNamespaceView,
SchemeStatementDetailView,
SchemeStatementListCreateView,
TextualWorkRdmSystemSerializerView,
PersonRdmSystemSerializerView,
GroupRdmSystemSerializerView,
)

urlpatterns = [
Expand Down Expand Up @@ -53,11 +56,26 @@
SchemeCreationView.as_view(),
name="api-scheme-creation",
),
path(
"api/scheme/<uuid:pk>/scheme-rights",
SchemeRightsView.as_view(),
name="api-scheme-rights",
),
path(
"api/textual-work",
TextualWorkRdmSystemSerializerView.as_view(),
name="api-textualwork-list",
),
path(
"api/person",
PersonRdmSystemSerializerView.as_view(),
name="api-person-list",
),
path(
"api/group",
GroupRdmSystemSerializerView.as_view(),
name="api-group-list",
),
path(
"api/scheme/statements",
SchemeStatementListCreateView.as_view(),
Expand Down
19 changes: 19 additions & 0 deletions arches_lingo/views/api/pythonic_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,12 @@
SchemeCreationSerializer,
SchemeNamespaceSerializer,
SchemeSerializer,
SchemeRightsSerializer,
ConceptStatementSerializer,
SchemeStatementSerializer,
TextualWorkRdmSystemSerializer,
GroupRdmSystemSerializer,
PersonRdmSystemSerializer,
)


Expand Down Expand Up @@ -54,11 +57,27 @@ class SchemeCreationView(ArchesModelAPIMixin, RetrieveUpdateDestroyAPIView):
serializer_class = SchemeCreationSerializer


class SchemeRightsView(ArchesModelAPIMixin, RetrieveUpdateDestroyAPIView):
permission_classes = [RDMAdministrator]
serializer_class = SchemeRightsSerializer


class TextualWorkRdmSystemSerializerView(ArchesModelAPIMixin, ListAPIView):
permission_classes = [RDMAdministrator]
serializer_class = TextualWorkRdmSystemSerializer
pagination_class = None

class GroupRdmSystemSerializerView(ArchesModelAPIMixin, ListAPIView):
permission_classes = [RDMAdministrator]
serializer_class = GroupRdmSystemSerializer
pagination_class = None


class PersonRdmSystemSerializerView(ArchesModelAPIMixin, ListAPIView):
permission_classes = [RDMAdministrator]
serializer_class = PersonRdmSystemSerializer
pagination_class = None


class ConceptDetailView(ArchesModelAPIMixin, RetrieveUpdateDestroyAPIView):
permission_classes = [RDMAdministrator]
Expand Down

0 comments on commit 6685e40

Please sign in to comment.