@ndla/ui 13.2.0 → 14.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/es/Footer/FooterAuth.js +15 -22
- package/es/LearningPaths/LearningPathMenu.js +3 -4
- package/es/Masthead/MastheadAuthModal.js +2 -2
- package/es/Notion/ConceptNotion.js +2 -1
- package/es/Notion/FigureNotion.js +14 -10
- package/es/Notion/NotionVisualElement.js +3 -2
- package/es/ResourceGroup/ResourceItem.js +14 -17
- package/es/Search/ActiveFilters.js +6 -7
- package/es/Search/ContentTypeResult.js +6 -8
- package/es/SearchTypeResult/ActiveFilters.js +6 -10
- package/es/SearchTypeResult/SearchViewType.js +5 -5
- package/es/TopicIntroductionList/TopicIntroduction.js +2 -4
- package/es/TopicIntroductionList/TopicShortcutItem.js +1 -3
- package/es/User/AuthModal.js +15 -24
- package/es/User/UserInfo.js +70 -0
- package/es/User/apiTypes.js +0 -0
- package/es/User/index.js +2 -0
- package/es/User/parseUserObject.js +102 -0
- package/es/all.css +18 -0
- package/es/index.js +1 -0
- package/es/locale/messages-en.js +13 -4
- package/es/locale/messages-nb.js +13 -4
- package/es/locale/messages-nn.js +13 -4
- package/es/locale/messages-se.js +13 -4
- package/es/locale/messages-sma.js +13 -4
- package/lib/Footer/FooterAuth.d.ts +1 -1
- package/lib/Footer/FooterAuth.js +17 -17
- package/lib/LearningPaths/LearningPathMenu.js +3 -4
- package/lib/Masthead/MastheadAuthModal.d.ts +3 -3
- package/lib/Masthead/MastheadAuthModal.js +3 -3
- package/lib/Notion/ConceptNotion.js +2 -1
- package/lib/Notion/FigureNotion.d.ts +1 -1
- package/lib/Notion/FigureNotion.js +13 -9
- package/lib/Notion/NotionVisualElement.js +3 -2
- package/lib/ResourceGroup/ResourceItem.js +14 -17
- package/lib/Search/ActiveFilters.js +6 -7
- package/lib/Search/ContentTypeResult.js +6 -8
- package/lib/SearchTypeResult/ActiveFilters.js +6 -10
- package/lib/SearchTypeResult/SearchViewType.js +5 -5
- package/lib/TopicIntroductionList/TopicIntroduction.js +2 -4
- package/lib/TopicIntroductionList/TopicShortcutItem.js +1 -3
- package/lib/User/AuthModal.d.ts +3 -3
- package/lib/User/AuthModal.js +16 -23
- package/lib/User/UserInfo.d.ts +13 -0
- package/lib/User/UserInfo.js +84 -0
- package/lib/User/apiTypes.d.ts +61 -0
- package/lib/User/apiTypes.js +1 -0
- package/lib/User/index.d.ts +4 -0
- package/lib/User/index.js +8 -0
- package/lib/User/parseUserObject.d.ts +32 -0
- package/lib/User/parseUserObject.js +105 -0
- package/lib/all.css +18 -0
- package/lib/index.d.ts +2 -0
- package/lib/index.js +8 -1
- package/lib/locale/messages-en.d.ts +9 -0
- package/lib/locale/messages-en.js +13 -4
- package/lib/locale/messages-nb.d.ts +9 -0
- package/lib/locale/messages-nb.js +13 -4
- package/lib/locale/messages-nn.d.ts +9 -0
- package/lib/locale/messages-nn.js +13 -4
- package/lib/locale/messages-se.d.ts +9 -0
- package/lib/locale/messages-se.js +13 -4
- package/lib/locale/messages-sma.d.ts +9 -0
- package/lib/locale/messages-sma.js +13 -4
- package/package.json +5 -5
- package/src/Footer/FooterAuth.tsx +7 -9
- package/src/LearningPaths/LearningPathMenu.tsx +1 -1
- package/src/Masthead/MastheadAuthModal.tsx +4 -5
- package/src/Notion/ConceptNotion.tsx +1 -0
- package/src/Notion/FigureNotion.tsx +13 -6
- package/src/Notion/NotionVisualElement.tsx +1 -1
- package/src/ResourceGroup/ResourceItem.tsx +3 -3
- package/src/Search/ActiveFilters.jsx +0 -1
- package/src/Search/ContentTypeResult.tsx +8 -9
- package/src/SearchTypeResult/ActiveFilters.tsx +1 -3
- package/src/SearchTypeResult/SearchViewType.tsx +1 -1
- package/src/TopicIntroductionList/TopicIntroduction.tsx +2 -2
- package/src/TopicIntroductionList/TopicShortcutItem.tsx +1 -5
- package/src/User/AuthModal.tsx +5 -26
- package/src/User/UserInfo.tsx +80 -0
- package/src/User/__tests__/parseUserObject-test.ts +315 -0
- package/src/User/apiTypes.ts +74 -0
- package/src/User/index.ts +4 -0
- package/src/User/parseUserObject.ts +83 -0
- package/src/all.scss +1 -0
- package/src/index.ts +2 -0
- package/src/locale/messages-en.ts +13 -4
- package/src/locale/messages-nb.ts +13 -4
- package/src/locale/messages-nn.ts +13 -4
- package/src/locale/messages-se.ts +13 -4
- package/src/locale/messages-sma.ts +13 -4
package/src/User/AuthModal.tsx
CHANGED
|
@@ -13,6 +13,8 @@ import Modal, { ModalCloseButton } from '@ndla/modal';
|
|
|
13
13
|
import Button from '@ndla/button';
|
|
14
14
|
import { FeideText, LogIn, LogOut, HumanMaleBoard } from '@ndla/icons/common';
|
|
15
15
|
import { fonts, spacing } from '@ndla/core';
|
|
16
|
+
import { UserInfo } from './UserInfo';
|
|
17
|
+
import { FeideUserApiType } from './apiTypes';
|
|
16
18
|
|
|
17
19
|
const StyledModalBody = styled.div`
|
|
18
20
|
padding: ${spacing.normal} ${spacing.medium} ${spacing.medium};
|
|
@@ -38,17 +40,6 @@ const StyledHeading = styled.h2`
|
|
|
38
40
|
}
|
|
39
41
|
`;
|
|
40
42
|
|
|
41
|
-
const StyledAuthorizedInfoList = styled.ul`
|
|
42
|
-
margin: 0;
|
|
43
|
-
padding: 0 0 0 ${spacing.normal};
|
|
44
|
-
list-style-image: unset;
|
|
45
|
-
|
|
46
|
-
li {
|
|
47
|
-
margin: 0;
|
|
48
|
-
font-weight: ${fonts.weight.semibold};
|
|
49
|
-
}
|
|
50
|
-
`;
|
|
51
|
-
|
|
52
43
|
const StyledHumanMaleBoardIconWrapper = styled.span`
|
|
53
44
|
margin-left: ${spacing.xsmall};
|
|
54
45
|
`;
|
|
@@ -63,9 +54,8 @@ const StyledButtonWrapper = styled.div`
|
|
|
63
54
|
|
|
64
55
|
export type AuthModalProps = {
|
|
65
56
|
isAuthenticated?: boolean;
|
|
57
|
+
user?: FeideUserApiType;
|
|
66
58
|
showGeneralMessage?: boolean;
|
|
67
|
-
authorizedRole?: string;
|
|
68
|
-
authorizedCollectedInfo?: string[];
|
|
69
59
|
onAuthenticateClick: () => void;
|
|
70
60
|
position?: 'top' | 'bottom';
|
|
71
61
|
activateButton?: ReactElement;
|
|
@@ -76,9 +66,8 @@ export type AuthModalProps = {
|
|
|
76
66
|
|
|
77
67
|
const AuthModal = ({
|
|
78
68
|
isAuthenticated,
|
|
69
|
+
user,
|
|
79
70
|
showGeneralMessage = true,
|
|
80
|
-
authorizedRole,
|
|
81
|
-
authorizedCollectedInfo,
|
|
82
71
|
onAuthenticateClick,
|
|
83
72
|
position = 'top',
|
|
84
73
|
activateButton,
|
|
@@ -104,17 +93,7 @@ const AuthModal = ({
|
|
|
104
93
|
<ModalCloseButton onClick={onClose} title="Lukk" />
|
|
105
94
|
</StyledModalHeader>
|
|
106
95
|
<StyledModalContent>
|
|
107
|
-
{
|
|
108
|
-
{authorizedCollectedInfo && authorizedCollectedInfo.length > 0 && (
|
|
109
|
-
<div>
|
|
110
|
-
{t('user.modal.collectedInfo')}
|
|
111
|
-
<StyledAuthorizedInfoList>
|
|
112
|
-
{authorizedCollectedInfo.map((value) => (
|
|
113
|
-
<li key={value}>{value}</li>
|
|
114
|
-
))}
|
|
115
|
-
</StyledAuthorizedInfoList>
|
|
116
|
-
</div>
|
|
117
|
-
)}
|
|
96
|
+
{user && <UserInfo user={user} />}
|
|
118
97
|
{children}
|
|
119
98
|
{showGeneralMessage && (
|
|
120
99
|
<p>
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2022-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import styled from '@emotion/styled';
|
|
9
|
+
import { spacing } from '@ndla/core';
|
|
10
|
+
import React from 'react';
|
|
11
|
+
import { useTranslation } from 'react-i18next';
|
|
12
|
+
import { FeideUserApiType } from './apiTypes';
|
|
13
|
+
import { parseUserObject } from './parseUserObject';
|
|
14
|
+
|
|
15
|
+
const InfoList = styled.ul`
|
|
16
|
+
padding: 0 0 0 ${spacing.normal};
|
|
17
|
+
`;
|
|
18
|
+
|
|
19
|
+
interface Props {
|
|
20
|
+
user: FeideUserApiType;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const ShortInfoDiv = styled.div`
|
|
24
|
+
margin: 2rem auto;
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
export const UserInfo = ({ user }: Props) => {
|
|
28
|
+
const { t } = useTranslation();
|
|
29
|
+
|
|
30
|
+
const parsedUser = parseUserObject(user);
|
|
31
|
+
|
|
32
|
+
return (
|
|
33
|
+
<div>
|
|
34
|
+
{
|
|
35
|
+
<p>
|
|
36
|
+
{t('user.loggedInAs', {
|
|
37
|
+
role: t(`user.role.${parsedUser.primaryAffiliation}`),
|
|
38
|
+
})}
|
|
39
|
+
</p>
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
<ShortInfoDiv>
|
|
43
|
+
<div>
|
|
44
|
+
{t('user.username')}: <b>{user.uid}</b>
|
|
45
|
+
</div>
|
|
46
|
+
<div>
|
|
47
|
+
{t('user.name')}: <b>{user.displayName}</b>
|
|
48
|
+
</div>
|
|
49
|
+
<div>
|
|
50
|
+
{t('user.mail')}: <b>{user.mail?.join(', ')}</b>
|
|
51
|
+
</div>
|
|
52
|
+
</ShortInfoDiv>
|
|
53
|
+
|
|
54
|
+
{t('user.modal.collectedInfo')}
|
|
55
|
+
|
|
56
|
+
<InfoList>
|
|
57
|
+
{parsedUser.organizations.map((org) => (
|
|
58
|
+
<li key={org.id}>
|
|
59
|
+
{`${org.displayName}${org.membership.primarySchool ? ` (${t('user.primarySchool')})` : ''}`}
|
|
60
|
+
<InfoList>
|
|
61
|
+
{Object.entries(org.children).map(([groupType, val]) => {
|
|
62
|
+
if (val.length < 1) return null;
|
|
63
|
+
return (
|
|
64
|
+
<li key={groupType}>
|
|
65
|
+
{t(`user.groupTypes.${groupType}`)}
|
|
66
|
+
<InfoList>
|
|
67
|
+
{val.map((group) => (
|
|
68
|
+
<li key={group.id}>{`${group.displayName}${group.grep ? ` (${group.grep.code})` : ''}`}</li>
|
|
69
|
+
))}
|
|
70
|
+
</InfoList>
|
|
71
|
+
</li>
|
|
72
|
+
);
|
|
73
|
+
})}
|
|
74
|
+
</InfoList>
|
|
75
|
+
</li>
|
|
76
|
+
))}
|
|
77
|
+
</InfoList>
|
|
78
|
+
</div>
|
|
79
|
+
);
|
|
80
|
+
};
|
|
@@ -0,0 +1,315 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2022-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { FeideUserApiType } from '../apiTypes';
|
|
10
|
+
import { parseUserObject } from '../parseUserObject';
|
|
11
|
+
|
|
12
|
+
const feideUserLaerer: FeideUserApiType = {
|
|
13
|
+
cn: ['David LærerVGS Jonsen'],
|
|
14
|
+
displayName: 'David LærerVGS Jonsen',
|
|
15
|
+
eduPersonAffiliation: ['member', 'employee', 'faculty'],
|
|
16
|
+
eduPersonPrimaryAffiliation: 'employee',
|
|
17
|
+
eduPersonPrincipalName: 'david_laerervgs@spusers.feide.no',
|
|
18
|
+
givenName: ['David LærerVGS'],
|
|
19
|
+
mail: ['david_laerervgs@feide.no'],
|
|
20
|
+
sn: ['Jonsen'],
|
|
21
|
+
uid: ['david_laerervgs'],
|
|
22
|
+
groups: [
|
|
23
|
+
{
|
|
24
|
+
id: 'fc:org:spusers.feide.no',
|
|
25
|
+
displayName: 'Rogn fylkeskommune',
|
|
26
|
+
type: 'fc:org',
|
|
27
|
+
public: false,
|
|
28
|
+
membership: {
|
|
29
|
+
basic: 'admin',
|
|
30
|
+
affiliation: ['member', 'employee', 'faculty'],
|
|
31
|
+
primaryAffiliation: 'employee',
|
|
32
|
+
displayName: 'Akademisk ansatt',
|
|
33
|
+
},
|
|
34
|
+
orgType: ['higher_education', 'upper_secondary_owner', 'primary_and_lower_secondary_owner'],
|
|
35
|
+
norEduOrgNIN: 'NO956326503',
|
|
36
|
+
eduOrgLegalName: 'Rogn fylkeskommune',
|
|
37
|
+
mail: 'support@feide.no',
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
id: 'fc:org:spusers.feide.no:unit:NO956326504',
|
|
41
|
+
parent: 'fc:org:spusers.feide.no',
|
|
42
|
+
displayName: 'Lind VGS',
|
|
43
|
+
type: 'fc:org',
|
|
44
|
+
public: false,
|
|
45
|
+
membership: {
|
|
46
|
+
basic: 'member',
|
|
47
|
+
primarySchool: true,
|
|
48
|
+
},
|
|
49
|
+
orgType: ['primary_and_lower_secondary'],
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: 'fc:org:spusers.feide.no:unit:NO856326501',
|
|
53
|
+
parent: 'fc:org:spusers.feide.no',
|
|
54
|
+
displayName: 'Lerk VGS',
|
|
55
|
+
type: 'fc:org',
|
|
56
|
+
public: false,
|
|
57
|
+
membership: {
|
|
58
|
+
basic: 'member',
|
|
59
|
+
primarySchool: false,
|
|
60
|
+
},
|
|
61
|
+
orgType: ['primary_and_lower_secondary'],
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: 'fc:gogroup:spusers.feide.no:b:NO856326501:1sta:2000-07-01:2100-06-30',
|
|
65
|
+
displayName: 'Klasse 1STA',
|
|
66
|
+
type: 'fc:gogroup',
|
|
67
|
+
notBefore: '2000-06-30T22:00:00Z',
|
|
68
|
+
notAfter: '2100-06-30T23:00:00Z',
|
|
69
|
+
go_type: 'b',
|
|
70
|
+
parent: 'fc:org:spusers.feide.no:unit:NO856326501',
|
|
71
|
+
membership: {
|
|
72
|
+
basic: 'member',
|
|
73
|
+
affiliation: 'employee',
|
|
74
|
+
displayName: 'Ansatt',
|
|
75
|
+
},
|
|
76
|
+
go_type_displayName: 'basisgruppe',
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: 'fc:gogroup:spusers.feide.no:a:NO856326501:1sta-lab1:2000-07-01:2100-06-30',
|
|
80
|
+
displayName: 'Laboratoriegruppe 1',
|
|
81
|
+
type: 'fc:gogroup',
|
|
82
|
+
notBefore: '2000-06-30T22:00:00Z',
|
|
83
|
+
notAfter: '2100-06-30T23:00:00Z',
|
|
84
|
+
go_type: 'a',
|
|
85
|
+
parent: 'fc:org:spusers.feide.no:unit:NO856326501',
|
|
86
|
+
membership: {
|
|
87
|
+
basic: 'member',
|
|
88
|
+
affiliation: 'employee',
|
|
89
|
+
displayName: 'Ansatt',
|
|
90
|
+
},
|
|
91
|
+
go_type_displayName: 'other groups',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
id: 'fc:gogroup:spusers.feide.no:a:NO856326501:1sta-lab2:2000-07-01:2100-06-30',
|
|
95
|
+
displayName: 'Laboratoriegruppe 2',
|
|
96
|
+
type: 'fc:gogroup',
|
|
97
|
+
notBefore: '2000-06-30T22:00:00Z',
|
|
98
|
+
notAfter: '2100-06-30T23:00:00Z',
|
|
99
|
+
go_type: 'a',
|
|
100
|
+
parent: 'fc:org:spusers.feide.no:unit:NO856326501',
|
|
101
|
+
membership: {
|
|
102
|
+
basic: 'member',
|
|
103
|
+
affiliation: 'employee',
|
|
104
|
+
displayName: 'Ansatt',
|
|
105
|
+
},
|
|
106
|
+
go_type_displayName: 'other groups',
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: 'fc:gogroup:spusers.feide.no:u:NO856326501:1mat11-1map1:2000-07-01:2100-06-30',
|
|
110
|
+
displayName: 'Matematikk 1P',
|
|
111
|
+
type: 'fc:gogroup',
|
|
112
|
+
notBefore: '2000-06-30T22:00:00Z',
|
|
113
|
+
notAfter: '2100-06-30T23:00:00Z',
|
|
114
|
+
go_type: 'u',
|
|
115
|
+
parent: 'fc:org:spusers.feide.no:unit:NO856326501',
|
|
116
|
+
membership: {
|
|
117
|
+
basic: 'member',
|
|
118
|
+
affiliation: 'employee',
|
|
119
|
+
displayName: 'Ansatt',
|
|
120
|
+
},
|
|
121
|
+
go_type_displayName: 'undervisningsgruppe',
|
|
122
|
+
grep: {
|
|
123
|
+
displayName: 'Mathematics 1P',
|
|
124
|
+
code: 'MAT1011',
|
|
125
|
+
},
|
|
126
|
+
},
|
|
127
|
+
{
|
|
128
|
+
id: 'fc:gogroup:spusers.feide.no:u:NO856326501:1mat13-1mat1:2000-07-01:2100-06-30',
|
|
129
|
+
displayName: 'Matematikk 1T',
|
|
130
|
+
type: 'fc:gogroup',
|
|
131
|
+
notBefore: '2000-06-30T22:00:00Z',
|
|
132
|
+
notAfter: '2100-06-30T23:00:00Z',
|
|
133
|
+
go_type: 'u',
|
|
134
|
+
parent: 'fc:org:spusers.feide.no:unit:NO856326501',
|
|
135
|
+
membership: {
|
|
136
|
+
basic: 'member',
|
|
137
|
+
affiliation: 'employee',
|
|
138
|
+
displayName: 'Ansatt',
|
|
139
|
+
},
|
|
140
|
+
go_type_displayName: 'undervisningsgruppe',
|
|
141
|
+
grep: {
|
|
142
|
+
displayName: 'Mathematics 1T',
|
|
143
|
+
code: 'MAT1013',
|
|
144
|
+
},
|
|
145
|
+
},
|
|
146
|
+
],
|
|
147
|
+
primarySchool: {
|
|
148
|
+
id: 'fc:org:spusers.feide.no:unit:NO956326504',
|
|
149
|
+
parent: 'fc:org:spusers.feide.no',
|
|
150
|
+
displayName: 'Lind VGS',
|
|
151
|
+
type: 'fc:org',
|
|
152
|
+
public: false,
|
|
153
|
+
membership: {
|
|
154
|
+
basic: 'member',
|
|
155
|
+
primarySchool: true,
|
|
156
|
+
},
|
|
157
|
+
orgType: ['primary_and_lower_secondary'],
|
|
158
|
+
},
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
describe('parseUserObject', () => {
|
|
162
|
+
it('Correctly parses Feide user', () => {
|
|
163
|
+
const expected = {
|
|
164
|
+
uid: ['david_laerervgs'],
|
|
165
|
+
primaryAffiliation: 'employee',
|
|
166
|
+
displayName: 'David LærerVGS Jonsen',
|
|
167
|
+
mail: ['david_laerervgs@feide.no'],
|
|
168
|
+
organizations: [
|
|
169
|
+
{
|
|
170
|
+
id: 'fc:org:spusers.feide.no',
|
|
171
|
+
displayName: 'Rogn fylkeskommune',
|
|
172
|
+
type: 'fc:org',
|
|
173
|
+
public: false,
|
|
174
|
+
membership: {
|
|
175
|
+
basic: 'admin',
|
|
176
|
+
affiliation: ['member', 'employee', 'faculty'],
|
|
177
|
+
primaryAffiliation: 'employee',
|
|
178
|
+
displayName: 'Akademisk ansatt',
|
|
179
|
+
},
|
|
180
|
+
orgType: ['higher_education', 'upper_secondary_owner', 'primary_and_lower_secondary_owner'],
|
|
181
|
+
norEduOrgNIN: 'NO956326503',
|
|
182
|
+
eduOrgLegalName: 'Rogn fylkeskommune',
|
|
183
|
+
mail: 'support@feide.no',
|
|
184
|
+
children: {
|
|
185
|
+
basic: [],
|
|
186
|
+
teaching: [],
|
|
187
|
+
other: [],
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
id: 'fc:org:spusers.feide.no:unit:NO956326504',
|
|
192
|
+
parent: 'fc:org:spusers.feide.no',
|
|
193
|
+
displayName: 'Lind VGS',
|
|
194
|
+
type: 'fc:org',
|
|
195
|
+
public: false,
|
|
196
|
+
membership: {
|
|
197
|
+
basic: 'member',
|
|
198
|
+
primarySchool: true,
|
|
199
|
+
},
|
|
200
|
+
orgType: ['primary_and_lower_secondary'],
|
|
201
|
+
children: {
|
|
202
|
+
basic: [],
|
|
203
|
+
teaching: [],
|
|
204
|
+
other: [],
|
|
205
|
+
},
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
id: 'fc:org:spusers.feide.no:unit:NO856326501',
|
|
209
|
+
parent: 'fc:org:spusers.feide.no',
|
|
210
|
+
displayName: 'Lerk VGS',
|
|
211
|
+
type: 'fc:org',
|
|
212
|
+
public: false,
|
|
213
|
+
membership: {
|
|
214
|
+
basic: 'member',
|
|
215
|
+
primarySchool: false,
|
|
216
|
+
},
|
|
217
|
+
orgType: ['primary_and_lower_secondary'],
|
|
218
|
+
children: {
|
|
219
|
+
basic: [
|
|
220
|
+
{
|
|
221
|
+
id: 'fc:gogroup:spusers.feide.no:b:NO856326501:1sta:2000-07-01:2100-06-30',
|
|
222
|
+
displayName: 'Klasse 1STA',
|
|
223
|
+
type: 'fc:gogroup',
|
|
224
|
+
notBefore: '2000-06-30T22:00:00Z',
|
|
225
|
+
notAfter: '2100-06-30T23:00:00Z',
|
|
226
|
+
go_type: 'b',
|
|
227
|
+
parent: 'fc:org:spusers.feide.no:unit:NO856326501',
|
|
228
|
+
membership: {
|
|
229
|
+
basic: 'member',
|
|
230
|
+
affiliation: 'employee',
|
|
231
|
+
displayName: 'Ansatt',
|
|
232
|
+
},
|
|
233
|
+
go_type_displayName: 'basisgruppe',
|
|
234
|
+
},
|
|
235
|
+
],
|
|
236
|
+
teaching: [
|
|
237
|
+
{
|
|
238
|
+
id: 'fc:gogroup:spusers.feide.no:u:NO856326501:1mat11-1map1:2000-07-01:2100-06-30',
|
|
239
|
+
displayName: 'Matematikk 1P',
|
|
240
|
+
type: 'fc:gogroup',
|
|
241
|
+
notBefore: '2000-06-30T22:00:00Z',
|
|
242
|
+
notAfter: '2100-06-30T23:00:00Z',
|
|
243
|
+
go_type: 'u',
|
|
244
|
+
parent: 'fc:org:spusers.feide.no:unit:NO856326501',
|
|
245
|
+
membership: {
|
|
246
|
+
basic: 'member',
|
|
247
|
+
affiliation: 'employee',
|
|
248
|
+
displayName: 'Ansatt',
|
|
249
|
+
},
|
|
250
|
+
go_type_displayName: 'undervisningsgruppe',
|
|
251
|
+
grep: {
|
|
252
|
+
displayName: 'Mathematics 1P',
|
|
253
|
+
code: 'MAT1011',
|
|
254
|
+
},
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
id: 'fc:gogroup:spusers.feide.no:u:NO856326501:1mat13-1mat1:2000-07-01:2100-06-30',
|
|
258
|
+
displayName: 'Matematikk 1T',
|
|
259
|
+
type: 'fc:gogroup',
|
|
260
|
+
notBefore: '2000-06-30T22:00:00Z',
|
|
261
|
+
notAfter: '2100-06-30T23:00:00Z',
|
|
262
|
+
go_type: 'u',
|
|
263
|
+
parent: 'fc:org:spusers.feide.no:unit:NO856326501',
|
|
264
|
+
membership: {
|
|
265
|
+
basic: 'member',
|
|
266
|
+
affiliation: 'employee',
|
|
267
|
+
displayName: 'Ansatt',
|
|
268
|
+
},
|
|
269
|
+
go_type_displayName: 'undervisningsgruppe',
|
|
270
|
+
grep: {
|
|
271
|
+
displayName: 'Mathematics 1T',
|
|
272
|
+
code: 'MAT1013',
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
],
|
|
276
|
+
other: [
|
|
277
|
+
{
|
|
278
|
+
id: 'fc:gogroup:spusers.feide.no:a:NO856326501:1sta-lab1:2000-07-01:2100-06-30',
|
|
279
|
+
displayName: 'Laboratoriegruppe 1',
|
|
280
|
+
type: 'fc:gogroup',
|
|
281
|
+
notBefore: '2000-06-30T22:00:00Z',
|
|
282
|
+
notAfter: '2100-06-30T23:00:00Z',
|
|
283
|
+
go_type: 'a',
|
|
284
|
+
parent: 'fc:org:spusers.feide.no:unit:NO856326501',
|
|
285
|
+
membership: {
|
|
286
|
+
basic: 'member',
|
|
287
|
+
affiliation: 'employee',
|
|
288
|
+
displayName: 'Ansatt',
|
|
289
|
+
},
|
|
290
|
+
go_type_displayName: 'other groups',
|
|
291
|
+
},
|
|
292
|
+
{
|
|
293
|
+
id: 'fc:gogroup:spusers.feide.no:a:NO856326501:1sta-lab2:2000-07-01:2100-06-30',
|
|
294
|
+
displayName: 'Laboratoriegruppe 2',
|
|
295
|
+
type: 'fc:gogroup',
|
|
296
|
+
notBefore: '2000-06-30T22:00:00Z',
|
|
297
|
+
notAfter: '2100-06-30T23:00:00Z',
|
|
298
|
+
go_type: 'a',
|
|
299
|
+
parent: 'fc:org:spusers.feide.no:unit:NO856326501',
|
|
300
|
+
membership: {
|
|
301
|
+
basic: 'member',
|
|
302
|
+
affiliation: 'employee',
|
|
303
|
+
displayName: 'Ansatt',
|
|
304
|
+
},
|
|
305
|
+
go_type_displayName: 'other groups',
|
|
306
|
+
},
|
|
307
|
+
],
|
|
308
|
+
},
|
|
309
|
+
},
|
|
310
|
+
],
|
|
311
|
+
};
|
|
312
|
+
const actual = parseUserObject(feideUserLaerer);
|
|
313
|
+
expect(actual).toEqual(expected);
|
|
314
|
+
});
|
|
315
|
+
});
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2022-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
type OrgType =
|
|
10
|
+
| 'higher_education'
|
|
11
|
+
| 'primary_and_lower_secondary'
|
|
12
|
+
| 'primary_and_lower_secondary_owner'
|
|
13
|
+
| 'upper_secondary'
|
|
14
|
+
| 'upper_secondary_owner';
|
|
15
|
+
|
|
16
|
+
type AffiliationType = 'member' | 'student' | 'faculty' | 'staff' | 'affiliate' | 'employee';
|
|
17
|
+
|
|
18
|
+
export interface FeideMembershipType {
|
|
19
|
+
basic: 'member' | 'admin' | 'owner'; // Basic membership role of user.
|
|
20
|
+
affiliation?: AffiliationType[] | AffiliationType;
|
|
21
|
+
primarySchool?: boolean;
|
|
22
|
+
primaryAffiliation?: AffiliationType;
|
|
23
|
+
displayName?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
interface FeideBaseGroup {
|
|
27
|
+
id: string;
|
|
28
|
+
type: 'fc:org' | 'fc:gogroup';
|
|
29
|
+
displayName: string;
|
|
30
|
+
membership: FeideMembershipType;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface FeideOrg extends FeideBaseGroup {
|
|
34
|
+
type: 'fc:org';
|
|
35
|
+
orgType: OrgType[];
|
|
36
|
+
norEduOrgNIN?: string;
|
|
37
|
+
eduOrgLegalName?: string;
|
|
38
|
+
mail?: string;
|
|
39
|
+
parent?: string;
|
|
40
|
+
public: boolean;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
export interface FeideGoGroup extends FeideBaseGroup {
|
|
44
|
+
type: 'fc:gogroup';
|
|
45
|
+
notBefore: string;
|
|
46
|
+
notAfter: string;
|
|
47
|
+
go_type: 'b' | 'u' | 'a';
|
|
48
|
+
parent: string;
|
|
49
|
+
go_type_displayName: string;
|
|
50
|
+
grep?: {
|
|
51
|
+
displayName: string;
|
|
52
|
+
code: string;
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
export type FeideGroup = FeideOrg | FeideGoGroup;
|
|
57
|
+
|
|
58
|
+
interface FeideUser {
|
|
59
|
+
cn: string[];
|
|
60
|
+
displayName: string;
|
|
61
|
+
eduPersonAffiliation: AffiliationType[] | AffiliationType;
|
|
62
|
+
eduPersonPrimaryAffiliation: string;
|
|
63
|
+
eduPersonPrincipalName: string;
|
|
64
|
+
givenName: string[];
|
|
65
|
+
mail?: string[];
|
|
66
|
+
schacHomeOrganization?: string;
|
|
67
|
+
sn: string[];
|
|
68
|
+
uid: string[];
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export interface FeideUserApiType extends FeideUser {
|
|
72
|
+
groups: FeideGroup[];
|
|
73
|
+
primarySchool?: FeideGroup;
|
|
74
|
+
}
|
package/src/User/index.ts
CHANGED
|
@@ -7,5 +7,9 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import AuthModal from './AuthModal';
|
|
10
|
+
import { UserInfo } from './UserInfo';
|
|
11
|
+
import type { FeideGoGroup, FeideGroup, FeideOrg, FeideUserApiType } from './apiTypes';
|
|
10
12
|
|
|
13
|
+
export { UserInfo };
|
|
14
|
+
export type { FeideGoGroup, FeideGroup, FeideOrg, FeideUserApiType };
|
|
11
15
|
export default AuthModal;
|
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) 2022-present, NDLA.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the GPLv3 license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { groupBy } from 'lodash';
|
|
9
|
+
import { FeideGoGroup, FeideGroup, FeideOrg, FeideUserApiType } from './apiTypes';
|
|
10
|
+
|
|
11
|
+
type GoGroupType = 'basic' | 'teaching' | 'other';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* The keys come from:
|
|
15
|
+
* https://docs.feide.no/reference/apis/groups_api/groups_data_model/primary_and_secondary_education_groups.html?highlight=gogroup#specific-attributes-for-fc-gogroup
|
|
16
|
+
*/
|
|
17
|
+
const goGroupTypeMap: Record<'a' | 'b' | 'u', GoGroupType> = {
|
|
18
|
+
a: 'other',
|
|
19
|
+
b: 'basic',
|
|
20
|
+
u: 'teaching',
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @param groups GoGroups to be mapped to specific GoGroupType
|
|
25
|
+
* @returns GoGroups mapped to GoGroupType. basic, teaching and other..
|
|
26
|
+
*/
|
|
27
|
+
const createGroupings = (groups: FeideGoGroup[]) => {
|
|
28
|
+
return groups.reduce<Record<GoGroupType, FeideGoGroup[]>>(
|
|
29
|
+
(acc, curr) => {
|
|
30
|
+
const type = goGroupTypeMap[curr.go_type];
|
|
31
|
+
if (!acc[type]) return acc;
|
|
32
|
+
|
|
33
|
+
acc[type] = acc[type].concat(curr);
|
|
34
|
+
return acc;
|
|
35
|
+
},
|
|
36
|
+
{
|
|
37
|
+
basic: [],
|
|
38
|
+
teaching: [],
|
|
39
|
+
other: [],
|
|
40
|
+
},
|
|
41
|
+
);
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* @param groups GoGroups to be mapped to root/child relations.
|
|
46
|
+
* @returns An object containing root groups mapped with children.
|
|
47
|
+
*/
|
|
48
|
+
const parseOrgs = (groups: FeideGroup[]) => {
|
|
49
|
+
const [roots, children] = groups.reduce<[FeideOrg[], FeideGoGroup[]]>(
|
|
50
|
+
(acc, curr) => {
|
|
51
|
+
if (curr.type === 'fc:org') {
|
|
52
|
+
return [acc[0].concat(curr), acc[1]];
|
|
53
|
+
} else {
|
|
54
|
+
return [acc[0], acc[1].concat(curr)];
|
|
55
|
+
}
|
|
56
|
+
},
|
|
57
|
+
[[], []],
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const childrenByParentId = groupBy(children, (c) => c.parent);
|
|
61
|
+
const rootsWithChildren = roots.map((root) => ({ ...root, children: childrenByParentId[root.id] ?? [] }));
|
|
62
|
+
|
|
63
|
+
return rootsWithChildren.map((root) => ({
|
|
64
|
+
...root,
|
|
65
|
+
children: createGroupings(root.children),
|
|
66
|
+
}));
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* @param user A user object coming from the API
|
|
71
|
+
* @returns A user object parsed in a presentable way to be handled by i.e UserInfo component.
|
|
72
|
+
*/
|
|
73
|
+
export const parseUserObject = (user: FeideUserApiType) => {
|
|
74
|
+
const orgs = parseOrgs(user.groups);
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
uid: user.uid,
|
|
78
|
+
primaryAffiliation: user.eduPersonPrimaryAffiliation,
|
|
79
|
+
displayName: user.displayName,
|
|
80
|
+
mail: user.mail,
|
|
81
|
+
organizations: orgs,
|
|
82
|
+
};
|
|
83
|
+
};
|
package/src/all.scss
CHANGED
package/src/index.ts
CHANGED
|
@@ -108,7 +108,9 @@ export { SearchFieldForm } from './Search/SearchFieldForm';
|
|
|
108
108
|
|
|
109
109
|
export { default as MastheadSearchModal } from './Masthead/MastheadSearchModal';
|
|
110
110
|
export { default as MastheadAuthModal } from './Masthead/MastheadAuthModal';
|
|
111
|
+
export { UserInfo } from './User';
|
|
111
112
|
export { default as AuthModal } from './User';
|
|
113
|
+
export type { FeideGoGroup, FeideGroup, FeideOrg, FeideUserApiType } from './User';
|
|
112
114
|
|
|
113
115
|
export { default as CreatedBy } from './CreatedBy';
|
|
114
116
|
|
|
@@ -757,15 +757,15 @@ const messages = {
|
|
|
757
757
|
},
|
|
758
758
|
blogPosts: {
|
|
759
759
|
blog1: {
|
|
760
|
-
text: '
|
|
761
|
-
externalLink: 'https://blogg.ndla.no/2021/
|
|
760
|
+
text: 'Forslag til årsplaner fra NDLA',
|
|
761
|
+
externalLink: 'https://blogg.ndla.no/2021/08/forslag-til-arsplaner-hos-ndla/',
|
|
762
762
|
linkText: 'Fagblogg',
|
|
763
763
|
license: 'CC-BY-SA-4.0',
|
|
764
764
|
licenseAuthor: 'Vibeke Klungland',
|
|
765
765
|
},
|
|
766
766
|
blog2: {
|
|
767
|
-
text: '
|
|
768
|
-
externalLink: 'https://blogg.ndla.no/
|
|
767
|
+
text: 'Huskeliste for kontaktlærere',
|
|
768
|
+
externalLink: 'https://blogg.ndla.no/2019/08/huskeliste-for-kontaktlaerere/',
|
|
769
769
|
linkText: 'Fagblogg',
|
|
770
770
|
license: 'CC-BY-SA-4.0',
|
|
771
771
|
licenseAuthor: 'Tom Knudsen',
|
|
@@ -945,6 +945,15 @@ const messages = {
|
|
|
945
945
|
resource: {
|
|
946
946
|
accessDenied: 'We are sorry, but this resource is only available to teachers who are logged in with Feide.',
|
|
947
947
|
},
|
|
948
|
+
primarySchool: 'Primary School',
|
|
949
|
+
name: 'Name',
|
|
950
|
+
mail: 'E-mail',
|
|
951
|
+
username: 'Username',
|
|
952
|
+
groupTypes: {
|
|
953
|
+
basic: 'Basic group',
|
|
954
|
+
teaching: 'Teaching group',
|
|
955
|
+
other: 'Other groups',
|
|
956
|
+
},
|
|
948
957
|
},
|
|
949
958
|
checkOutNewFeature: 'New feature',
|
|
950
959
|
slateBlockMenu: {
|