Skip to content

Commit 69b7d1a

Browse files
committed
better access cntrl
1 parent 92d5efe commit 69b7d1a

File tree

6 files changed

+58
-10
lines changed

6 files changed

+58
-10
lines changed

src/client/components/Courses/Course/index.tsx

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,18 @@ const Course = () => {
122122
if (isLoading || courseLoading || !course || isUserLoading || !user)
123123
return null
124124

125+
const amongResponsibles = course.responsibilities
126+
? course.responsibilities.some((r) => r.user.id === user.id)
127+
: false
128+
129+
if (!user.isAdmin && !amongResponsibles) {
130+
return (
131+
<Box>
132+
<Typography variant="h5">{t('noAccess')}</Typography>
133+
</Box>
134+
)
135+
}
136+
125137
const mandatoryPromptId = prompts.find((prompt) => prompt.mandatory)?.id
126138

127139
const handleSave = () => {

src/client/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"common": {
3+
"noAccess": "No access",
34
"courseStats": "Course stats",
45
"appName": "CurreChat",
56
"admin": "Admin",
@@ -49,7 +50,7 @@
4950
},
5051
"info": {
5152
"title": "## Attention",
52-
"disclaimer": "### When using AI tools avoid sharing any information, if you have not made sure you are allowed to share it. That is, when you are entering prompts to an AI tool, make sure that you consider any possible confidentiality restrictions and that you have acquired the necessary copyright permits, licenses etc. for sharing the entered information. Any unauthorized use of information within AI systems may lead to infringement of third-party IP rights. \n \n ### CurreChat utilizes large language models developed by OpenAI, which are located in the Microsoft Azure cloud service of the University of Helsinki within the EU region. The information input into the service is not used to further train the language model. Additionally, no user identification information is passed on to the language model. \n \n ### Each user has 75,000 tokens available for the GPT-4 language model. This balance resets every month. To reduce token consumption, it is advisable to clear the conversation using the CLEAR button whenever you change the topic of conversation. \n \n ### You can see the token consumption and the language model in use underneath the conversation window. \n ### You can learn more about tokens used by large language models here: [https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them). \n \n ### You can find more information about the use of artificial intelligence in teaching at: [https://teaching.helsinki.fi/instructions/article/artificial-intelligence-teaching](https://teaching.helsinki.fi/instructions/article/artificial-intelligence-teaching). \n ### Please contact [[email protected]](mailto:[email protected]) with any questions regarding CurreChat."
53+
"disclaimer": "### When using AI tools avoid sharing any information, if you have not made sure you are allowed to share it. That is, when you are entering prompts to an AI tool, make sure that you consider any possible confidentiality restrictions and that you have acquired the necessary copyright permits, licenses etc. for sharing the entered information. Any unauthorized use of information within AI systems may lead to infringement of third-party IP rights. \n \n ### CurreChat utilizes large language models developed by OpenAI, which are located in the Microsoft Azure cloud service of the University of Helsinki within the EU region. The information input into the service is not used to further train the language model. Additionally, no user identification information is passed on to the language model. \n \n ### Each user has 75,000 tokens available for the GPT-4o language model. This balance resets every month. To reduce token consumption, it is advisable to clear the conversation using the CLEAR button whenever you change the topic of conversation. \n \n ### You can see the token consumption and the language model in use underneath the conversation window. \n ### You can learn more about tokens used by large language models here: [https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them). \n \n ### You can find more information about the use of artificial intelligence in teaching at: [https://teaching.helsinki.fi/instructions/article/artificial-intelligence-teaching](https://teaching.helsinki.fi/instructions/article/artificial-intelligence-teaching). \n ### Please contact [[email protected]](mailto:[email protected]) with any questions regarding CurreChat."
5354
},
5455
"footer": {
5556
"contactSupport": "Contact support: <mailTo>{{supportEmail}}</mailTo>"

src/client/locales/fi.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"common": {
3+
"noAccess": "Ei oikeuksia",
34
"courseStats": "Kurssitilastot",
45
"appName": "CurreChat",
56
"admin": "Ylläpito",
@@ -48,7 +49,7 @@
4849
},
4950
"info": {
5051
"title": "## Huomio",
51-
"disclaimer": "### Kun käytät tekoälytyökaluja, vältä tietojen jakamista, joiden jakamisen luvallisuudesta sinulla ei ole varmuutta. Kun syötät tietoja tekoälytyökaluun, varmista, että otat huomioon mahdolliset luottamuksellisuusrajoitukset ja olet hankkinut tarvittavat tekijänoikeusluvat jne. annettujen tietojen jakamiseksi. Minkä tahansa luvattoman tiedon käyttö tekoälyjärjestelmissä voi johtaa kolmansien osapuolien immateriaalioikeuksien loukkaamiseen. \n \n ### CurreChat käyttää OpenAI:n kehittämiä suuria kielimalleja, jotka sijaitsevat Helsingin yliopiston Microsoft Azure -pilvipalvelussa EU-alueella. Palveluun syötettyjä tietoja ei käytetä kielimallin jatkokouluttamiseen. Käyttäjistä ei myöskään välity tunnistetietoja kielimallille. \n \n ### Jokaisella käyttäjällä on käytössään 75 000 tokenia GPT-4 -kielimalliin. Tämä saldo nollautuu kuukauden välein. Vähentääksesi tokenien kulutusta, kannattaa keskustelu tyhjentää TYHJENNÄ -painikkeesta aina, kun vaihdat keskustelun aihetta. \n \n ### Näet tokenien kulutuksen ja käytössä olevan kielimallin keskusteluikkunan alapuolella. \n ### Voit lukea suurten kielimallien käyttämistä tokeneista tarkemmin täältä: [https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them). \n \n ### Lisätietoa tekoälyn käytöstä opetuksessa löydät: [https://teaching.helsinki.fi/ohjeet/artikkeli/tekoaly-opetuksessa](https://teaching.helsinki.fi/ohjeet/artikkeli/tekoaly-opetuksessa). \n ### Voit olla yhteydessä CurreChat -palveluun liittyyvissä kysymyksissä osoitteeseen [[email protected]](mailto:[email protected])"
52+
"disclaimer": "### Kun käytät tekoälytyökaluja, vältä tietojen jakamista, joiden jakamisen luvallisuudesta sinulla ei ole varmuutta. Kun syötät tietoja tekoälytyökaluun, varmista, että otat huomioon mahdolliset luottamuksellisuusrajoitukset ja olet hankkinut tarvittavat tekijänoikeusluvat jne. annettujen tietojen jakamiseksi. Minkä tahansa luvattoman tiedon käyttö tekoälyjärjestelmissä voi johtaa kolmansien osapuolien immateriaalioikeuksien loukkaamiseen. \n \n ### CurreChat käyttää OpenAI:n kehittämiä suuria kielimalleja, jotka sijaitsevat Helsingin yliopiston Microsoft Azure -pilvipalvelussa EU-alueella. Palveluun syötettyjä tietoja ei käytetä kielimallin jatkokouluttamiseen. Käyttäjistä ei myöskään välity tunnistetietoja kielimallille. \n \n ### Jokaisella käyttäjällä on käytössään 75 000 tokenia GPT-4o -kielimalliin. Tämä saldo nollautuu kuukauden välein. Vähentääksesi tokenien kulutusta, kannattaa keskustelu tyhjentää TYHJENNÄ -painikkeesta aina, kun vaihdat keskustelun aihetta. \n \n ### Näet tokenien kulutuksen ja käytössä olevan kielimallin keskusteluikkunan alapuolella. \n ### Voit lukea suurten kielimallien käyttämistä tokeneista tarkemmin täältä: [https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them). \n \n ### Lisätietoa tekoälyn käytöstä opetuksessa löydät: [https://teaching.helsinki.fi/ohjeet/artikkeli/tekoaly-opetuksessa](https://teaching.helsinki.fi/ohjeet/artikkeli/tekoaly-opetuksessa). \n ### Voit olla yhteydessä CurreChat -palveluun liittyyvissä kysymyksissä osoitteeseen [[email protected]](mailto:[email protected])"
5253
},
5354
"footer": {
5455
"contactSupport": "Ota yhteyttä tukeen: <mailTo>{{supportEmail}}</mailTo>"

src/client/locales/sv.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"common": {
3-
"courseStats": "",
3+
"noAccess": "Ingen åtkomst",
4+
"courseStats": "Kursstatistik",
45
"appName": "CurreChat",
56
"admin": "Admin",
67
"send": "Skicka till",

src/server/db/seeders/infotexts.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ const infoTexts = [
44
{
55
name: 'disclaimer',
66
text: {
7-
fi: '### Kun käytät tekoälytyökaluja, vältä tietojen jakamista, joiden jakamisen luvallisuudesta sinulla ei ole varmuutta. Kun syötät tietoja tekoälytyökaluun, varmista, että otat huomioon mahdolliset luottamuksellisuusrajoitukset ja olet hankkinut tarvittavat tekijänoikeusluvat jne. annettujen tietojen jakamiseksi. Minkä tahansa luvattoman tiedon käyttö tekoälyjärjestelmissä voi johtaa kolmansien osapuolien immateriaalioikeuksien loukkaamiseen. \n \n ### CurreChat käyttää OpenAI:n kehittämiä suuria kielimalleja, jotka sijaitsevat Helsingin yliopiston Microsoft Azure -pilvipalvelussa EU-alueella. Palveluun syötettyjä tietoja ei käytetä kielimallin jatkokouluttamiseen. Käyttäjistä ei myöskään välity tunnistetietoja kielimallille. \n \n ### Jokaisella käyttäjällä on käytössään 75 000 tokenia GPT-4 -kielimalliin. Tämä saldo nollautuu kuukauden välein. Vähentääksesi tokenien kulutusta, kannattaa keskustelu tyhjentää TYHJENNÄ -painikkeesta aina, kun vaihdat keskustelun aihetta. \n \n ### Näet tokenien kulutuksen ja käytössä olevan kielimallin keskusteluikkunan alapuolella. \n ### Voit lukea suurten kielimallien käyttämistä tokeneista tarkemmin täältä: [https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them). \n \n ### Lisätietoa tekoälyn käytöstä opetuksessa löydät: [https://teaching.helsinki.fi/ohjeet/artikkeli/tekoaly-opetuksessa](https://teaching.helsinki.fi/ohjeet/artikkeli/tekoaly-opetuksessa). \n ### Voit olla yhteydessä CurreChat -palveluun liittyyvissä kysymyksissä osoitteeseen [[email protected]](mailto:[email protected])',
7+
fi: '### Kun käytät tekoälytyökaluja, vältä tietojen jakamista, joiden jakamisen luvallisuudesta sinulla ei ole varmuutta. Kun syötät tietoja tekoälytyökaluun, varmista, että otat huomioon mahdolliset luottamuksellisuusrajoitukset ja olet hankkinut tarvittavat tekijänoikeusluvat jne. annettujen tietojen jakamiseksi. Minkä tahansa luvattoman tiedon käyttö tekoälyjärjestelmissä voi johtaa kolmansien osapuolien immateriaalioikeuksien loukkaamiseen. \n \n ### CurreChat käyttää OpenAI:n kehittämiä suuria kielimalleja, jotka sijaitsevat Helsingin yliopiston Microsoft Azure -pilvipalvelussa EU-alueella. Palveluun syötettyjä tietoja ei käytetä kielimallin jatkokouluttamiseen. Käyttäjistä ei myöskään välity tunnistetietoja kielimallille. \n \n ### Jokaisella käyttäjällä on käytössään 75 000 tokenia GPT-4o -kielimalliin. Tämä saldo nollautuu kuukauden välein. Vähentääksesi tokenien kulutusta, kannattaa keskustelu tyhjentää TYHJENNÄ -painikkeesta aina, kun vaihdat keskustelun aihetta. \n \n ### Näet tokenien kulutuksen ja käytössä olevan kielimallin keskusteluikkunan alapuolella. \n ### Voit lukea suurten kielimallien käyttämistä tokeneista tarkemmin täältä: [https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them). \n \n ### Lisätietoa tekoälyn käytöstä opetuksessa löydät: [https://teaching.helsinki.fi/ohjeet/artikkeli/tekoaly-opetuksessa](https://teaching.helsinki.fi/ohjeet/artikkeli/tekoaly-opetuksessa). \n ### Voit olla yhteydessä CurreChat -palveluun liittyyvissä kysymyksissä osoitteeseen [[email protected]](mailto:[email protected])',
88
sv: '### När du använder AI-verktyg, undvik att dela data som du inte är säker på att du har rätt att dela. När du matar in data i ett AI-verktyg ska du se till att du tar hänsyn till eventuella sekretessbegränsningar och att du har fått nödvändiga upphovsrättstillstånd etc. för att dela de data som tillhandahålls. Användning av obehöriga data i AI-system kan leda till intrång i tredje parts immateriella rättigheter. \n \n ### CurreChat använder stora språkmodeller som utvecklats av OpenAI och som finns på Microsoft Azure-molntjänsten vid Helsingfors universitet i EU. De uppgifter som matas in i tjänsten kommer inte att användas för ytterligare utbildning av språkmodellen. Dessutom överförs inga användaridentifieringsdata till språkmodellen. \n \n ### Varje användare har tillgång till 75 000 tokens för språkmodellen GPT-4. Detta saldo återställs varje månad. För att minska förbrukningen av tokens bör du rensa konversationen med CLEAR-knappen varje gång du byter ämne för konversationen. \n \n ### Du kan se förbrukningen av tokens och den språkmodell som används längst ner i konversationsfönstret. \n ### Du kan läsa mer om de tokens som används av de viktigaste språkmodellerna här: [https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them). \n \n ### Mer information om användningen av AI inom utbildning finns på: [https://teaching.helsinki.fi/instruktioner/artikel/artificiell-intelligens-i-undervisningen](https://teaching.helsinki.fi/instruktioner/artikel/artificiell-intelligens-i-undervisningen).',
9-
en: '### When using AI tools avoid sharing any information, if you have not made sure you are allowed to share it. That is, when you are entering prompts to an AI tool, make sure that you consider any possible confidentiality restrictions and that you have acquired the necessary copyright permits, licenses etc. for sharing the entered information. Any unauthorized use of information within AI systems may lead to infringement of third-party IP rights. \n \n ### CurreChat utilizes large language models developed by OpenAI, which are located in the Microsoft Azure cloud service of the University of Helsinki within the EU region. The information input into the service is not used to further train the language model. Additionally, no user identification information is passed on to the language model. \n \n ### Each user has 75,000 tokens available for the GPT-4 language model. This balance resets every month. To reduce token consumption, it is advisable to clear the conversation using the CLEAR button whenever you change the topic of conversation. \n \n ### You can see the token consumption and the language model in use underneath the conversation window. \n ### You can learn more about tokens used by large language models here: [https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them). \n \n ### You can find more information about the use of artificial intelligence in teaching at: [https://teaching.helsinki.fi/instructions/article/artificial-intelligence-teaching](https://teaching.helsinki.fi/instructions/article/artificial-intelligence-teaching). \n ### Please contact [[email protected]](mailto:[email protected]) with any questions regarding CurreChat.',
9+
en: '### When using AI tools avoid sharing any information, if you have not made sure you are allowed to share it. That is, when you are entering prompts to an AI tool, make sure that you consider any possible confidentiality restrictions and that you have acquired the necessary copyright permits, licenses etc. for sharing the entered information. Any unauthorized use of information within AI systems may lead to infringement of third-party IP rights. \n \n ### CurreChat utilizes large language models developed by OpenAI, which are located in the Microsoft Azure cloud service of the University of Helsinki within the EU region. The information input into the service is not used to further train the language model. Additionally, no user identification information is passed on to the language model. \n \n ### Each user has 75,000 tokens available for the GPT-4o language model. This balance resets every month. To reduce token consumption, it is advisable to clear the conversation using the CLEAR button whenever you change the topic of conversation. \n \n ### You can see the token consumption and the language model in use underneath the conversation window. \n ### You can learn more about tokens used by large language models here: [https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them](https://help.openai.com/en/articles/4936856-what-are-tokens-and-how-to-count-them). \n \n ### You can find more information about the use of artificial intelligence in teaching at: [https://teaching.helsinki.fi/instructions/article/artificial-intelligence-teaching](https://teaching.helsinki.fi/instructions/article/artificial-intelligence-teaching). \n ### Please contact [[email protected]](mailto:[email protected]) with any questions regarding CurreChat.',
1010
},
1111
},
1212
{

src/server/routes/prompt.ts

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import express from 'express'
22

3-
import { Message } from '../types'
4-
import { Prompt, ChatInstance } from '../db/models'
3+
import { Message, RequestWithUser } from '../types'
4+
import { Prompt, ChatInstance, Responsibility } from '../db/models'
55

66
const promptRouter = express.Router()
77

@@ -32,7 +32,40 @@ promptRouter.get('/:courseId', async (req, res) => {
3232
return res.send(prompts)
3333
})
3434

35-
promptRouter.post('/', async (req, res) => {
35+
const authorizeUser = async (
36+
req: express.Request,
37+
res: express.Response,
38+
next: express.NextFunction
39+
) => {
40+
const request = req as RequestWithUser
41+
const data = req.body as NewPromptData
42+
const { user } = request
43+
const { id } = req.params
44+
45+
const chatInstanceId = id
46+
? (await Prompt.findByPk(id)).chatInstanceId
47+
: data.chatInstanceId
48+
49+
const chatInstance = (await ChatInstance.findByPk(chatInstanceId, {
50+
include: [
51+
{
52+
model: Responsibility,
53+
as: 'responsibilities',
54+
},
55+
],
56+
})) as ChatInstance & { responsibilities: Responsibility[] }
57+
58+
const isAmongActiveCourses = chatInstance?.responsibilities.some(
59+
(r) => r.userId === user.id
60+
)
61+
62+
if (!isAmongActiveCourses && !user.isAdmin)
63+
return res.status(403).send('Not allowed')
64+
65+
return next()
66+
}
67+
68+
promptRouter.post('/', authorizeUser, async (req, res) => {
3669
const data = req.body as NewPromptData
3770

3871
const newPrompt = await Prompt.create(data)
@@ -42,7 +75,7 @@ promptRouter.post('/', async (req, res) => {
4275

4376
export default promptRouter
4477

45-
promptRouter.delete('/:id', async (req, res) => {
78+
promptRouter.delete('/:id', authorizeUser, authorizeUser, async (req, res) => {
4679
const { id } = req.params
4780

4881
const prompt = await Prompt.findByPk(id)
@@ -54,7 +87,7 @@ promptRouter.delete('/:id', async (req, res) => {
5487
return res.status(204).send()
5588
})
5689

57-
promptRouter.put('/:id', async (req, res) => {
90+
promptRouter.put('/:id', authorizeUser, authorizeUser, async (req, res) => {
5891
const { id } = req.params
5992
const data = req.body as Prompt
6093
const { systemMessage, name, hidden, mandatory } = data

0 commit comments

Comments
 (0)