-
-
Notifications
You must be signed in to change notification settings - Fork 54
SAK-51713 Tests & Quizzes Instructors should see all student submissions when a assessment is published to the entire site #278
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| -- SAK-51713 -- | ||
| -- Permission added might not be present | ||
| INSERT IGNORE INTO SAKAI_REALM_FUNCTION (FUNCTION_NAME) VALUES ('assessment.all.groups'); | ||
| -- Add this for every role able to create and manage conditions on a site, you'll need to add the tool too | ||
| INSERT INTO SAKAI_REALM_RL_FN VALUES((select REALM_KEY from SAKAI_REALM where REALM_ID = '!site.template'), (select ROLE_KEY from SAKAI_REALM_ROLE where ROLE_NAME = 'maintain'), (select FUNCTION_KEY from SAKAI_REALM_FUNCTION where FUNCTION_NAME = 'assessment.all.groups')); | ||
| INSERT INTO SAKAI_REALM_RL_FN VALUES((select REALM_KEY from SAKAI_REALM where REALM_ID = '!site.template.course'), (select ROLE_KEY from SAKAI_REALM_ROLE where ROLE_NAME = 'Instructor'), (select FUNCTION_KEY from SAKAI_REALM_FUNCTION where FUNCTION_NAME = 'assessment.all.groups')); | ||
| -- Add this to populate existing sites with the permission | ||
| CREATE TABLE PERMISSIONS_SRC_TEMP (ROLE_NAME VARCHAR(99), FUNCTION_NAME VARCHAR(99)); | ||
| INSERT INTO PERMISSIONS_SRC_TEMP values ('maintain','assessment.all.groups'); | ||
| INSERT INTO PERMISSIONS_SRC_TEMP values ('Instructor','assessment.all.groups'); | ||
|
|
||
| CREATE TABLE PERMISSIONS_TEMP (ROLE_KEY INTEGER, FUNCTION_KEY INTEGER); | ||
| INSERT INTO PERMISSIONS_TEMP (ROLE_KEY, FUNCTION_KEY) | ||
| SELECT SRR.ROLE_KEY, SRF.FUNCTION_KEY | ||
| from PERMISSIONS_SRC_TEMP TMPSRC | ||
| JOIN SAKAI_REALM_ROLE SRR ON (TMPSRC.ROLE_NAME = SRR.ROLE_NAME) | ||
| JOIN SAKAI_REALM_FUNCTION SRF ON (TMPSRC.FUNCTION_NAME = SRF.FUNCTION_NAME); | ||
|
|
||
| INSERT INTO SAKAI_REALM_RL_FN (REALM_KEY, ROLE_KEY, FUNCTION_KEY) | ||
| SELECT SRRFD.REALM_KEY, SRRFD.ROLE_KEY, TMP.FUNCTION_KEY | ||
| FROM | ||
| (SELECT DISTINCT SRRF.REALM_KEY, SRRF.ROLE_KEY FROM SAKAI_REALM_RL_FN SRRF) SRRFD | ||
| JOIN PERMISSIONS_TEMP TMP ON (SRRFD.ROLE_KEY = TMP.ROLE_KEY) | ||
| JOIN SAKAI_REALM SR ON (SRRFD.REALM_KEY = SR.REALM_KEY) | ||
| WHERE SR.REALM_ID != '!site.helper' AND SR.REALM_ID NOT LIKE '!user.template%' | ||
| AND NOT EXISTS ( | ||
| SELECT 1 | ||
| FROM SAKAI_REALM_RL_FN SRRFI | ||
| WHERE SRRFI.REALM_KEY=SRRFD.REALM_KEY AND SRRFI.ROLE_KEY=SRRFD.ROLE_KEY AND SRRFI.FUNCTION_KEY=TMP.FUNCTION_KEY | ||
| ); | ||
|
|
||
| DROP TABLE PERMISSIONS_TEMP; | ||
| DROP TABLE PERMISSIONS_SRC_TEMP; | ||
| -- END SAK-51713 -- | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,43 @@ | ||||||||||||||||||||||||||||||||||||||||||||
| -- SAK-51713 -- | ||||||||||||||||||||||||||||||||||||||||||||
| -- Permission added might not be present | ||||||||||||||||||||||||||||||||||||||||||||
| MERGE INTO SAKAI_REALM_FUNCTION srf | ||||||||||||||||||||||||||||||||||||||||||||
| USING ( | ||||||||||||||||||||||||||||||||||||||||||||
| SELECT -123 as function_key, | ||||||||||||||||||||||||||||||||||||||||||||
| 'assessment.all.groups' as function_name | ||||||||||||||||||||||||||||||||||||||||||||
| FROM dual | ||||||||||||||||||||||||||||||||||||||||||||
| ) t on (srf.function_name = t.function_name) | ||||||||||||||||||||||||||||||||||||||||||||
| WHEN NOT MATCHED THEN | ||||||||||||||||||||||||||||||||||||||||||||
| INSERT (function_key, function_name) | ||||||||||||||||||||||||||||||||||||||||||||
| VALUES (SAKAI_REALM_FUNCTION_SEQ.NEXTVAL, t.function_name); | ||||||||||||||||||||||||||||||||||||||||||||
| -- Add this for every role able to create and manage conditions on a site, you'll need to add the tool too | ||||||||||||||||||||||||||||||||||||||||||||
| INSERT INTO SAKAI_REALM_RL_FN VALUES((select REALM_KEY from SAKAI_REALM where REALM_ID = '!site.template'), (select ROLE_KEY from SAKAI_REALM_ROLE where ROLE_NAME = 'maintain'), (select FUNCTION_KEY from SAKAI_REALM_FUNCTION where FUNCTION_NAME = 'assessment.all.groups')); | ||||||||||||||||||||||||||||||||||||||||||||
| INSERT INTO SAKAI_REALM_RL_FN VALUES((select REALM_KEY from SAKAI_REALM where REALM_ID = '!site.template.course'), (select ROLE_KEY from SAKAI_REALM_ROLE where ROLE_NAME = 'Instructor'), (select FUNCTION_KEY from SAKAI_REALM_FUNCTION where FUNCTION_NAME = 'assessment.all.groups')); | ||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+13
to
+14
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Template inserts lack idempotency and may fail on re-run. Same issue as the MySQL version: these will fail with a constraint violation if run twice. Oracle doesn't have 🔎 Suggested fix using MERGE: -- Add this for every role able to create and manage conditions on a site, you'll need to add the tool too
-INSERT INTO SAKAI_REALM_RL_FN VALUES((select REALM_KEY from SAKAI_REALM where REALM_ID = '!site.template'), (select ROLE_KEY from SAKAI_REALM_ROLE where ROLE_NAME = 'maintain'), (select FUNCTION_KEY from SAKAI_REALM_FUNCTION where FUNCTION_NAME = 'assessment.all.groups'));
-INSERT INTO SAKAI_REALM_RL_FN VALUES((select REALM_KEY from SAKAI_REALM where REALM_ID = '!site.template.course'), (select ROLE_KEY from SAKAI_REALM_ROLE where ROLE_NAME = 'Instructor'), (select FUNCTION_KEY from SAKAI_REALM_FUNCTION where FUNCTION_NAME = 'assessment.all.groups'));
+MERGE INTO SAKAI_REALM_RL_FN t
+USING (
+ SELECT
+ (SELECT REALM_KEY FROM SAKAI_REALM WHERE REALM_ID = '!site.template') AS REALM_KEY,
+ (SELECT ROLE_KEY FROM SAKAI_REALM_ROLE WHERE ROLE_NAME = 'maintain') AS ROLE_KEY,
+ (SELECT FUNCTION_KEY FROM SAKAI_REALM_FUNCTION WHERE FUNCTION_NAME = 'assessment.all.groups') AS FUNCTION_KEY
+ FROM dual
+) s ON (t.REALM_KEY = s.REALM_KEY AND t.ROLE_KEY = s.ROLE_KEY AND t.FUNCTION_KEY = s.FUNCTION_KEY)
+WHEN NOT MATCHED THEN INSERT (REALM_KEY, ROLE_KEY, FUNCTION_KEY) VALUES (s.REALM_KEY, s.ROLE_KEY, s.FUNCTION_KEY);
+
+MERGE INTO SAKAI_REALM_RL_FN t
+USING (
+ SELECT
+ (SELECT REALM_KEY FROM SAKAI_REALM WHERE REALM_ID = '!site.template.course') AS REALM_KEY,
+ (SELECT ROLE_KEY FROM SAKAI_REALM_ROLE WHERE ROLE_NAME = 'Instructor') AS ROLE_KEY,
+ (SELECT FUNCTION_KEY FROM SAKAI_REALM_FUNCTION WHERE FUNCTION_NAME = 'assessment.all.groups') AS FUNCTION_KEY
+ FROM dual
+) s ON (t.REALM_KEY = s.REALM_KEY AND t.ROLE_KEY = s.ROLE_KEY AND t.FUNCTION_KEY = s.FUNCTION_KEY)
+WHEN NOT MATCHED THEN INSERT (REALM_KEY, ROLE_KEY, FUNCTION_KEY) VALUES (s.REALM_KEY, s.ROLE_KEY, s.FUNCTION_KEY);📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||
| -- Add this to populate existing sites with the permission | ||||||||||||||||||||||||||||||||||||||||||||
| CREATE TABLE PERMISSIONS_SRC_TEMP (ROLE_NAME VARCHAR(99), FUNCTION_NAME VARCHAR(99)); | ||||||||||||||||||||||||||||||||||||||||||||
| INSERT INTO PERMISSIONS_SRC_TEMP VALUES ('maintain','assessment.all.groups'); | ||||||||||||||||||||||||||||||||||||||||||||
| INSERT INTO PERMISSIONS_SRC_TEMP VALUES ('Instructor','assessment.all.groups'); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| CREATE TABLE PERMISSIONS_TEMP (ROLE_KEY INTEGER, FUNCTION_KEY INTEGER); | ||||||||||||||||||||||||||||||||||||||||||||
| INSERT INTO PERMISSIONS_TEMP (ROLE_KEY, FUNCTION_KEY) | ||||||||||||||||||||||||||||||||||||||||||||
| SELECT SRR.ROLE_KEY, SRF.FUNCTION_KEY | ||||||||||||||||||||||||||||||||||||||||||||
| FROM PERMISSIONS_SRC_TEMP TMPSRC | ||||||||||||||||||||||||||||||||||||||||||||
| JOIN SAKAI_REALM_ROLE SRR ON (TMPSRC.ROLE_NAME = SRR.ROLE_NAME) | ||||||||||||||||||||||||||||||||||||||||||||
| JOIN SAKAI_REALM_FUNCTION SRF ON (TMPSRC.FUNCTION_NAME = SRF.FUNCTION_NAME); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| INSERT INTO SAKAI_REALM_RL_FN (REALM_KEY, ROLE_KEY, FUNCTION_KEY) | ||||||||||||||||||||||||||||||||||||||||||||
| SELECT | ||||||||||||||||||||||||||||||||||||||||||||
| SRRFD.REALM_KEY, SRRFD.ROLE_KEY, TMP.FUNCTION_KEY | ||||||||||||||||||||||||||||||||||||||||||||
| FROM | ||||||||||||||||||||||||||||||||||||||||||||
| (SELECT DISTINCT SRRF.REALM_KEY, SRRF.ROLE_KEY FROM SAKAI_REALM_RL_FN SRRF) SRRFD | ||||||||||||||||||||||||||||||||||||||||||||
| JOIN PERMISSIONS_TEMP TMP ON (SRRFD.ROLE_KEY = TMP.ROLE_KEY) | ||||||||||||||||||||||||||||||||||||||||||||
| JOIN SAKAI_REALM SR ON (SRRFD.REALM_KEY = SR.REALM_KEY) | ||||||||||||||||||||||||||||||||||||||||||||
| WHERE SR.REALM_ID != '!site.helper' AND SR.REALM_ID NOT LIKE '!user.template%' | ||||||||||||||||||||||||||||||||||||||||||||
| AND NOT EXISTS ( | ||||||||||||||||||||||||||||||||||||||||||||
| SELECT 1 | ||||||||||||||||||||||||||||||||||||||||||||
| FROM SAKAI_REALM_RL_FN SRRFI | ||||||||||||||||||||||||||||||||||||||||||||
| WHERE SRRFI.REALM_KEY=SRRFD.REALM_KEY AND SRRFI.ROLE_KEY=SRRFD.ROLE_KEY AND SRRFI.FUNCTION_KEY=TMP.FUNCTION_KEY | ||||||||||||||||||||||||||||||||||||||||||||
| ); | ||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||
| DROP TABLE PERMISSIONS_TEMP; | ||||||||||||||||||||||||||||||||||||||||||||
| DROP TABLE PERMISSIONS_SRC_TEMP; | ||||||||||||||||||||||||||||||||||||||||||||
| -- END SAK-51713 -- | ||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Template inserts lack idempotency and may fail on re-run.
These direct
INSERTstatements will fail with a duplicate key error if the script runs a second time (or if the permission already exists). Additionally, if any subquery returnsNULL(e.g., role or realm not found), the insert will either fail or insert invalid data.Consider using
INSERT IGNOREor wrapping with aNOT EXISTScheck to match the idempotent pattern used in the bulk insert below.🔎 Suggested fix using INSERT IGNORE:
🤖 Prompt for AI Agents