Compare commits
635 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| bd27666c42 | |||
| d1787723db | |||
| 7ba9f14fe0 | |||
| 0d70e9b8e9 | |||
| 432d3cc846 | |||
| 59de100b8b | |||
| f1e0f1c194 | |||
| 444d046f9e | |||
| 64722afd45 | |||
| be092b7309 | |||
| 005b2bc8a0 | |||
| f4bd5f5e1a | |||
| 1a8342d9d4 | |||
| 6a87753e12 | |||
| 1d16496ee6 | |||
| e7dc32ad80 | |||
| fde541a1eb | |||
| 95ee02b253 | |||
| f562290f78 | |||
| 1273a6665b | |||
| 74ea4a91e1 | |||
| d035bebb1e | |||
| 4c51211800 | |||
| 61edefee12 | |||
| 304bd3b26b | |||
| 57c5494741 | |||
| f1019f4616 | |||
| bbdb62fffe | |||
| cce2977770 | |||
| 60357a5551 | |||
| ce5ea7e187 | |||
| 36b7d0471c | |||
| 580a0918b4 | |||
| 6aaf582982 | |||
| d6cbf8b8fb | |||
| e760287046 | |||
| f0b924f980 | |||
| 1260ed9e33 | |||
| 79df6aee8c | |||
| ee9c931987 | |||
| 01389839df | |||
| 88a78e9307 | |||
| 99e51855a6 | |||
| 5263019b3a | |||
| 442dc8270a | |||
| dab8d7a0dc | |||
| 9f256a8380 | |||
| 6f0614ef19 | |||
| 43dfc84482 | |||
| 5a7e921f70 | |||
| 0220cc4bdf | |||
| d470ef4c27 | |||
| efecaa34a4 | |||
| 11694360bd | |||
| 060e39220c | |||
| e016281821 | |||
| 2267c9fe7f | |||
| 8bcca194ce | |||
| 9bb1a66c3c | |||
| 627b0a7a45 | |||
| f873ff9ad2 | |||
| 0dfef1313f | |||
| e647f49fe4 | |||
| 088f6b973a | |||
| 3c613eb0f9 | |||
| 05403f4989 | |||
| a0a10c4d4c | |||
| f92552d372 | |||
| 769987cf28 | |||
| 3bee541afc | |||
| 069bf5a9dd | |||
| b5c2fef399 | |||
| 6c5b701bb5 | |||
| 696e063e65 | |||
| 0807b60603 | |||
| 2e7dbfaabb | |||
| d6e31537bc | |||
| d01d3d8eef | |||
| 7ac4ad9a8b | |||
| 9d349b8170 | |||
| bd20ed1a7c | |||
| f5d6dcfd06 | |||
| 466ae79141 | |||
| 821001ce9c | |||
| ac7cf1cfeb | |||
| f2057a1115 | |||
| 61c36e125e | |||
| 629c7f75b3 | |||
| bdefa64956 | |||
| bfc047cef0 | |||
| 9c9227995c | |||
| 3a69718c58 | |||
| cb8a553af9 | |||
| 83dc898b00 | |||
| 3e6e80f96f | |||
| 1b052996ff | |||
| e516332576 | |||
| 50615d7105 | |||
| 867e35d77f | |||
| 72337efdf7 | |||
| c0d8a1c3e1 | |||
| f6be98b942 | |||
| d694bf2435 | |||
| 2f58da96bb | |||
| 66f63a3bf6 | |||
| 349ac5cbd7 | |||
| 7985a77474 | |||
| 9df6a3972d | |||
| 5e26c462d3 | |||
| bd547eb6dd | |||
| b4db1fd8ad | |||
| 8cdf03c5a9 | |||
| 17567f33c9 | |||
| 8509759768 | |||
| 20eb1297ef | |||
| ddf605c655 | |||
| 6efc731aab | |||
| 6ea7ce8acb | |||
| 74a30640d6 | |||
| 105bfe1d95 | |||
| e87bbfbe94 | |||
| 5450a19dec | |||
| 094730c7d2 | |||
| 76f2ed9c6a | |||
| 0af0d1d7f6 | |||
| 6415201009 | |||
| 99566b5a60 | |||
| 06a92988fa | |||
| 4202a6935e | |||
| 7c730dfe01 | |||
| 6e0f59fe32 | |||
| 6ed9356daf | |||
| 8539f6168e | |||
| 9e6ea43d93 | |||
| 6b65d96d70 | |||
| 98e96df381 | |||
| 127b7446a0 | |||
| a032e58de6 | |||
| 4db39b4571 | |||
| a9b13cfac3 | |||
| c1d4386dd7 | |||
| b3065a69ed | |||
| aba27d5317 | |||
| 7391dfc208 | |||
| 6d2fedaa47 | |||
| 02f31bb65b | |||
| 1e2f780503 | |||
| 57bebf7c4b | |||
| f940b5dcd9 | |||
| 7cccc7e03a | |||
| 76483d4f45 | |||
| d3ef856e79 | |||
| 5c4aef2664 | |||
| 4bd4b46070 | |||
| 2392c10734 | |||
| f86bd7ece0 | |||
| 805417c33d | |||
| 127b54ffbe | |||
| 8450d9948a | |||
| 3eca9bf311 | |||
| 6b3738bc20 | |||
| 1974156194 | |||
| f0a4839154 | |||
| 3ab6d8ba2b | |||
| 1d2b6c84a2 | |||
| 266744a6f9 | |||
| c3a1ccc244 | |||
| 96df578e8e | |||
| 6cf6523cc7 | |||
| 43eadce6fc | |||
| 98fe6eee32 | |||
| 671ad6b497 | |||
| 49bfb1e5f9 | |||
| 000a5d0bec | |||
| 936ed6067f | |||
| 238006f649 | |||
| d11038dd43 | |||
| 6b8b06911b | |||
| fe1ae23939 | |||
| 64b5d44abc | |||
| 526e3e8c97 | |||
| 8668391630 | |||
| f35e7a0eeb | |||
| 949f522c13 | |||
| ac6bef4e38 | |||
| 72bb7ac302 | |||
| 1b4cd6be30 | |||
| 10dae695ec | |||
| fc12d8d459 | |||
| c46c85055b | |||
| f4411ba700 | |||
| 37002deeda | |||
| 06e4325bda | |||
| 8aa12f5bff | |||
| 84bef5413c | |||
| df26945105 | |||
| b9b8d94716 | |||
| ec92a0762d | |||
| 9bd851f39c | |||
| 502b17bebd | |||
| 2857ca0c9f | |||
| 5a1aa729df | |||
| 6020745280 | |||
| 948485dbd6 | |||
| 1da88f2c6a | |||
| ab38db069e | |||
| c1a29fc252 | |||
| a1d8976005 | |||
| c0171e6090 | |||
| bdf7f7613e | |||
| b42457028a | |||
| 783f2a8b8e | |||
| ac496f22af | |||
| a1c3aedf5b | |||
| a2c9e82c42 | |||
| 82d2d27cd3 | |||
| e8d8bccb25 | |||
| d5859dacc8 | |||
| d738ae91e7 | |||
| daff43e9c7 | |||
| 6aedf45bee | |||
| fa9fffdc9a | |||
| 7ad1d28554 | |||
| 3f3385c46a | |||
| 11ebc149ed | |||
| c985ad6263 | |||
| 6a6d683283 | |||
| ab9f7ab790 | |||
| 3248a578e9 | |||
| 3cd9d0a689 | |||
| 8ee6b2a201 | |||
| 692049a9c1 | |||
| 36895ee702 | |||
| 68e2d67939 | |||
| dd6f34e334 | |||
| 310eff99fc | |||
| 5047c83b9c | |||
| 5b531aabee | |||
| 5723130d84 | |||
| f490505b23 | |||
| ed90c88864 | |||
| faabcf6d76 | |||
| 8837262d2c | |||
| e30562a127 | |||
| b43f63c11f | |||
| 78ccc2c951 | |||
| 9835dc02dd | |||
| 5420485076 | |||
| e69a3f20ee | |||
| 5e29146127 | |||
| 421619e6e3 | |||
| 39ffa8c6e3 | |||
| 53e622ba88 | |||
| 3f70323ba7 | |||
| 99d1a03857 | |||
| a2ddeab20e | |||
| bb05597274 | |||
| cb8c503098 | |||
| dfe3389cf5 | |||
| aac5333538 | |||
| c9038ad429 | |||
| 6d0a80dfc1 | |||
| f22286dd83 | |||
| c4030220a4 | |||
| e088a1f198 | |||
| b6f35bf63e | |||
| b5282bfb67 | |||
| 5721a09e82 | |||
| 21e4f90ca8 | |||
| 9cb0f99c37 | |||
| 4c66ff31c8 | |||
| 2542cb94e4 | |||
| 97be43646f | |||
| 4b1adeef8d | |||
| 0ef5bc0b18 | |||
| 8632026272 | |||
| 706ba3f3af | |||
| c2c97dee39 | |||
| c74949b071 | |||
| 6dc3988fa0 | |||
| 1d59ae4286 | |||
| 38d309036c | |||
| 3c2fa60af3 | |||
| a9b2db5880 | |||
| 3482ea90a6 | |||
| c50377f55f | |||
| 2a9787beee | |||
| 73df15dd67 | |||
| 3fe9524aaf | |||
| 0ec785bfa5 | |||
| c6fa9f2ea2 | |||
| c485c0c443 | |||
| 474ec7e94b | |||
| d7b6ef5729 | |||
| fb6ae10135 | |||
| cadff587be | |||
| 74fbce7560 | |||
| 6ede900c49 | |||
| 4f7cf4088d | |||
| 76486ab639 | |||
| a3809c4fc6 | |||
| b80a22f5ba | |||
| ef6bdbae8e | |||
| 85abbf80e2 | |||
| f2757d51a9 | |||
| 24e83b2807 | |||
| 4e37604528 | |||
| 8b2ae94442 | |||
| 4dec82b25b | |||
| e3796a0678 | |||
| 104c9ffae9 | |||
| c5a4536bb8 | |||
| 740db2e5c3 | |||
| 9fc60dfeb1 | |||
| c270b92ddb | |||
| 835d570210 | |||
| 7a81bcdb34 | |||
| 9818499ed8 | |||
| 5e0c2c9815 | |||
| 50e48b78e9 | |||
| f3a11484ad | |||
| af9b4f1f3b | |||
| 25c946f628 | |||
| 110f3a3d68 | |||
| b20a4bc15c | |||
| d4315bf53e | |||
| f31105a9f5 | |||
| 771c8455cb | |||
| 8297de9fa3 | |||
| e336f07cd7 | |||
| 2ff2c49c85 | |||
| 2f7aaf1d53 | |||
| 551f57926a | |||
| b8daa178de | |||
| 8405e6f1cc | |||
| 89076b49fb | |||
| 8fc16d9e6a | |||
| 5136441985 | |||
| 1afa3903ae | |||
| 4c32762ca7 | |||
| 313531b030 | |||
| 2b37ee6049 | |||
| a5f3967e57 | |||
| 5b78584fdb | |||
| ce390c4725 | |||
| 942d4df55b | |||
| 23628a98fc | |||
| 2daceaf000 | |||
| 8675c2c908 | |||
| 70ffd8bb2b | |||
| 6c1aa273f2 | |||
| 8cc2d39207 | |||
| cac9523423 | |||
| cb4bb6efc5 | |||
| 750121698f | |||
| a78f6cd123 | |||
| c2fea8ae43 | |||
| 0a520053cb | |||
| 1da4edbaf0 | |||
| 9eff7d9535 | |||
| e154204728 | |||
| 2d90a7d91a | |||
| 8ac7c623d3 | |||
| caa9881c0d | |||
| b01258d7f0 | |||
| f0188d7b66 | |||
| 4e52235a23 | |||
| ab94fee038 | |||
| 2d64d63373 | |||
| 6cb165d681 | |||
| 55fc303a5f | |||
| c453ea21e1 | |||
| 24e4ec9d60 | |||
| 25e9be8ea9 | |||
| 9ffcaa7db7 | |||
| 936d21d2dd | |||
| d20b4b2f23 | |||
| d587c4bd90 | |||
| 3828033e98 | |||
| 4892662238 | |||
| ccbd142a63 | |||
| 3b52f52351 | |||
| 173968b25d | |||
| 4cdd9e77dc | |||
| 7805012e59 | |||
| 483d8fefa8 | |||
| 654eac4f13 | |||
| 86699bedb0 | |||
| 914e26d916 | |||
| ced6691934 | |||
| 07e1fa272f | |||
| ff1fbf2992 | |||
| 49e435c00a | |||
| b67ae5a0ad | |||
| b2b1bb2d29 | |||
| 5a13884a0f | |||
| d42328e223 | |||
| 3879b520b7 | |||
| 6a3cffd3c6 | |||
| 40790755ce | |||
| 310a1f0895 | |||
| ed3468e40b | |||
| 9bedb84419 | |||
| c843630aee | |||
| 94f5d062bd | |||
| 233847bdb7 | |||
| f29d518ba8 | |||
| 749c7cc5a9 | |||
| bb3ce79c7e | |||
| 4b52a5b2c6 | |||
| af344834e1 | |||
| cdc9e56198 | |||
| 0e0fd72d98 | |||
| 543005a342 | |||
| 5c33665a74 | |||
| 362518ef34 | |||
| ff246f2260 | |||
| fc1b13ede9 | |||
| 458b0fb900 | |||
| 5df53c769e | |||
| 380a437428 | |||
| 5f6539e379 | |||
| b44ddd4a7f | |||
| 833e2398ef | |||
| df9443db71 | |||
| 4d23edfb37 | |||
| 11489b20a5 | |||
| b3483e7ede | |||
| dd05e0d29e | |||
| 1b37fe78f9 | |||
| 82f21031a3 | |||
| 6545e50f62 | |||
| 3d7630a158 | |||
| 2588126d66 | |||
| de71bef7cb | |||
| e310f10818 | |||
| 9b6938f99b | |||
| 9c42327dd1 | |||
| 28631a1455 | |||
| aa7deee9cc | |||
| 009a9ca500 | |||
| 7de4759799 | |||
| 33433bb8a1 | |||
| 9efe4b84ce | |||
| 12d4fe9ee6 | |||
| 8793e120b9 | |||
| 43f742e1e5 | |||
| 3f4db3e89e | |||
| bea7b33840 | |||
| 4900f375d7 | |||
| a94b1fed30 | |||
| 9337d85eb3 | |||
| 2a8f28520d | |||
| e972b9e909 | |||
| 74c35a9133 | |||
| b4b5124c73 | |||
| af963ad2ae | |||
| 2341e8695e | |||
| f55516fd46 | |||
| 36e337b176 | |||
| 23e9fea9a5 | |||
| 1408aa8bc8 | |||
| 2f86cad04e | |||
| fd77e38fc9 | |||
| 0191113d24 | |||
| 016e029ea6 | |||
| 8bc0bbf1ee | |||
| 1dc4c34d07 | |||
| 5339d26259 | |||
| bc7a379947 | |||
| e9553d973a | |||
| 4f7fa18201 | |||
| 697a28aadf | |||
| 26f5750319 | |||
| d4fea9b20f | |||
| af280e5929 | |||
| fa8d508f36 | |||
| e7bf43ba0d | |||
| 793da897d1 | |||
| e1aa99e99d | |||
| 06b8272791 | |||
| 15703fb9f1 | |||
| 20d8c489d8 | |||
| 1d97a7818e | |||
| 7c64406d4d | |||
| f71b39b960 | |||
| 44dd58756b | |||
| 1dbbcaf9ba | |||
| d0e1b2921d | |||
| 72107631d7 | |||
| 888cfdc75f | |||
| 9886790075 | |||
| f3323c22fe | |||
| d8e011f721 | |||
| 3b63cb559e | |||
| f5189e3aa3 | |||
| 2c643bb988 | |||
| 54e6ea018d | |||
| c5fd53af5d | |||
| e275b0c4a6 | |||
| 9482a77a04 | |||
| fab105578b | |||
| b4dcfe9a06 | |||
| a31a20a5c6 | |||
| e6e7a85087 | |||
| 612c718696 | |||
| 180988c999 | |||
| 59380a9a64 | |||
| d2593fadb6 | |||
| 904aec69a0 | |||
| d851bb5c2a | |||
| 6fa61e69a7 | |||
| c0e65fbbf8 | |||
| cc0b367755 | |||
| 1dc3e88cca | |||
| d04e88b78f | |||
| d77209e8c5 | |||
| 3f27598353 | |||
| 334ced71a1 | |||
| f3a817e959 | |||
| 9712975595 | |||
| 4656db12e1 | |||
| a1ec9e389e | |||
| 3714b3d104 | |||
| 251358b364 | |||
| d2b6ce1555 | |||
| 3c22418e0a | |||
| 94269e4505 | |||
| 0f272f06ea | |||
| 08ca997c76 | |||
| 7d52baba45 | |||
| 72f73d595d | |||
| bf67536031 | |||
| 7a78ae6c10 | |||
| 2cdbfd1dca | |||
| d8924ce166 | |||
| 9ccbf4386c | |||
| fe9d8a7274 | |||
| 9ec5fa2208 | |||
| bffc50ae9d | |||
| a634c88ced | |||
| 2eb7c6d6cb | |||
| 8ae9044ef4 | |||
| eef776a0b4 | |||
| ef57748905 | |||
| 9903e25871 | |||
| 557a9b5674 | |||
| 0ff993ffe3 | |||
| a8a9876c1d | |||
| fd308528cd | |||
| b0f0c2af7e | |||
| ba5dde0347 | |||
| 22cab09558 | |||
| b02f319b78 | |||
| e03ef397fc | |||
| cddd2b461b | |||
| ec41f1ce1b | |||
| 7ce29a90af | |||
| 4dda9579b3 | |||
| 9b77f93fa0 | |||
| 4fc3adb35b | |||
| d3e3f0f109 | |||
| 8bc2ee1a4a | |||
| 93e51e74b4 | |||
| 148ef43015 | |||
| 8b5dfd0b06 | |||
| 1ebd063f4e | |||
| 40579dc143 | |||
| f26629e665 | |||
| ab96a452c6 | |||
| 50e1bbb583 | |||
| 09b6fbdaca | |||
| 8f9c8a5826 | |||
| 9c607c0b8c | |||
| 6dc178e448 | |||
| 187d2a26c0 | |||
| c6755d6f34 | |||
| bea2c40f53 | |||
| 363622d03e | |||
| 649c96c259 | |||
| ac32f752d9 | |||
| db79038541 | |||
| c390ae4f8d | |||
| e0a8cfdb6d | |||
| 52f03c6fc6 | |||
| 9f2c4a9277 | |||
| 575e209b93 | |||
| 0b363e6c4b | |||
| 5d8821ae05 | |||
| 512a916207 | |||
| 86a7cf0909 | |||
| f93f81a9f6 | |||
| bf6f0f03cf | |||
| 903182e4a3 | |||
| e7554e4b67 | |||
| 167420bd2e | |||
| f479887c77 | |||
| 5441c8fef4 | |||
| b104cede75 | |||
| c3c8223ca2 | |||
| d4773c32d6 | |||
| c8511e2808 | |||
| b23e6519fe | |||
| dc7c48a9d7 | |||
| a210233bfb | |||
| 9dcf28af7d | |||
| c030a94b68 | |||
| bd8b3a91e0 | |||
| 582eb6e6e2 | |||
| 9b127bcb70 | |||
| 171a764049 | |||
| 0da8ef69a8 | |||
| 815be4e003 | |||
| d897846115 | |||
| 5427855d50 | |||
| 6d7093e370 | |||
| d7c805a9f0 | |||
| 2032603ae9 | |||
| e7e91b8bae | |||
| 30cbfbdd61 | |||
| ab7694d82e | |||
| 61ee9a304e | |||
| f59bc1b152 | |||
| 3aa57f20af | |||
| b875ad18b5 | |||
| 2d69b0fbe7 | |||
| c8663da1a9 | |||
| 1de2735b16 | |||
| 4a5adabe95 | |||
| b566d8002a | |||
| 2e404995a0 | |||
| 654ad71526 | |||
| 2b50975563 | |||
| 81fb99ed66 | |||
| deb358f16c |
@@ -9,8 +9,6 @@ auth/cas/CAS/
|
||||
enrol/lti/ims-blti/
|
||||
filter/algebra/AlgParser.pm
|
||||
filter/tex/mimetex.*
|
||||
lib/editor/atto/plugins/html/yui/src/codemirror/
|
||||
lib/editor/atto/plugins/html/yui/src/beautify/
|
||||
lib/editor/atto/yui/src/rangy/js/*.*
|
||||
lib/editor/tinymce/plugins/pdw/tinymce/
|
||||
lib/editor/tinymce/plugins/spellchecker/rpc.php
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
# Generated by "grunt ignorefiles"
|
||||
**/yui/build/*
|
||||
theme/bootstrapbase/style/
|
||||
theme/clean/style/custom.css
|
||||
theme/more/style/custom.css
|
||||
@@ -12,8 +11,6 @@ auth/cas/CAS/
|
||||
enrol/lti/ims-blti/
|
||||
filter/algebra/AlgParser.pm
|
||||
filter/tex/mimetex.*
|
||||
lib/editor/atto/plugins/html/yui/src/codemirror/
|
||||
lib/editor/atto/plugins/html/yui/src/beautify/
|
||||
lib/editor/atto/yui/src/rangy/js/*.*
|
||||
lib/editor/tinymce/plugins/pdw/tinymce/
|
||||
lib/editor/tinymce/plugins/spellchecker/rpc.php
|
||||
|
||||
+1
-3
@@ -207,7 +207,7 @@ before_script:
|
||||
# We need the official upstream for comparison
|
||||
git remote add upstream https://github.com/moodle/moodle.git;
|
||||
|
||||
git fetch upstream MOODLE_36_STABLE;
|
||||
git fetch upstream MOODLE_35_STABLE;
|
||||
export GIT_PREVIOUS_COMMIT="`git merge-base FETCH_HEAD $TRAVIS_COMMIT`";
|
||||
export GIT_COMMIT="$TRAVIS_COMMIT";
|
||||
export UPSTREAM_FETCH_HEAD=`git rev-parse FETCH_HEAD`
|
||||
@@ -263,9 +263,7 @@ script:
|
||||
grunt ;
|
||||
# Add all files to the git index and then run diff --cached to see all changes.
|
||||
# This ensures that we get the status of all files, including new files.
|
||||
# We ignore npm-shrinkwrap.json to make the tasks immune to npm changes.
|
||||
git add . ;
|
||||
git reset -- npm-shrinkwrap.json ;
|
||||
git diff --cached --exit-code ;
|
||||
fi
|
||||
|
||||
|
||||
+1
-2
@@ -37,7 +37,7 @@ module.exports = function(grunt) {
|
||||
var expected = semver.validRange(grunt.file.readJSON('package.json').engines.node);
|
||||
var actual = semver.valid(process.version);
|
||||
if (!semver.satisfies(actual, expected)) {
|
||||
grunt.fail.fatal('Node version not satisfied. Require ' + expected + ', version installed: ' + actual);
|
||||
grunt.fail.fatal('Node version too old. Require ' + expected + ', version installed: ' + actual);
|
||||
}
|
||||
|
||||
// Windows users can't run grunt in a subdirectory, so allow them to set
|
||||
@@ -222,7 +222,6 @@ module.exports = function(grunt) {
|
||||
// Generate .stylelintignore.
|
||||
var stylelintIgnores = [
|
||||
'# Generated by "grunt ignorefiles"',
|
||||
'**/yui/build/*',
|
||||
'theme/bootstrapbase/style/',
|
||||
'theme/clean/style/custom.css',
|
||||
'theme/more/style/custom.css',
|
||||
|
||||
@@ -1,75 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Form for selective purging of caches.
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2018 The Open University
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_admin\form;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
/**
|
||||
* Form for selecting which caches to purge on admin/purgecaches.php
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2018 The Open University
|
||||
* @author Mark Johnson <mark.johnson@open.ac.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class purge_caches extends \moodleform {
|
||||
/**
|
||||
* Define a "Purge all caches" button, and a fieldset with checkboxes for selectively purging separate caches.
|
||||
*/
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
$mform->addElement('hidden', 'returnurl', $this->_customdata['returnurl']);
|
||||
$mform->setType('returnurl', PARAM_LOCALURL);
|
||||
$mform->addElement('submit', 'all', get_string('purgecaches', 'admin'));
|
||||
$mform->addElement('header', 'purgecacheheader', get_string('purgeselectedcaches', 'admin'));
|
||||
$checkboxes = [
|
||||
$mform->createElement('advcheckbox', 'theme', '', get_string('purgethemecache', 'admin')),
|
||||
$mform->createElement('advcheckbox', 'lang', '', get_string('purgelangcache', 'admin')),
|
||||
$mform->createElement('advcheckbox', 'js', '', get_string('purgejscache', 'admin')),
|
||||
$mform->createElement('advcheckbox', 'filter', '', get_string('purgefiltercache', 'admin')),
|
||||
$mform->createElement('advcheckbox', 'muc', '', get_string('purgemuc', 'admin')),
|
||||
$mform->createElement('advcheckbox', 'other', '', get_string('purgeothercaches', 'admin'))
|
||||
];
|
||||
$mform->addGroup($checkboxes, 'purgeselectedoptions');
|
||||
$mform->addElement('submit', 'purgeselectedcaches', get_string('purgeselectedcaches', 'admin'));
|
||||
}
|
||||
|
||||
/**
|
||||
* If the "Purge selected caches" button was pressed, ensure at least one cache was selected.
|
||||
*
|
||||
* @param array $data
|
||||
* @param array $files
|
||||
* @return array Error messages
|
||||
*/
|
||||
public function validation($data, $files) {
|
||||
$errors = [];
|
||||
if (isset($data['purgeselectedcaches']) && empty(array_filter($data['purgeselectedoptions']))) {
|
||||
$errors['purgeselectedoptions'] = get_string('purgecachesnoneselected', 'admin');
|
||||
}
|
||||
return $errors;
|
||||
}
|
||||
}
|
||||
@@ -28,16 +28,7 @@ define('CLI_SCRIPT', true);
|
||||
require(__DIR__.'/../../config.php');
|
||||
require_once($CFG->libdir.'/clilib.php');
|
||||
|
||||
$longoptions = [
|
||||
'help' => false,
|
||||
'muc' => false,
|
||||
'theme' => false,
|
||||
'lang' => false,
|
||||
'js' => false,
|
||||
'filter' => false,
|
||||
'other' => false
|
||||
];
|
||||
list($options, $unrecognized) = cli_get_params($longoptions, ['h' => 'help']);
|
||||
list($options, $unrecognized) = cli_get_params(array('help' => false), array('h' => 'help'));
|
||||
|
||||
if ($unrecognized) {
|
||||
$unrecognized = implode("\n ", $unrecognized);
|
||||
@@ -45,32 +36,20 @@ if ($unrecognized) {
|
||||
}
|
||||
|
||||
if ($options['help']) {
|
||||
// The indentation of this string is "wrong" but this is to avoid a extra whitespace in console output.
|
||||
$help = <<<EOF
|
||||
Invalidates Moodle internal caches
|
||||
|
||||
Specific caches can be defined (alone or in combination) using arguments. If none are specified,
|
||||
all caches will be purged.
|
||||
$help =
|
||||
"Invalidates all Moodle internal caches
|
||||
|
||||
Options:
|
||||
-h, --help Print out this help
|
||||
--muc Purge all MUC caches (includes lang cache)
|
||||
--theme Purge theme cache
|
||||
--lang Purge language string cache
|
||||
--js Purge JavaScript cache
|
||||
--filter Purge text filter cache
|
||||
--other Purge all file caches and other miscellaneous caches (may include MUC
|
||||
if using cachestore_file).
|
||||
|
||||
Example:
|
||||
\$ sudo -u www-data /usr/bin/php admin/cli/purge_caches.php
|
||||
|
||||
EOF;
|
||||
\$sudo -u www-data /usr/bin/php admin/cli/purge_caches.php
|
||||
";
|
||||
|
||||
echo $help;
|
||||
exit(0);
|
||||
}
|
||||
|
||||
purge_caches(array_filter($options));
|
||||
purge_all_caches();
|
||||
|
||||
exit(0);
|
||||
|
||||
+4
-23
@@ -51,8 +51,7 @@ list($options, $unrecognized) = cli_get_params(
|
||||
'non-interactive' => false,
|
||||
'allow-unstable' => false,
|
||||
'help' => false,
|
||||
'lang' => $lang,
|
||||
'verbose-settings' => false
|
||||
'lang' => $lang
|
||||
),
|
||||
array(
|
||||
'h' => 'help'
|
||||
@@ -85,9 +84,6 @@ Options:
|
||||
site language if not set. Defaults to 'en' if the lang
|
||||
parameter is invalid or if the language pack is not
|
||||
installed.
|
||||
--verbose-settings Show new settings values. By default only the name of
|
||||
new core or plugin settings are displayed. This option
|
||||
outputs the new values as well as the setting name.
|
||||
-h, --help Print out this help
|
||||
|
||||
Example:
|
||||
@@ -188,24 +184,9 @@ upgrade_noncore(true);
|
||||
// log in as admin - we need doanything permission when applying defaults
|
||||
\core\session\manager::set_user(get_admin());
|
||||
|
||||
// Apply default settings and output those that have changed.
|
||||
cli_heading(get_string('cliupgradedefaultheading', 'admin'));
|
||||
$settingsoutput = admin_apply_default_settings(null, false);
|
||||
|
||||
foreach ($settingsoutput as $setting => $value) {
|
||||
|
||||
if ($options['verbose-settings']) {
|
||||
$stringvlaues = array(
|
||||
'name' => $setting,
|
||||
'defaultsetting' => var_export($value, true) // Expand objects.
|
||||
);
|
||||
echo get_string('cliupgradedefaultverbose', 'admin', $stringvlaues) . PHP_EOL;
|
||||
|
||||
} else {
|
||||
echo get_string('cliupgradedefault', 'admin', $setting) . PHP_EOL;
|
||||
|
||||
}
|
||||
}
|
||||
// apply all default settings, just in case do it twice to fill all defaults
|
||||
admin_apply_default_settings(NULL, false);
|
||||
admin_apply_default_settings(NULL, false);
|
||||
|
||||
// This needs to happen at the end to ensure it occurs after all caches
|
||||
// have been purged for the last time.
|
||||
|
||||
@@ -2097,7 +2097,6 @@
|
||||
<VENDOR name="oracle" version="10.2" />
|
||||
</DATABASE>
|
||||
<PHP version="7.0.0" level="required">
|
||||
<RESTRICT function="restrict_php_version_73" message="unsupportedphpversion73" />
|
||||
</PHP>
|
||||
<PCREUNICODE level="optional">
|
||||
<FEEDBACK>
|
||||
@@ -2274,7 +2273,6 @@
|
||||
<VENDOR name="oracle" version="10.2" />
|
||||
</DATABASE>
|
||||
<PHP version="7.0.0" level="required">
|
||||
<RESTRICT function="restrict_php_version_73" message="unsupportedphpversion73" />
|
||||
</PHP>
|
||||
<PCREUNICODE level="optional">
|
||||
<FEEDBACK>
|
||||
|
||||
@@ -28,6 +28,10 @@ require_once($CFG->libdir . '/adminlib.php');
|
||||
$action = optional_param('action', '', PARAM_ALPHA);
|
||||
$filterpath = optional_param('filterpath', '', PARAM_PLUGIN);
|
||||
|
||||
require_login();
|
||||
$systemcontext = context_system::instance();
|
||||
require_capability('moodle/site:config', $systemcontext);
|
||||
|
||||
admin_externalpage_setup('managefilters');
|
||||
|
||||
// Clean up bogus filter states first.
|
||||
|
||||
@@ -1,96 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This file is used to display a categories sub categories, external pages, and settings.
|
||||
*
|
||||
* @package admin
|
||||
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once('../config.php');
|
||||
require_once("{$CFG->libdir}/adminlib.php");
|
||||
|
||||
$contextid = required_param('id', PARAM_INT);
|
||||
$confirm = optional_param('confirm', null, PARAM_INT);
|
||||
$returnurl = optional_param('returnurl', null, PARAM_LOCALURL);
|
||||
|
||||
$PAGE->set_url('/admin/lock.php', ['id' => $contextid]);
|
||||
|
||||
list($context, $course, $cm) = get_context_info_array($contextid);
|
||||
|
||||
$parentcontext = $context->get_parent_context();
|
||||
if ($parentcontext && !empty($parentcontext->locked)) {
|
||||
// Can't make changes to a context whose parent is locked.
|
||||
throw new \coding_exception('Not sure how you got here');
|
||||
}
|
||||
|
||||
if ($course) {
|
||||
$isfrontpage = ($course->id == SITEID);
|
||||
} else {
|
||||
$isfrontpage = false;
|
||||
$course = $SITE;
|
||||
}
|
||||
|
||||
require_login($course, false, $cm);
|
||||
require_capability('moodle/site:managecontextlocks', $context);
|
||||
|
||||
$PAGE->set_pagelayout('admin');
|
||||
$PAGE->navigation->clear_cache();
|
||||
|
||||
$a = (object) [
|
||||
'contextname' => $context->get_context_name(),
|
||||
];
|
||||
|
||||
if (null !== $confirm && confirm_sesskey()) {
|
||||
$context->set_locked(!empty($confirm));
|
||||
|
||||
if ($context->locked) {
|
||||
$lockmessage = get_string('managecontextlocklocked', 'admin', $a);
|
||||
} else {
|
||||
$lockmessage = get_string('managecontextlockunlocked', 'admin', $a);
|
||||
}
|
||||
|
||||
if (empty($returnurl)) {
|
||||
$returnurl = $context->get_url();
|
||||
} else {
|
||||
$returnurl = new moodle_url($returnurl);
|
||||
}
|
||||
redirect($returnurl, $lockmessage);
|
||||
}
|
||||
|
||||
$heading = get_string('managecontextlock', 'admin');
|
||||
$PAGE->set_title($heading);
|
||||
$PAGE->set_heading($heading);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
if ($context->locked) {
|
||||
$confirmstring = get_string('confirmcontextunlock', 'admin', $a);
|
||||
$target = 0;
|
||||
} else {
|
||||
$confirmstring = get_string('confirmcontextlock', 'admin', $a);
|
||||
$target = 1;
|
||||
}
|
||||
|
||||
$confirmurl = new \moodle_url($PAGE->url, ['confirm' => $target]);
|
||||
if (!empty($returnurl)) {
|
||||
$confirmurl->param('returnurl', $returnurl);
|
||||
}
|
||||
|
||||
echo $OUTPUT->confirm($confirmstring, $confirmurl, $context->get_url());
|
||||
echo $OUTPUT->footer();
|
||||
@@ -28,6 +28,9 @@ require_once($CFG->libdir.'/adminlib.php');
|
||||
// This is an admin page
|
||||
admin_externalpage_setup('managemessageoutputs');
|
||||
|
||||
// Require site configuration capability
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
// Get the submitted params
|
||||
$disable = optional_param('disable', 0, PARAM_INT);
|
||||
$enable = optional_param('enable', 0, PARAM_INT);
|
||||
|
||||
@@ -12,6 +12,8 @@ $page = optional_param('page', 0, PARAM_INT);
|
||||
$perpage = optional_param('perpage', 30, PARAM_INT);
|
||||
$action = trim(strtolower(optional_param('action', '', PARAM_ALPHA)));
|
||||
|
||||
require_login();
|
||||
|
||||
admin_externalpage_setup('ssoaccesscontrol');
|
||||
|
||||
if (!extension_loaded('openssl')) {
|
||||
|
||||
@@ -34,8 +34,10 @@ $step = optional_param('step', 'verify', PARAM_ALPHA);
|
||||
$hostid = required_param('hostid', PARAM_INT);
|
||||
|
||||
|
||||
require_login();
|
||||
|
||||
$context = context_system::instance();
|
||||
require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
|
||||
|
||||
$mnet = get_mnet_environment();
|
||||
|
||||
|
||||
@@ -6,10 +6,12 @@
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
include_once($CFG->dirroot.'/mnet/lib.php');
|
||||
|
||||
require_login();
|
||||
admin_externalpage_setup('net');
|
||||
|
||||
$context = context_system::instance();
|
||||
|
||||
require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
|
||||
|
||||
$site = get_site();
|
||||
$mnet = get_mnet_environment();
|
||||
|
||||
@@ -32,6 +32,10 @@ require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->dirroot.'/mnet/lib.php');
|
||||
require_once($CFG->dirroot.'/'.$CFG->admin.'/mnet/peer_forms.php');
|
||||
|
||||
require_login();
|
||||
|
||||
$context = context_system::instance();
|
||||
require_capability('moodle/site:config', $context, $USER->id, true, 'nopermissions');
|
||||
|
||||
/// Initialize variables.
|
||||
$hostid = optional_param('hostid', 0, PARAM_INT);
|
||||
|
||||
@@ -29,10 +29,14 @@ require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->dirroot . '/' . $CFG->admin .'/mnet/profilefields_form.php');
|
||||
$mnet = get_mnet_environment();
|
||||
|
||||
require_login();
|
||||
$hostid = required_param('hostid', PARAM_INT);
|
||||
$mnet_peer = new mnet_peer();
|
||||
$mnet_peer->set_id($hostid);
|
||||
|
||||
$context = context_system::instance();
|
||||
|
||||
require_capability('moodle/site:config', $context, $USER->id, true, 'nopermissions');
|
||||
admin_externalpage_setup('mnetpeers');
|
||||
$form = new mnet_profile_form(null, array('hostid' => $hostid));
|
||||
|
||||
|
||||
@@ -30,8 +30,11 @@ require_once($CFG->libdir.'/adminlib.php');
|
||||
require_once($CFG->dirroot . '/' . $CFG->admin . '/mnet/services_form.php');
|
||||
$mnet = get_mnet_environment();
|
||||
|
||||
require_login();
|
||||
admin_externalpage_setup('mnetpeers');
|
||||
|
||||
$context = context_system::instance();
|
||||
require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
|
||||
|
||||
$hostid = required_param('hostid', PARAM_INT);
|
||||
|
||||
|
||||
@@ -21,8 +21,12 @@ if ($CFG->mnet_dispatcher_mode === 'off') {
|
||||
print_error('mnetdisabled', 'mnet');
|
||||
}
|
||||
|
||||
require_login();
|
||||
admin_externalpage_setup('mnettestclient');
|
||||
|
||||
$context = context_system::instance();
|
||||
require_capability('moodle/site:config', $context);
|
||||
|
||||
error_reporting(DEBUG_ALL);
|
||||
|
||||
echo $OUTPUT->header();
|
||||
|
||||
@@ -5,8 +5,12 @@
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
include_once($CFG->dirroot.'/mnet/lib.php');
|
||||
|
||||
require_login();
|
||||
admin_externalpage_setup('trustedhosts');
|
||||
|
||||
$context = context_system::instance();
|
||||
|
||||
require_capability('moodle/site:config', $context, $USER->id, true, "nopermissions");
|
||||
|
||||
if (!extension_loaded('openssl')) {
|
||||
echo $OUTPUT->header();
|
||||
|
||||
+1
-5
@@ -87,13 +87,9 @@
|
||||
$table->set_attribute('class', 'admintable generaltable');
|
||||
$table->setup();
|
||||
|
||||
$pluginmanager = core_plugin_manager::instance();
|
||||
|
||||
foreach ($modules as $module) {
|
||||
$plugininfo = $pluginmanager->get_plugin_info('mod_'.$module->name);
|
||||
$status = $plugininfo->get_status();
|
||||
|
||||
if ($status === core_plugin_manager::PLUGIN_STATUS_MISSING) {
|
||||
if (!file_exists("$CFG->dirroot/mod/$module->name/lib.php")) {
|
||||
$strmodulename = '<span class="notifyproblem">'.$module->name.' ('.get_string('missingfromdisk').')</span>';
|
||||
$missing = true;
|
||||
} else {
|
||||
|
||||
@@ -35,6 +35,8 @@ if ($action == 'newon') {
|
||||
|
||||
admin_externalpage_setup($pagename);
|
||||
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
|
||||
$baseurl = "$CFG->wwwroot/$CFG->admin/portfolio.php";
|
||||
$sesskeyurl = "$CFG->wwwroot/$CFG->admin/portfolio.php?sesskey=" . sesskey();
|
||||
$configstr = get_string('manageportfolios', 'portfolio');
|
||||
|
||||
+13
-20
@@ -27,43 +27,36 @@ require_once('../config.php');
|
||||
require_once($CFG->libdir.'/adminlib.php');
|
||||
|
||||
$confirm = optional_param('confirm', 0, PARAM_BOOL);
|
||||
$returnurl = optional_param('returnurl', '/admin/purgecaches.php', PARAM_LOCALURL);
|
||||
$returnurl = new moodle_url($returnurl);
|
||||
$returnurl = optional_param('returnurl', null, PARAM_LOCALURL);
|
||||
|
||||
admin_externalpage_setup('purgecaches');
|
||||
|
||||
$form = new core_admin\form\purge_caches(null, ['returnurl' => $returnurl]);
|
||||
|
||||
// If we have got here as a confirmed aciton, do it.
|
||||
if ($data = $form->get_data()) {
|
||||
if ($confirm && confirm_sesskey()) {
|
||||
|
||||
// Valid request. Purge, and redirect the user back to where they came from.
|
||||
$selected = $data->purgeselectedoptions;
|
||||
purge_caches($selected);
|
||||
purge_all_caches();
|
||||
|
||||
if (isset($data->all)) {
|
||||
$message = get_string('purgecachesfinished', 'admin');
|
||||
if ($returnurl) {
|
||||
$returnurl = $CFG->wwwroot . $returnurl;
|
||||
} else {
|
||||
$message = get_string('purgeselectedcachesfinished', 'admin');
|
||||
$returnurl = new moodle_url('/admin/purgecaches.php');
|
||||
}
|
||||
|
||||
} else if ($confirm && confirm_sesskey()) {
|
||||
purge_caches();
|
||||
$message = get_string('purgecachesfinished', 'admin');
|
||||
redirect($returnurl, get_string('purgecachesfinished', 'admin'));
|
||||
}
|
||||
|
||||
if (isset($message)) {
|
||||
redirect($returnurl, $message);
|
||||
// Otherwise, show a button to actually purge the caches.
|
||||
$actionurl = new moodle_url('/admin/purgecaches.php', array('sesskey'=>sesskey(), 'confirm'=>1));
|
||||
if ($returnurl) {
|
||||
$actionurl->param('returnurl', $returnurl);
|
||||
}
|
||||
|
||||
// Otherwise, show a form to actually purge the caches.
|
||||
|
||||
echo $OUTPUT->header();
|
||||
echo $OUTPUT->heading(get_string('purgecachespage', 'admin'));
|
||||
echo $OUTPUT->heading(get_string('purgecaches', 'admin'));
|
||||
|
||||
echo $OUTPUT->box_start('generalbox', 'notice');
|
||||
echo html_writer::tag('p', get_string('purgecachesconfirm', 'admin'));
|
||||
echo $form->render();
|
||||
echo $OUTPUT->single_button($actionurl, get_string('purgecaches', 'admin'), 'post');
|
||||
echo $OUTPUT->box_end();
|
||||
|
||||
echo $OUTPUT->footer();
|
||||
|
||||
@@ -31,6 +31,7 @@ require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->libdir . '/tablelib.php');
|
||||
|
||||
// Check permissions.
|
||||
require_login();
|
||||
$systemcontext = context_system::instance();
|
||||
require_capability('moodle/question:config', $systemcontext);
|
||||
$canviewreports = has_capability('report/questioninstances:view', $systemcontext);
|
||||
|
||||
@@ -47,6 +47,7 @@ if ($action == 'newon') {
|
||||
$visible = false;
|
||||
}
|
||||
|
||||
require_capability('moodle/site:config', context_system::instance());
|
||||
admin_externalpage_setup($pagename);
|
||||
|
||||
$sesskeyurl = $CFG->wwwroot.'/'.$CFG->admin.'/repository.php?sesskey=' . sesskey();
|
||||
|
||||
@@ -42,6 +42,7 @@ if ($edit){
|
||||
}
|
||||
|
||||
admin_externalpage_setup($pagename, '', null, new moodle_url('/admin/repositoryinstance.php'));
|
||||
require_capability('moodle/site:config', $context);
|
||||
|
||||
$baseurl = new moodle_url("/$CFG->admin/repositoryinstance.php", array('sesskey'=>sesskey()));
|
||||
|
||||
|
||||
@@ -80,16 +80,9 @@ if (optional_param('add', false, PARAM_BOOL) and confirm_sesskey()) {
|
||||
}
|
||||
|
||||
if (isset($admins[$newmain])) {
|
||||
$logstringold = implode(', ', $admins);
|
||||
|
||||
unset($admins[$newmain]);
|
||||
array_unshift($admins, $newmain);
|
||||
|
||||
$logstringnew = implode(', ', $admins);
|
||||
|
||||
set_config('siteadmins', implode(',', $admins));
|
||||
add_to_config_log('siteadmins', $logstringold, $logstringnew, null);
|
||||
|
||||
redirect($PAGE->url);
|
||||
}
|
||||
}
|
||||
@@ -102,16 +95,8 @@ if (optional_param('add', false, PARAM_BOOL) and confirm_sesskey()) {
|
||||
$admins[$admin] = $admin;
|
||||
}
|
||||
}
|
||||
|
||||
$logstringold = implode(', ', $admins);
|
||||
|
||||
$admins[$confirmadd] = $confirmadd;
|
||||
|
||||
$logstringnew = implode(', ', $admins);
|
||||
|
||||
set_config('siteadmins', implode(',', $admins));
|
||||
add_to_config_log('siteadmins', $logstringold, $logstringnew, 'core');
|
||||
|
||||
redirect($PAGE->url);
|
||||
|
||||
} else if ($confirmdel and confirm_sesskey() and $confirmdel != $USER->id) {
|
||||
@@ -122,16 +107,8 @@ if (optional_param('add', false, PARAM_BOOL) and confirm_sesskey()) {
|
||||
$admins[$admin] = $admin;
|
||||
}
|
||||
}
|
||||
|
||||
$logstringold = implode(', ', $admins);
|
||||
|
||||
unset($admins[$confirmdel]);
|
||||
|
||||
$logstringnew = implode(', ', $admins);
|
||||
|
||||
set_config('siteadmins', implode(',', $admins));
|
||||
add_to_config_log('siteadmins', $logstringold, $logstringnew, 'core');
|
||||
|
||||
redirect($PAGE->url);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,6 +46,7 @@ $controller = new $classformode[$mode]();
|
||||
|
||||
if (optional_param('submit', false, PARAM_BOOL) && data_submitted() && confirm_sesskey()) {
|
||||
$controller->process_submission();
|
||||
$syscontext->mark_dirty();
|
||||
$event = null;
|
||||
// Create event depending on mode.
|
||||
switch ($mode) {
|
||||
|
||||
@@ -123,6 +123,9 @@ abstract class core_role_capability_table_with_risks extends core_role_capabilit
|
||||
assign_capability($changedcap, $this->permissions[$changedcap],
|
||||
$this->roleid, $this->context->id, true);
|
||||
}
|
||||
|
||||
// Force accessinfo refresh for users visiting this context.
|
||||
$this->context->mark_dirty();
|
||||
}
|
||||
|
||||
public function display() {
|
||||
|
||||
@@ -434,7 +434,7 @@ class core_role_define_role_table_advanced extends core_role_capability_table_wi
|
||||
}
|
||||
|
||||
public function save_changes() {
|
||||
global $DB;
|
||||
global $DB, $CFG;
|
||||
|
||||
if (!$this->roleid) {
|
||||
// Creating role.
|
||||
@@ -448,7 +448,8 @@ class core_role_define_role_table_advanced extends core_role_capability_table_wi
|
||||
// the UI. It would be better to do this only when we know that fields affected are
|
||||
// updated. But thats getting into the weeds of the coursecat cache and role edits
|
||||
// should not be that frequent, so here is the ugly brutal approach.
|
||||
core_course_category::role_assignment_changed($this->role->id, context_system::instance());
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
coursecat::role_assignment_changed($this->role->id, context_system::instance());
|
||||
}
|
||||
|
||||
// Assignable contexts.
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Privacy Subsystem implementation for core_role.
|
||||
*
|
||||
@@ -21,9 +20,7 @@
|
||||
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace core_role\privacy;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use \core_privacy\local\metadata\collection;
|
||||
@@ -31,8 +28,6 @@ use \core_privacy\local\request\contextlist;
|
||||
use \core_privacy\local\request\approved_contextlist;
|
||||
use \core_privacy\local\request\transform;
|
||||
use \core_privacy\local\request\writer;
|
||||
use \core_privacy\local\request\userlist;
|
||||
use \core_privacy\local\request\approved_userlist;
|
||||
|
||||
/**
|
||||
* Privacy provider for core_role.
|
||||
@@ -44,8 +39,7 @@ class provider implements
|
||||
\core_privacy\local\metadata\provider,
|
||||
\core_privacy\local\request\subsystem\provider,
|
||||
\core_privacy\local\request\subsystem\plugin_provider,
|
||||
\core_privacy\local\request\user_preference_provider,
|
||||
\core_privacy\local\request\core_userlist_provider {
|
||||
\core_privacy\local\request\user_preference_provider {
|
||||
|
||||
/**
|
||||
* Get information about the user data stored by this plugin.
|
||||
@@ -157,50 +151,6 @@ class provider implements
|
||||
|
||||
return $contextlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of users within a specific context.
|
||||
*
|
||||
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
|
||||
*/
|
||||
public static function get_users_in_context(userlist $userlist) {
|
||||
|
||||
if (empty($userlist)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$context = $userlist->get_context();
|
||||
|
||||
// Include users who created or modified role capabilities.
|
||||
$sql = "SELECT modifierid as userid
|
||||
FROM {role_capabilities}
|
||||
WHERE contextid = :contextid";
|
||||
|
||||
$params = [
|
||||
'contextid' => $context->id
|
||||
];
|
||||
|
||||
$userlist->add_from_sql('userid', $sql, $params);
|
||||
|
||||
// Include users that have a role assigned to them.
|
||||
$sql = "SELECT userid
|
||||
FROM {role_assignments}
|
||||
WHERE contextid = :contextid";
|
||||
|
||||
$userlist->add_from_sql('userid', $sql, $params);
|
||||
|
||||
// Include users who created or modified the role assignment.
|
||||
// Differentiate and exclude special cases where tool_cohortroles adds records through the
|
||||
// "Assign user roles to cohort" feature into the role_assignments table.
|
||||
// These records should be separately processed in tool_cohortroles.
|
||||
$sql = "SELECT modifierid as userid
|
||||
FROM {role_assignments}
|
||||
WHERE contextid = :contextid
|
||||
AND component != 'tool_cohortroles'";
|
||||
|
||||
$userlist->add_from_sql('userid', $sql, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Export all user data for the specified user, in the specified contexts.
|
||||
*
|
||||
@@ -365,32 +315,6 @@ class provider implements
|
||||
// Remove data from role_assignments.
|
||||
$DB->delete_records('role_assignments', ['contextid' => $context->id]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete multiple users within a single context.
|
||||
*
|
||||
* @param approved_userlist $userlist The approved context and user information to delete information for.
|
||||
*/
|
||||
public static function delete_data_for_users(approved_userlist $userlist) {
|
||||
global $DB;
|
||||
|
||||
// Don't remove data from role_capabilities.
|
||||
// Because this data affects the whole Moodle, there are override capabilities.
|
||||
// Don't belong to the modifier user.
|
||||
$context = $userlist->get_context();
|
||||
$userids = $userlist->get_userids();
|
||||
|
||||
if (empty($userids)) {
|
||||
return;
|
||||
}
|
||||
list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
|
||||
$params = ['contextid' => $context->id] + $userparams;
|
||||
|
||||
// Remove data from role_assignments.
|
||||
$DB->delete_records_select('role_assignments',
|
||||
"contextid = :contextid AND userid {$usersql}", $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all user data for this user only.
|
||||
*
|
||||
@@ -408,14 +332,10 @@ class provider implements
|
||||
return;
|
||||
}
|
||||
$userid = $contextlist->get_user()->id;
|
||||
$contextids = $contextlist->get_contextids();
|
||||
|
||||
list($contextsql, $contextparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED);
|
||||
$params = ['userid' => $userid] + $contextparams;
|
||||
|
||||
// Only delete the roles assignments where the user is assigned in all contexts.
|
||||
$DB->delete_records_select('role_assignments',
|
||||
"userid = :userid AND contextid {$contextsql}", $params);
|
||||
foreach ($contextlist->get_contexts() as $context) {
|
||||
// Only delete the roles assignments where the user is assigned in all contexts.
|
||||
$DB->delete_records('role_assignments', ['userid' => $userid, 'contextid' => $context->id]);
|
||||
}
|
||||
}
|
||||
/**
|
||||
* Delete user entries in role_assignments related to the feature
|
||||
|
||||
@@ -54,6 +54,7 @@ if ($return === 'manage') {
|
||||
|
||||
// Check access permissions.
|
||||
$systemcontext = context_system::instance();
|
||||
require_login();
|
||||
require_capability('moodle/role:manage', $systemcontext);
|
||||
admin_externalpage_setup('defineroles', '', array('action' => $action, 'roleid' => $roleid), new moodle_url('/admin/roles/define.php'));
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@ $defineurl = $CFG->wwwroot . '/' . $CFG->admin . '/roles/define.php';
|
||||
|
||||
// Check access permissions.
|
||||
$systemcontext = context_system::instance();
|
||||
require_login();
|
||||
require_capability('moodle/role:manage', $systemcontext);
|
||||
admin_externalpage_setup('defineroles');
|
||||
|
||||
@@ -84,10 +85,12 @@ switch ($action) {
|
||||
die;
|
||||
}
|
||||
if (!delete_role($roleid)) {
|
||||
// The delete failed.
|
||||
// The delete failed, but mark the context dirty in case.
|
||||
$systemcontext->mark_dirty();
|
||||
print_error('cannotdeleterolewithid', 'error', $baseurl, $roleid);
|
||||
}
|
||||
// Deleted a role sitewide...
|
||||
$systemcontext->mark_dirty();
|
||||
redirect($baseurl);
|
||||
break;
|
||||
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Privacy test for core_role
|
||||
*
|
||||
@@ -22,16 +21,13 @@
|
||||
* @copyright 2018 Carlos Escobedo <carlos@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use \core_role\privacy\provider;
|
||||
use \core_privacy\local\request\approved_contextlist;
|
||||
use \core_privacy\local\request\writer;
|
||||
use \core_privacy\tests\provider_testcase;
|
||||
use \core_privacy\local\request\transform;
|
||||
use \tool_cohortroles\api;
|
||||
use \core_privacy\local\request\approved_userlist;
|
||||
|
||||
/**
|
||||
* Privacy test for core_role
|
||||
@@ -58,7 +54,6 @@ class core_role_privacy_testcase extends provider_testcase {
|
||||
$this->assertEquals(get_string('privacy:metadata:preference:showadvanced', 'core_role'),
|
||||
$prefs->definerole_showadvanced->description);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check all contexts are returned if there is any user data for this user.
|
||||
*/
|
||||
@@ -236,7 +231,6 @@ class core_role_privacy_testcase extends provider_testcase {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for provider::delete_data_for_all_users_in_context().
|
||||
*/
|
||||
@@ -322,7 +316,6 @@ class core_role_privacy_testcase extends provider_testcase {
|
||||
$count = $DB->count_records('role_assignments', ['contextid' => $usercontext2->id]);
|
||||
$this->assertEquals(0, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for provider::delete_data_for_user().
|
||||
*/
|
||||
@@ -380,7 +373,6 @@ class core_role_privacy_testcase extends provider_testcase {
|
||||
$count = $DB->count_records('role_assignments', ['modifierid' => $user->id]);
|
||||
$this->assertEquals(2, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Export for a user with a key against a script where no instance is specified.
|
||||
*/
|
||||
@@ -434,7 +426,6 @@ class core_role_privacy_testcase extends provider_testcase {
|
||||
$exported = $writer->get_related_data($subcontextteacher, 'cohortroles');
|
||||
$this->assertEquals($user2->id, reset($exported)->userid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for provider::delete_user_role_to_cohort().
|
||||
*/
|
||||
@@ -469,267 +460,6 @@ class core_role_privacy_testcase extends provider_testcase {
|
||||
$count = $DB->count_records('role_assignments', ['userid' => $user->id, 'component' => 'tool_cohortroles']);
|
||||
$this->assertEquals(0, $count);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that only users within a course context are fetched.
|
||||
*/
|
||||
public function test_get_users_in_context() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$component = 'core_role';
|
||||
|
||||
$this->setAdminUser();
|
||||
$admin = \core_user::get_user_by_username('admin');
|
||||
// Create user1.
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
$usercontext1 = \context_user::instance($user1->id);
|
||||
// Create user2.
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$usercontext2 = \context_user::instance($user2->id);
|
||||
// Create course1.
|
||||
$course1 = $this->getDataGenerator()->create_course();
|
||||
$coursecontext1 = \context_course::instance($course1->id);
|
||||
// Create course category.
|
||||
$coursecat = $this->getDataGenerator()->create_category();
|
||||
$coursecatcontext = \context_coursecat::instance($coursecat->id);
|
||||
// Create chat module.
|
||||
$cm = $this->getDataGenerator()->create_module('chat', ['course' => $course1->id]);
|
||||
$cmcontext = \context_module::instance($cm->cmid);
|
||||
|
||||
$systemcontext = \context_system::instance();
|
||||
// Create a block.
|
||||
$block = $this->getDataGenerator()->create_block('online_users');
|
||||
$blockcontext = \context_block::instance($block->id);
|
||||
|
||||
$studentrole = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST);
|
||||
$managerrole = $DB->get_record('role', array('shortname' => 'manager'), '*', MUST_EXIST);
|
||||
|
||||
// Role assignments CONTEXT_COURSE.
|
||||
role_assign($studentrole->id, $user1->id, $coursecontext1->id);
|
||||
role_assign($studentrole->id, $user2->id, $coursecontext1->id);
|
||||
// Role assignments CONTEXT_COURSECAT.
|
||||
role_assign($studentrole->id, $user2->id, $coursecatcontext->id);
|
||||
// Role assignments CONTEXT_SYSTEM.
|
||||
role_assign($studentrole->id, $user1->id, $systemcontext->id);
|
||||
// Role assignments CONTEXT_MODULE.
|
||||
role_assign($studentrole->id, $user2->id, $cmcontext->id);
|
||||
// Role assigments CONTEXT_BLOCK.
|
||||
role_assign($studentrole->id, $user1->id, $blockcontext->id);
|
||||
// Role assigments CONTEXT_USER.
|
||||
role_assign($managerrole->id, $user1->id, $usercontext2->id);
|
||||
|
||||
// Role capabilities.
|
||||
$this->setUser($user1);
|
||||
assign_capability('moodle/backup:backupcourse', CAP_ALLOW, $studentrole->id, $cmcontext->id);
|
||||
|
||||
// The user list for usercontext1 should not return any users.
|
||||
$userlist1 = new \core_privacy\local\request\userlist($usercontext1, $component);
|
||||
provider::get_users_in_context($userlist1);
|
||||
$this->assertCount(0, $userlist1);
|
||||
// The user list for usercontext2 should user1 and admin (role creator).
|
||||
$userlist2 = new \core_privacy\local\request\userlist($usercontext2, $component);
|
||||
provider::get_users_in_context($userlist2);
|
||||
$this->assertCount(2, $userlist2);
|
||||
$expected = [
|
||||
$user1->id,
|
||||
$admin->id
|
||||
];
|
||||
$this->assertEquals($expected, $userlist2->get_userids(), '', 0.0, 10, true);
|
||||
|
||||
// The user list for coursecontext1 should user1, user2 and admin (role creator).
|
||||
$userlist3 = new \core_privacy\local\request\userlist($coursecontext1, $component);
|
||||
provider::get_users_in_context($userlist3);
|
||||
$this->assertCount(3, $userlist3);
|
||||
$expected = [
|
||||
$user1->id,
|
||||
$user2->id,
|
||||
$admin->id
|
||||
];
|
||||
$this->assertEquals($expected, $userlist3->get_userids(), '', 0.0, 10, true);
|
||||
|
||||
// The user list for coursecatcontext should user2 and admin (role creator).
|
||||
$userlist4 = new \core_privacy\local\request\userlist($coursecatcontext, $component);
|
||||
provider::get_users_in_context($userlist4);
|
||||
$this->assertCount(2, $userlist4);
|
||||
$expected = [
|
||||
$user2->id,
|
||||
$admin->id
|
||||
];
|
||||
$this->assertEquals($expected, $userlist4->get_userids(), '', 0.0, 10, true);
|
||||
|
||||
// The user list for systemcontext should user1 and admin (role creator).
|
||||
$userlist6 = new \core_privacy\local\request\userlist($systemcontext, $component);
|
||||
provider::get_users_in_context($userlist6);
|
||||
$this->assertCount(2, $userlist6);
|
||||
$expected = [
|
||||
$user1->id,
|
||||
$admin->id
|
||||
];
|
||||
$this->assertEquals($expected, $userlist6->get_userids(), '', 0.0, 10, true);
|
||||
|
||||
// The user list for cmcontext should user1, user2 and admin (role creator).
|
||||
$userlist7 = new \core_privacy\local\request\userlist($cmcontext, $component);
|
||||
provider::get_users_in_context($userlist7);
|
||||
$this->assertCount(3, $userlist7);
|
||||
$expected = [
|
||||
$user1->id,
|
||||
$user2->id,
|
||||
$admin->id
|
||||
];
|
||||
$this->assertEquals($expected, $userlist7->get_userids(), '', 0.0, 10, true);
|
||||
|
||||
// The user list for blockcontext should user1 and admin (role creator).
|
||||
$userlist8 = new \core_privacy\local\request\userlist($blockcontext, $component);
|
||||
provider::get_users_in_context($userlist8);
|
||||
$this->assertCount(2, $userlist8);
|
||||
$expected = [
|
||||
$user1->id,
|
||||
$admin->id
|
||||
];
|
||||
$this->assertEquals($expected, $userlist8->get_userids(), '', 0.0, 10, true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that data for users in approved userlist is deleted.
|
||||
*/
|
||||
public function test_delete_data_for_users() {
|
||||
global $DB;
|
||||
|
||||
$this->resetAfterTest();
|
||||
|
||||
$component = 'core_role';
|
||||
|
||||
$this->setAdminUser();
|
||||
$admin = \core_user::get_user_by_username('admin');
|
||||
// Create user1.
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
// Create user2.
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
$usercontext2 = \context_user::instance($user2->id);
|
||||
// Create course1.
|
||||
$course1 = $this->getDataGenerator()->create_course();
|
||||
$coursecontext1 = \context_course::instance($course1->id);
|
||||
// Create course category.
|
||||
$coursecat = $this->getDataGenerator()->create_category();
|
||||
$coursecatcontext = \context_coursecat::instance($coursecat->id);
|
||||
// Create chat module.
|
||||
$cm = $this->getDataGenerator()->create_module('chat', ['course' => $course1->id]);
|
||||
$cmcontext = \context_module::instance($cm->cmid);
|
||||
|
||||
$systemcontext = \context_system::instance();
|
||||
// Create a block.
|
||||
$block = $this->getDataGenerator()->create_block('online_users');
|
||||
$blockcontext = \context_block::instance($block->id);
|
||||
|
||||
$studentrole = $DB->get_record('role', array('shortname' => 'student'), '*', MUST_EXIST);
|
||||
$managerrole = $DB->get_record('role', array('shortname' => 'manager'), '*', MUST_EXIST);
|
||||
|
||||
// Role assignments CONTEXT_COURSE.
|
||||
role_assign($studentrole->id, $user1->id, $coursecontext1->id);
|
||||
role_assign($studentrole->id, $user2->id, $coursecontext1->id);
|
||||
// Role assignments CONTEXT_COURSECAT.
|
||||
role_assign($studentrole->id, $user2->id, $coursecatcontext->id);
|
||||
// Role assignments CONTEXT_SYSTEM.
|
||||
role_assign($studentrole->id, $user1->id, $systemcontext->id);
|
||||
// Role assignments CONTEXT_MODULE.
|
||||
role_assign($studentrole->id, $user2->id, $cmcontext->id);
|
||||
// Role assigments CONTEXT_BLOCK.
|
||||
role_assign($studentrole->id, $user1->id, $blockcontext->id);
|
||||
// Role assigments CONTEXT_USER.
|
||||
role_assign($managerrole->id, $user1->id, $usercontext2->id);
|
||||
|
||||
// Role capabilities.
|
||||
$this->setUser($user1);
|
||||
assign_capability('moodle/backup:backupcourse', CAP_ALLOW, $studentrole->id, $cmcontext->id);
|
||||
|
||||
// The user list for usercontext2 should user1 and admin (role creator).
|
||||
$userlist1 = new \core_privacy\local\request\userlist($usercontext2, $component);
|
||||
provider::get_users_in_context($userlist1);
|
||||
$this->assertCount(2, $userlist1);
|
||||
// The user list for coursecontext1 should user1, user2 and admin (role creator).
|
||||
$userlist2 = new \core_privacy\local\request\userlist($coursecontext1, $component);
|
||||
provider::get_users_in_context($userlist2);
|
||||
$this->assertCount(3, $userlist2);
|
||||
// The user list for coursecatcontext should user2 and admin (role creator).
|
||||
$userlist3 = new \core_privacy\local\request\userlist($coursecatcontext, $component);
|
||||
provider::get_users_in_context($userlist3);
|
||||
$this->assertCount(2, $userlist3);
|
||||
// The user list for systemcontext should user1 and admin (role creator).
|
||||
$userlist4 = new \core_privacy\local\request\userlist($systemcontext, $component);
|
||||
provider::get_users_in_context($userlist4);
|
||||
$this->assertCount(2, $userlist4);
|
||||
// The user list for cmcontext should user1, user2 and admin (role creator).
|
||||
$userlist5 = new \core_privacy\local\request\userlist($cmcontext, $component);
|
||||
provider::get_users_in_context($userlist5);
|
||||
$this->assertCount(3, $userlist5);
|
||||
// The user list for blockcontext should user1 and admin (role creator).
|
||||
$userlist6 = new \core_privacy\local\request\userlist($blockcontext, $component);
|
||||
provider::get_users_in_context($userlist6);
|
||||
$this->assertCount(2, $userlist6);
|
||||
|
||||
// Convert $userlist1 into an approved_contextlist.
|
||||
$approvedlist1 = new approved_userlist($usercontext2, $component, $userlist1->get_userids());
|
||||
// Delete using delete_data_for_user.
|
||||
provider::delete_data_for_users($approvedlist1);
|
||||
// Re-fetch users in usercontext2.
|
||||
$userlist1 = new \core_privacy\local\request\userlist($usercontext2, $component);
|
||||
provider::get_users_in_context($userlist1);
|
||||
$this->assertCount(0, $userlist1);
|
||||
|
||||
// Convert $userlist2 into an approved_contextlist.
|
||||
$approvedlist2 = new approved_userlist($coursecontext1, $component, $userlist2->get_userids());
|
||||
// Delete using delete_data_for_user.
|
||||
provider::delete_data_for_users($approvedlist2);
|
||||
// Re-fetch users in coursecontext1.
|
||||
$userlist2 = new \core_privacy\local\request\userlist($coursecontext1, $component);
|
||||
provider::get_users_in_context($userlist2);
|
||||
$this->assertCount(0, $userlist2);
|
||||
|
||||
// Convert $userlist3 into an approved_contextlist.
|
||||
$approvedlist3 = new approved_userlist($coursecatcontext, $component, $userlist3->get_userids());
|
||||
// Delete using delete_data_for_user.
|
||||
provider::delete_data_for_users($approvedlist3);
|
||||
// Re-fetch users in coursecatcontext.
|
||||
$userlist3 = new \core_privacy\local\request\userlist($coursecatcontext, $component);
|
||||
provider::get_users_in_context($userlist3);
|
||||
$this->assertCount(0, $userlist3);
|
||||
|
||||
// Convert $userlist4 into an approved_contextlist.
|
||||
$approvedlist4 = new approved_userlist($systemcontext, $component, $userlist4->get_userids());
|
||||
// Delete using delete_data_for_user.
|
||||
provider::delete_data_for_users($approvedlist4);
|
||||
// Re-fetch users in systemcontext.
|
||||
$userlist4 = new \core_privacy\local\request\userlist($systemcontext, $component);
|
||||
provider::get_users_in_context($userlist4);
|
||||
// The data from role_capabilities should still be present. The user list should return the admin user.
|
||||
$this->assertCount(1, $userlist4);
|
||||
$expected = [$admin->id];
|
||||
$this->assertEquals($expected, $userlist4->get_userids());
|
||||
|
||||
// Convert $userlist5 into an approved_contextlist.
|
||||
$approvedlist5 = new approved_userlist($cmcontext, $component, $userlist5->get_userids());
|
||||
// Delete using delete_data_for_user.
|
||||
provider::delete_data_for_users($approvedlist5);
|
||||
// Re-fetch users in cmcontext.
|
||||
$userlist5 = new \core_privacy\local\request\userlist($cmcontext, $component);
|
||||
provider::get_users_in_context($userlist5);
|
||||
// The data from role_capabilities should still be present. The user list should return user1.
|
||||
$this->assertCount(1, $userlist5);
|
||||
$expected = [$user1->id];
|
||||
$this->assertEquals($expected, $userlist5->get_userids());
|
||||
|
||||
// Convert $userlist6 into an approved_contextlist.
|
||||
$approvedlist6 = new approved_userlist($blockcontext, $component, $userlist6->get_userids());
|
||||
// Delete using delete_data_for_user.
|
||||
provider::delete_data_for_users($approvedlist6);
|
||||
// Re-fetch users in blockcontext.
|
||||
$userlist6 = new \core_privacy\local\request\userlist($blockcontext, $component);
|
||||
provider::get_users_in_context($userlist6);
|
||||
$this->assertCount(0, $userlist6);
|
||||
}
|
||||
|
||||
/**
|
||||
* Supoort function to get all the localised roles name
|
||||
* in a simple array for testing.
|
||||
|
||||
@@ -37,8 +37,8 @@ if ($hassiteconfig) {
|
||||
$predictors[$fullclassname] = new lang_string('pluginname', $pluginname);
|
||||
}
|
||||
$settings->add(new \core_analytics\admin_setting_predictor('analytics/predictionsprocessor',
|
||||
new lang_string('defaultpredictionsprocessor', 'analytics'), new lang_string('predictionsprocessor_help', 'analytics'),
|
||||
\core_analytics\manager::default_mlbackend(), $predictors)
|
||||
new lang_string('predictionsprocessor', 'analytics'), new lang_string('predictionsprocessor_help', 'analytics'),
|
||||
'\mlbackend_php\processor', $predictors)
|
||||
);
|
||||
|
||||
// Log store.
|
||||
|
||||
@@ -32,9 +32,9 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) { // sp
|
||||
'customusermenuitems',
|
||||
new lang_string('customusermenuitems', 'admin'),
|
||||
new lang_string('configcustomusermenuitems', 'admin'),
|
||||
'grades,grades|/grade/report/mygrades.php|t/grades
|
||||
messages,message|/message/index.php|t/message
|
||||
preferences,moodle|/user/preferences.php|t/preferences',
|
||||
'grades,grades|/grade/report/mygrades.php|grades
|
||||
messages,message|/message/index.php|message
|
||||
preferences,moodle|/user/preferences.php|preferences',
|
||||
PARAM_RAW,
|
||||
'50',
|
||||
'10'
|
||||
@@ -218,9 +218,6 @@ preferences,moodle|/user/preferences.php|t/preferences',
|
||||
// coursecontact is the person responsible for course - usually manages enrolments, receives notification, etc.
|
||||
$temp = new admin_settingpage('coursecontact', new lang_string('courses'));
|
||||
$temp->add(new admin_setting_special_coursecontact());
|
||||
$temp->add(new admin_setting_configcheckbox('coursecontactduplicates',
|
||||
new lang_string('coursecontactduplicates', 'admin'),
|
||||
new lang_string('coursecontactduplicates_desc', 'admin'), 0));
|
||||
$temp->add(new admin_setting_configcheckbox('courselistshortnames',
|
||||
new lang_string('courselistshortnames', 'admin'),
|
||||
new lang_string('courselistshortnames_desc', 'admin'), 0));
|
||||
@@ -230,10 +227,6 @@ preferences,moodle|/user/preferences.php|t/preferences',
|
||||
new lang_string('configcourseoverviewfileslimit', 'admin'), 1, PARAM_INT));
|
||||
$temp->add(new admin_setting_configtext('courseoverviewfilesext', new lang_string('courseoverviewfilesext'),
|
||||
new lang_string('configcourseoverviewfilesext', 'admin'), '.jpg,.gif,.png'));
|
||||
$temp->add(new admin_setting_configtext('coursegraceperiodbefore', new lang_string('coursegraceperiodbefore', 'admin'),
|
||||
new lang_string('configcoursegraceperiodbefore', 'admin'), 0, PARAM_INT));
|
||||
$temp->add(new admin_setting_configtext('coursegraceperiodafter', new lang_string('coursegraceperiodafter', 'admin'),
|
||||
new lang_string('configcoursegraceperiodafter', 'admin'), 0, PARAM_INT));
|
||||
$ADMIN->add('appearance', $temp);
|
||||
|
||||
$temp = new admin_settingpage('ajax', new lang_string('ajaxuse'));
|
||||
@@ -259,3 +252,4 @@ preferences,moodle|/user/preferences.php|t/preferences',
|
||||
$ADMIN->add('appearance', $temp);
|
||||
|
||||
} // end of speedup
|
||||
|
||||
|
||||
@@ -43,12 +43,6 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) {
|
||||
array('moodle/category:manage')
|
||||
)
|
||||
);
|
||||
$ADMIN->add('courses',
|
||||
new admin_externalpage('addnewcourse', new lang_string('addnewcourse'),
|
||||
new moodle_url('/course/edit.php', array('category' => 0)),
|
||||
array('moodle/category:manage')
|
||||
)
|
||||
);
|
||||
$ADMIN->add('courses',
|
||||
new admin_externalpage('restorecourse', new lang_string('restorecourse', 'admin'),
|
||||
new moodle_url('/backup/restorefile.php', array('contextid' => context_system::instance()->id)),
|
||||
@@ -155,6 +149,7 @@ if ($hassiteconfig or has_any_capability($capabilities, $systemcontext)) {
|
||||
|
||||
$ADMIN->add('courses', $temp);
|
||||
|
||||
|
||||
// "courserequests" settingpage.
|
||||
$temp = new admin_settingpage('courserequest', new lang_string('courserequest'));
|
||||
$temp->add(new admin_setting_configcheckbox('enablecourserequests', new lang_string('enablecourserequests', 'admin'), new lang_string('configenablecourserequests', 'admin'), 0));
|
||||
|
||||
@@ -16,16 +16,6 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
|
||||
|
||||
$temp->add(new admin_setting_configexecutable('pathtosassc', new lang_string('pathtosassc', 'admin'), new lang_string('pathtosassc_help', 'admin'), ''));
|
||||
|
||||
$temp->add(new admin_setting_configcheckbox('contextlocking', new lang_string('contextlocking', 'core_admin'),
|
||||
new lang_string('contextlocking_desc', 'core_admin'), 0));
|
||||
|
||||
$temp->add(new admin_setting_configcheckbox(
|
||||
'contextlockappliestoadmin',
|
||||
new lang_string('contextlockappliestoadmin', 'core_admin'),
|
||||
new lang_string('contextlockappliestoadmin_desc', 'core_admin'),
|
||||
1
|
||||
));
|
||||
|
||||
$temp->add(new admin_setting_configcheckbox('forceclean', new lang_string('forceclean', 'core_admin'),
|
||||
new lang_string('forceclean_desc', 'core_admin'), 0));
|
||||
|
||||
@@ -93,8 +83,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
|
||||
$ADMIN->add('development', new admin_externalpage('mnettestclient', new lang_string('testclient', 'mnet'), "$CFG->wwwroot/$CFG->admin/mnet/testclient.php"));
|
||||
}
|
||||
|
||||
$ADMIN->add('development', new admin_externalpage('purgecaches', new lang_string('purgecachespage', 'admin'),
|
||||
"$CFG->wwwroot/$CFG->admin/purgecaches.php"));
|
||||
$ADMIN->add('development', new admin_externalpage('purgecaches', new lang_string('purgecaches','admin'), "$CFG->wwwroot/$CFG->admin/purgecaches.php"));
|
||||
|
||||
$ADMIN->add('development', new admin_externalpage('thirdpartylibs', new lang_string('thirdpartylibs','admin'), "$CFG->wwwroot/$CFG->admin/thirdpartylibs.php"));
|
||||
} // end of speedup
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This file gives information about Moodle Services
|
||||
*
|
||||
* @package core
|
||||
* @copyright 2018 Amaia Anabitarte <amaia@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
if ($hassiteconfig) {
|
||||
|
||||
// Create Moodle Services information.
|
||||
$moodleservices->add(new admin_setting_heading('moodleservicesintro', '',
|
||||
new lang_string('moodleservices_help', 'admin')));
|
||||
|
||||
// Moodle Partners information.
|
||||
if (empty($CFG->disableserviceads_partner)) {
|
||||
$moodleservices->add(new admin_setting_heading('moodlepartners',
|
||||
new lang_string('moodlepartners', 'admin'),
|
||||
new lang_string('moodlepartners_help', 'admin')));
|
||||
}
|
||||
|
||||
// Moodle app information.
|
||||
$moodleservices->add(new admin_setting_heading('moodleapp',
|
||||
new lang_string('moodleapp', 'admin'),
|
||||
new lang_string('moodleapp_help', 'admin')));
|
||||
|
||||
// Branded Moodle app information.
|
||||
if (empty($CFG->disableserviceads_branded)) {
|
||||
$moodleservices->add(new admin_setting_heading('moodlebrandedapp',
|
||||
new lang_string('moodlebrandedapp', 'admin'),
|
||||
new lang_string('moodlebrandedapp_help', 'admin')));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
|
||||
|
||||
// "systempaths" settingpage
|
||||
$temp = new admin_settingpage('systempaths', new lang_string('systempaths','admin'));
|
||||
$temp->add(new admin_setting_configexecutable('pathtophp', new lang_string('pathtophp', 'admin'),
|
||||
new lang_string('configpathtophp', 'admin'), ''));
|
||||
|
||||
$temp->add(new admin_setting_configexecutable('pathtodu', new lang_string('pathtodu', 'admin'), new lang_string('configpathtodu', 'admin'), ''));
|
||||
$temp->add(new admin_setting_configexecutable('aspellpath', new lang_string('aspellpath', 'admin'), new lang_string('edhelpaspellpath'), ''));
|
||||
$temp->add(new admin_setting_configexecutable('pathtodot', new lang_string('pathtodot', 'admin'), new lang_string('pathtodot_help', 'admin'), ''));
|
||||
|
||||
@@ -15,11 +15,7 @@ if ($hassiteconfig) { // speedup for non-admins, add all caps used on this page
|
||||
|
||||
$optionalsubsystems->add(new admin_setting_configcheckbox('messaging', new lang_string('messaging', 'admin'), new lang_string('configmessaging','admin'), 1));
|
||||
|
||||
$optionalsubsystems->add(new admin_setting_configcheckbox('messagingallusers',
|
||||
new lang_string('messagingallusers', 'admin'),
|
||||
new lang_string('configmessagingallusers', 'admin'),
|
||||
0)
|
||||
);
|
||||
$optionalsubsystems->add(new admin_setting_configcheckbox('messaginghidereadnotifications', new lang_string('messaginghidereadnotifications', 'admin'), new lang_string('configmessaginghidereadnotifications','admin'), 0));
|
||||
|
||||
$options = array(DAYSECS=>new lang_string('secondstotime86400'), WEEKSECS=>new lang_string('secondstotime604800'), 2620800=>new lang_string('nummonths', 'moodle', 1), 15724800=>new lang_string('nummonths', 'moodle', 6),0=>new lang_string('never'));
|
||||
$optionalsubsystems->add(new admin_setting_configselect('messagingdeletereadnotificationsdelay', new lang_string('messagingdeletereadnotificationsdelay', 'admin'), new lang_string('configmessagingdeletereadnotificationsdelay', 'admin'), 604800, $options));
|
||||
|
||||
@@ -15,11 +15,6 @@ $ADMIN->add('root', new admin_externalpage('registrationmoodleorg', new lang_str
|
||||
// hidden upgrade script
|
||||
$ADMIN->add('root', new admin_externalpage('upgradesettings', new lang_string('upgradesettings', 'admin'), "$CFG->wwwroot/$CFG->admin/upgradesettings.php", 'moodle/site:config', true));
|
||||
|
||||
// Adding Moodle Services information page.
|
||||
$moodleservices = new admin_settingpage('moodleservices', new lang_string('moodleservices',
|
||||
'admin'));
|
||||
$ADMIN->add('root', $moodleservices);
|
||||
|
||||
if ($hassiteconfig) {
|
||||
$optionalsubsystems = new admin_settingpage('optionalsubsystems', new lang_string('advancedfeatures', 'admin'));
|
||||
$ADMIN->add('root', $optionalsubsystems);
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
{{!
|
||||
This file is part of Moodle - http://moodle.org/
|
||||
|
||||
Moodle is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Moodle is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
}}
|
||||
{{!
|
||||
@template core_admin/setting_description
|
||||
|
||||
Admin setting description template.
|
||||
|
||||
Context variables required for this template:
|
||||
* labelfor - id of the form element
|
||||
* title - Setting title
|
||||
* name - Setting name
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"title": "Setting title",
|
||||
"name": "Name",
|
||||
"description": "Description goes here"
|
||||
}
|
||||
}}
|
||||
{{!
|
||||
Setting description.
|
||||
}}
|
||||
<div class="form-item form-horizontal clearfix">
|
||||
<div class="form-label">
|
||||
<label>
|
||||
{{{title}}}
|
||||
</label>
|
||||
<span class="form-shortname ">{{{name}}}</span>
|
||||
</div>
|
||||
<div class="controls felement fstatic">{{{description}}}</div>
|
||||
</div>
|
||||
@@ -22,7 +22,7 @@
|
||||
Context variables required for this template:
|
||||
* actionurl - Url to post to
|
||||
* hasresults - True if there are results
|
||||
* results - List of results containing url, title, path (array of strings), settings (array of raw html)
|
||||
* results - List of results containing url, title, settings (array of raw html)
|
||||
* showsave - Show save buttons
|
||||
|
||||
Example context (json):
|
||||
@@ -30,7 +30,7 @@
|
||||
"actionurl": "/",
|
||||
"hasresults": true,
|
||||
"results": [
|
||||
{ "url": "/", "title": "Match!", "path": ["Administration", "Match!"], "settings": [ "blah blah blah" ] }
|
||||
{ "url": "/", "title": "Match!", "settings": [ "blah blah blah" ] }
|
||||
]
|
||||
}
|
||||
}}
|
||||
@@ -41,15 +41,9 @@
|
||||
</div>
|
||||
<fieldset>
|
||||
<div class="clearer"></div>
|
||||
<h2 class="main">{{#str}}searchresults, admin{{/str}}</h2>
|
||||
{{#hasresults}}
|
||||
{{#results}}
|
||||
<h3 class="adminpagetitle"><a href="{{url}}">{{{title}}}</a></h3>
|
||||
<ul class="adminpagepath" aria-label="{{#str}} pagepath, core {{/str}}">
|
||||
{{#path}}
|
||||
<li>{{.}}</li>
|
||||
{{/path}}
|
||||
</ul>
|
||||
<h2 class="main">{{#str}}searchresults, admin{{/str}} - <a href="{{url}}">{{{title}}}</a></h2>
|
||||
<fieldset class="adminsettings">
|
||||
{{#settings}}
|
||||
<div class="clearer"></div>
|
||||
|
||||
@@ -10,7 +10,7 @@ Feature: Enable multiple accounts to have the same email address
|
||||
Scenario: Enable registration of multiple accounts with the same email address
|
||||
Given the following config values are set as admin:
|
||||
| allowaccountssameemail | 1 |
|
||||
When I navigate to "Users > Accounts > Add a new user" in site administration
|
||||
When I navigate to "Add a new user" node in "Site administration>Users>Accounts"
|
||||
And I set the following fields to these values:
|
||||
| Username | testmultiemailuser1 |
|
||||
| Choose an authentication method | Manual accounts |
|
||||
@@ -35,7 +35,7 @@ Feature: Enable multiple accounts to have the same email address
|
||||
Scenario: Disable registration of multiple accounts with the same email address
|
||||
Given the following config values are set as admin:
|
||||
| allowaccountssameemail | 0 |
|
||||
When I navigate to "Users > Accounts > Add a new user" in site administration
|
||||
When I navigate to "Add a new user" node in "Site administration>Users>Accounts"
|
||||
And I set the following fields to these values:
|
||||
| Username | testmultiemailuser1 |
|
||||
| Choose an authentication method | Manual accounts |
|
||||
|
||||
@@ -65,20 +65,3 @@ Feature: An administrator can filter user accounts by role, cohort and other pro
|
||||
And I should not see "User Two"
|
||||
And I should not see "User Three"
|
||||
And I should not see "User Four"
|
||||
|
||||
Scenario: Filter user accounts by enrolled in any course
|
||||
When I set the following fields to these values:
|
||||
| id_anycourses | Yes |
|
||||
And I press "Add filter"
|
||||
Then I should see "User One"
|
||||
And I should see "User Two"
|
||||
And I should see "User Three"
|
||||
And I should not see "User Four"
|
||||
And I press "Remove all filters"
|
||||
And I set the following fields to these values:
|
||||
| id_anycourses | No |
|
||||
And I press "Add filter"
|
||||
And I should not see "User One"
|
||||
And I should not see "User Two"
|
||||
And I should not see "User Three"
|
||||
And I should see "User Four"
|
||||
|
||||
@@ -1,34 +0,0 @@
|
||||
@core @core_admin
|
||||
Feature: Purge caches
|
||||
In order to see changes to cached data
|
||||
As a Moodle administrator
|
||||
I want manually purge different data and file caches
|
||||
|
||||
Background:
|
||||
Given I log in as "admin"
|
||||
And I navigate to "Development > Purge caches" in site administration
|
||||
|
||||
Scenario: Purge all caches
|
||||
Given I should not see "All caches were purged"
|
||||
When I press "Purge all caches"
|
||||
Then I should see "All caches were purged"
|
||||
|
||||
Scenario: Purge selected caches
|
||||
Given I should not see "Selected caches were purged"
|
||||
When I set the field "Themes" to "1"
|
||||
And I press "Purge selected caches"
|
||||
Then I should see "The selected caches were purged"
|
||||
|
||||
Scenario: Purge selected caches without selecting any caches
|
||||
Given I should not see "Select one or more caches to purge"
|
||||
When I press "Purge selected caches"
|
||||
Then I should not see "The selected caches were purged"
|
||||
And I should see "Select one or more caches to purge"
|
||||
|
||||
Scenario: Redirect back to the original page after following a Purge all caches link
|
||||
Given I am on site homepage
|
||||
And I should see "Available courses"
|
||||
And I should not see "All caches were purged"
|
||||
When I follow "Purge all caches"
|
||||
Then I should see "All caches were purged"
|
||||
And I should see "Available courses"
|
||||
@@ -72,22 +72,6 @@ class edit_model extends \moodleform {
|
||||
$mform->addElement('select', 'timesplitting', get_string('timesplittingmethod', 'analytics'), $timesplittings);
|
||||
$mform->addHelpButton('timesplitting', 'timesplittingmethod', 'analytics');
|
||||
|
||||
$defaultprocessor = \core_analytics\manager::get_predictions_processor_name(
|
||||
\core_analytics\manager::get_predictions_processor()
|
||||
);
|
||||
$predictionprocessors = ['' => get_string('defaultpredictoroption', 'analytics', $defaultprocessor)];
|
||||
foreach ($this->_customdata['predictionprocessors'] as $classname => $predictionsprocessor) {
|
||||
if ($predictionsprocessor->is_ready() !== true) {
|
||||
continue;
|
||||
}
|
||||
$optionname = \tool_analytics\output\helper::class_to_option($classname);
|
||||
$predictionprocessors[$optionname] = \core_analytics\manager::get_predictions_processor_name($predictionsprocessor);
|
||||
}
|
||||
|
||||
$mform->addElement('select', 'predictionsprocessor', get_string('predictionsprocessor', 'analytics'),
|
||||
$predictionprocessors);
|
||||
$mform->addHelpButton('predictionsprocessor', 'predictionsprocessor', 'analytics');
|
||||
|
||||
$mform->addElement('hidden', 'id', $this->_customdata['id']);
|
||||
$mform->setType('id', PARAM_INT);
|
||||
|
||||
|
||||
@@ -110,8 +110,7 @@ switch ($action) {
|
||||
'id' => $model->get_id(),
|
||||
'model' => $model,
|
||||
'indicators' => $model->get_potential_indicators(),
|
||||
'timesplittings' => \core_analytics\manager::get_enabled_time_splitting_methods(),
|
||||
'predictionprocessors' => \core_analytics\manager::get_all_prediction_processors()
|
||||
'timesplittings' => \core_analytics\manager::get_enabled_time_splitting_methods()
|
||||
);
|
||||
$mform = new \tool_analytics\output\form\edit_model(null, $customdata);
|
||||
|
||||
@@ -127,8 +126,7 @@ switch ($action) {
|
||||
$indicators[] = \core_analytics\manager::get_indicator($indicatorclass);
|
||||
}
|
||||
$timesplitting = \tool_analytics\output\helper::option_to_class($data->timesplitting);
|
||||
$predictionsprocessor = \tool_analytics\output\helper::option_to_class($data->predictionsprocessor);
|
||||
$model->update($data->enabled, $indicators, $timesplitting, $predictionsprocessor);
|
||||
$model->update($data->enabled, $indicators, $timesplitting);
|
||||
redirect(new \moodle_url('/admin/tool/analytics/index.php'));
|
||||
}
|
||||
|
||||
@@ -139,7 +137,6 @@ switch ($action) {
|
||||
$callable = array('\tool_analytics\output\helper', 'class_to_option');
|
||||
$modelobj->indicators = array_map($callable, json_decode($modelobj->indicators));
|
||||
$modelobj->timesplitting = \tool_analytics\output\helper::class_to_option($modelobj->timesplitting);
|
||||
$modelobj->predictionsprocessor = \tool_analytics\output\helper::class_to_option($modelobj->predictionsprocessor);
|
||||
$mform->set_data($modelobj);
|
||||
$mform->display();
|
||||
break;
|
||||
|
||||
@@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2018120300; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2018112800; // Requires this Moodle version.
|
||||
$plugin->version = 2018051400; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2018050800; // Requires this Moodle version.
|
||||
$plugin->component = 'tool_analytics'; // Full name of the plugin (used for diagnostics).
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Script to show all the assignments that have not been upgraded after the main upgrade.
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
define('NO_OUTPUT_BUFFERING', true);
|
||||
|
||||
require_once(__DIR__ . '/../../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/locallib.php');
|
||||
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/upgradableassignmentstable.php');
|
||||
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/upgradableassignmentsbatchform.php');
|
||||
|
||||
require_sesskey();
|
||||
|
||||
// This calls require_login and checks moodle/site:config.
|
||||
admin_externalpage_setup('assignmentupgrade', '', array(), tool_assignmentupgrade_url('batchupgrade'));
|
||||
|
||||
$PAGE->set_pagelayout('maintenance');
|
||||
$PAGE->navbar->add(get_string('batchupgrade', 'tool_assignmentupgrade'));
|
||||
|
||||
$renderer = $PAGE->get_renderer('tool_assignmentupgrade');
|
||||
|
||||
$confirm = required_param('confirm', PARAM_BOOL);
|
||||
if (!$confirm) {
|
||||
print_error('invalidrequest');
|
||||
die();
|
||||
}
|
||||
raise_memory_limit(MEMORY_EXTRA);
|
||||
// Release session.
|
||||
\core\session\manager::write_close();
|
||||
|
||||
echo $renderer->header();
|
||||
echo $renderer->heading(get_string('batchupgrade', 'tool_assignmentupgrade'));
|
||||
|
||||
$current = 0;
|
||||
if (optional_param('upgradeall', false, PARAM_BOOL)) {
|
||||
$assignmentids = tool_assignmentupgrade_load_all_upgradable_assignmentids();
|
||||
} else {
|
||||
$assignmentids = explode(',', optional_param('selected', '', PARAM_TEXT));
|
||||
}
|
||||
$total = count($assignmentids);
|
||||
|
||||
foreach ($assignmentids as $assignmentid) {
|
||||
list($summary, $success, $log) = tool_assignmentupgrade_upgrade_assignment($assignmentid);
|
||||
$current += 1;
|
||||
$params = array('current'=>$current, 'total'=>$total);
|
||||
echo $renderer->heading(get_string('upgradeprogress', 'tool_assignmentupgrade', $params), 3);
|
||||
echo $renderer->convert_assignment_result($summary, $success, $log);
|
||||
}
|
||||
|
||||
echo $renderer->continue_button(tool_assignmentupgrade_url('listnotupgraded'));
|
||||
echo $renderer->footer();
|
||||
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Privacy Subsystem implementation for tool_assignmentupgrade.
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2018 Zig Tan <zig@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace tool_assignmentupgrade\privacy;
|
||||
|
||||
use core_privacy\local\metadata\collection;
|
||||
use core_privacy\local\request\writer;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Privacy Subsystem for tool_assignmentupgrade implementing metadata, plugin, and user_preference providers.
|
||||
*
|
||||
* @copyright 2018 Zig Tan <zig@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class provider implements
|
||||
\core_privacy\local\metadata\provider,
|
||||
\core_privacy\local\request\user_preference_provider {
|
||||
|
||||
/**
|
||||
* Returns meta data about this system.
|
||||
*
|
||||
* @param collection $collection The initialised collection to add items to.
|
||||
* @return collection A listing of user data stored through this system.
|
||||
*/
|
||||
public static function get_metadata(collection $collection) : collection {
|
||||
$collection->add_user_preference(
|
||||
'tool_assignmentupgrade_perpage',
|
||||
'privacy:metadata:preference:perpage'
|
||||
);
|
||||
return $collection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Export all user preferences for the plugin.
|
||||
*
|
||||
* @param int $userid The userid of the user whose data is to be exported.
|
||||
*/
|
||||
public static function export_user_preferences(int $userid) {
|
||||
$perpage = get_user_preferences('tool_assignmentupgrade_perpage', null, $userid);
|
||||
if ($perpage !== null) {
|
||||
writer::export_user_preference(
|
||||
'tool_assignmentupgrade',
|
||||
'perpage',
|
||||
$perpage,
|
||||
get_string('privacy:metadata:preference:perpage', 'tool_assignmentupgrade')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This tool can upgrade old assignment activities to the new assignment activity type
|
||||
*
|
||||
* The upgrade can be done on any old assignment instance providing it is using one of the core
|
||||
* assignment subtypes (online text, single upload, etc).
|
||||
* The new assignment module was introduced in Moodle 2.3 and although it completely reproduces
|
||||
* the features of the existing assignment type it wasn't designed to replace it entirely as there
|
||||
* are many custom assignment types people use and it wouldn't be practical to try to convert them.
|
||||
* Instead the existing assignment type will be left in core and people will be encouraged to
|
||||
* use the new assignment type.
|
||||
*
|
||||
* This screen is the main entry-point to the plugin, it gives the admin a list
|
||||
* of options available to them.
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . '/../../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/locallib.php');
|
||||
|
||||
// This calls require_login and checks moodle/site:config.
|
||||
admin_externalpage_setup('assignmentupgrade');
|
||||
|
||||
$renderer = $PAGE->get_renderer('tool_assignmentupgrade');
|
||||
|
||||
$actions = array();
|
||||
|
||||
$header = get_string('pluginname', 'tool_assignmentupgrade');
|
||||
$actions[] = tool_assignmentupgrade_action::make('listnotupgraded');
|
||||
|
||||
echo $renderer->index_page($header, $actions);
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Strings for the assignment upgrade tool
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
$string['areyousure'] = 'Are you sure?';
|
||||
$string['areyousuremessage'] = 'Are you sure you want to upgrade the assignment "{$a->name}"?';
|
||||
$string['assignmentid'] = 'Assignment ID';
|
||||
$string['assignmentnotfound'] = 'Assignment could not be found (id={$a})';
|
||||
$string['assignmentsperpage'] = 'Assignments per page';
|
||||
$string['assignmenttype'] = 'Assignment type';
|
||||
$string['backtoindex'] = 'Back to index';
|
||||
$string['batchoperations'] = 'Batch operations';
|
||||
$string['batchupgrade'] = 'Upgrade multiple assignments';
|
||||
$string['confirmbatchupgrade'] = 'Confirm batch upgrade assignments';
|
||||
$string['conversioncomplete'] = 'Assignment converted';
|
||||
$string['conversionfailed'] = 'The assignment conversion was not successful. The log from the upgrade was: <br />{$a}';
|
||||
$string['listnotupgraded'] = 'List assignments that have not been upgraded';
|
||||
$string['listnotupgraded_desc'] = 'You can upgrade individual assignments from here';
|
||||
$string['noassignmentsselected'] = 'No assignments selected';
|
||||
$string['noassignmentstoupgrade'] = 'There are no assignments that require upgrading';
|
||||
$string['notsupported'] = '';
|
||||
$string['notupgradedintro'] = 'This page lists the assignments created with an older version of Moodle that have not been upgraded to the new assignment module in Moodle 2.3. Not all assignments can be upgraded - if they were created with a custom assignment subtype, then that subtype will need to be upgraded to the new assignment plugin format in order to complete the upgrade.';
|
||||
$string['notupgradedtitle'] = 'Assignments not upgraded';
|
||||
$string['pluginname'] = 'Assignment upgrade helper';
|
||||
$string['select'] = 'Select';
|
||||
$string['submissions'] = 'Submissions';
|
||||
$string['supported'] = 'Upgrade';
|
||||
$string['updatetable'] = 'Update table';
|
||||
$string['unknown'] = 'Unknown';
|
||||
$string['upgradeassignmentsummary'] = 'Upgrade assignment: {$a->name} (Course: {$a->shortname})';
|
||||
$string['upgradeassignmentsuccess'] = 'Result: Upgrade successful';
|
||||
$string['upgradeassignmentfailed'] = 'Result: Upgrade failed. The log from the upgrade was: <br/><div class="tool_assignmentupgrade_upgradelog">{$a->log}</div>';
|
||||
$string['upgradable'] = 'Upgradable';
|
||||
$string['upgradeselected'] = 'Upgrade selected assignments';
|
||||
$string['upgradeselectedcount'] = 'Upgrade {$a} selected assignments?';
|
||||
$string['upgradeall'] = 'Upgrade all assignments';
|
||||
$string['upgradeallconfirm'] = 'Upgrade all assignments?';
|
||||
$string['upgradeprogress'] = 'Upgrade assignment {$a->current} of {$a->total}';
|
||||
$string['upgradesingle'] = 'Upgrade single assignment';
|
||||
$string['viewcourse'] = 'View the course with the converted assignment';
|
||||
$string['privacy:metadata:preference:perpage'] = 'The assignment upgrade records per page preference set for the user.';
|
||||
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Script to show all the assignments that have not been upgraded after the main upgrade.
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . '/../../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/locallib.php');
|
||||
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/upgradableassignmentstable.php');
|
||||
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/upgradableassignmentsbatchform.php');
|
||||
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/paginationform.php');
|
||||
|
||||
// This calls require_login and checks moodle/site:config.
|
||||
admin_externalpage_setup('assignmentupgrade', '', array(), tool_assignmentupgrade_url('listnotupgraded'));
|
||||
$PAGE->navbar->add(get_string('listnotupgraded', 'tool_assignmentupgrade'));
|
||||
|
||||
$renderer = $PAGE->get_renderer('tool_assignmentupgrade');
|
||||
|
||||
$perpage = optional_param('perpage', 0, PARAM_INT);
|
||||
if (!$perpage) {
|
||||
$perpage = get_user_preferences('tool_assignmentupgrade_perpage', 100);
|
||||
} else {
|
||||
set_user_preference('tool_assignmentupgrade_perpage', $perpage);
|
||||
}
|
||||
$assignments = new tool_assignmentupgrade_assignments_table($perpage);
|
||||
|
||||
$batchform = new tool_assignmentupgrade_batchoperations_form();
|
||||
$data = $batchform->get_data();
|
||||
|
||||
if ($data && $data->selectedassignments != '' || $data && isset($data->upgradeall)) {
|
||||
require_sesskey();
|
||||
echo $renderer->confirm_batch_operation_page($data);
|
||||
} else {
|
||||
$paginationform = new tool_assignmentupgrade_pagination_form();
|
||||
$pagedata = new stdClass();
|
||||
$pagedata->perpage = $perpage;
|
||||
$paginationform->set_data($pagedata);
|
||||
echo $renderer->assignment_list_page($assignments, $batchform, $paginationform);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,234 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Assignment upgrade tool library functions
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Get the URL of a script within this plugin.
|
||||
* @param string $script the script name, without .php. E.g. 'index'
|
||||
* @param array $params URL parameters (optional)
|
||||
* @return moodle_url
|
||||
*/
|
||||
function tool_assignmentupgrade_url($script, $params = array()) {
|
||||
return new moodle_url('/admin/tool/assignmentupgrade/' . $script . '.php', $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Class to encapsulate the continue / cancel for batch operations
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_assignmentupgrade_batchoperationconfirm implements renderable {
|
||||
/** @var string $continuemessage The message to show above the continue cancel buttons */
|
||||
public $continuemessage = '';
|
||||
/** @var string $continueurl The url to load if the user clicks continue */
|
||||
public $continueurl;
|
||||
|
||||
/**
|
||||
* Constructor for this class
|
||||
* @param stdClass $data - The data from the previous batch form
|
||||
*/
|
||||
public function __construct($data) {
|
||||
if (isset($data->upgradeselected)) {
|
||||
$this->continuemessage = get_string('upgradeselectedcount',
|
||||
'tool_assignmentupgrade',
|
||||
count(explode(',', $data->selectedassignments)));
|
||||
$urlparams = array('upgradeselected'=>'1',
|
||||
'confirm'=>'1',
|
||||
'sesskey'=>sesskey(),
|
||||
'selected'=>$data->selectedassignments);
|
||||
$this->continueurl = new moodle_url('/admin/tool/assignmentupgrade/batchupgrade.php', $urlparams);
|
||||
} else if (isset($data->upgradeall)) {
|
||||
if (!tool_assignmentupgrade_any_upgradable_assignments()) {
|
||||
$this->continuemessage = get_string('noassignmentstoupgrade', 'tool_assignmentupgrade');
|
||||
$this->continueurl = '';
|
||||
} else {
|
||||
$this->continuemessage = get_string('upgradeallconfirm', 'tool_assignmentupgrade');
|
||||
$urlparams = array('upgradeall'=>'1', 'confirm'=>'1', 'sesskey'=>sesskey());
|
||||
$this->continueurl = new moodle_url('/admin/tool/assignmentupgrade/batchupgrade.php', $urlparams);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Class to encapsulate one of the functionalities that this plugin offers.
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_assignmentupgrade_action {
|
||||
/** @var string the name of this action. */
|
||||
public $name;
|
||||
/** @var moodle_url the URL to launch this action. */
|
||||
public $url;
|
||||
/** @var string a description of this aciton. */
|
||||
public $description;
|
||||
|
||||
/**
|
||||
* Constructor to set the fields.
|
||||
*
|
||||
* In order to create a new tool_assignmentupgrade_action instance you must use
|
||||
* the tool_assignmentupgrade_action::make
|
||||
* method.
|
||||
*
|
||||
* @param string $name the name of this action.
|
||||
* @param moodle_url $url the URL to launch this action.
|
||||
* @param string $description a description of this aciton.
|
||||
*/
|
||||
protected function __construct($name, moodle_url $url, $description) {
|
||||
$this->name = $name;
|
||||
$this->url = $url;
|
||||
$this->description = $description;
|
||||
}
|
||||
|
||||
/**
|
||||
* Make an action with standard values.
|
||||
* @param string $shortname internal name of the action. Used to get strings and build a URL.
|
||||
* @param array $params any URL params required.
|
||||
* @return tool_assignmentupgrade_action
|
||||
*/
|
||||
public static function make($shortname, $params = array()) {
|
||||
return new self(
|
||||
get_string($shortname, 'tool_assignmentupgrade'),
|
||||
tool_assignmentupgrade_url($shortname, $params),
|
||||
get_string($shortname . '_desc', 'tool_assignmentupgrade'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if there are any assignments that can be upgraded
|
||||
* @return boolean - Are there any assignments that can be upgraded
|
||||
*/
|
||||
function tool_assignmentupgrade_any_upgradable_assignments() {
|
||||
global $DB, $CFG;
|
||||
require_once($CFG->dirroot . '/mod/assign/locallib.php');
|
||||
// First find all the unique assignment types.
|
||||
$types = $DB->get_records_sql('SELECT plugin AS assignmenttype,
|
||||
value AS version
|
||||
FROM {config_plugins}
|
||||
WHERE
|
||||
name = ? AND
|
||||
plugin LIKE ?', array('version', 'assignment_%'));
|
||||
|
||||
$upgradabletypes = array();
|
||||
|
||||
foreach ($types as $assignment) {
|
||||
$shorttype = substr($assignment->assignmenttype, strlen('assignment_'));
|
||||
if (assign::can_upgrade_assignment($shorttype, $assignment->version)) {
|
||||
$upgradabletypes[] = $shorttype;
|
||||
}
|
||||
}
|
||||
list($sql, $params) = $DB->get_in_or_equal($upgradabletypes);
|
||||
|
||||
$count = $DB->count_records_sql('SELECT COUNT(id) FROM {assignment} WHERE assignmenttype ' . $sql, $params);
|
||||
|
||||
return $count > 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Load a list of all the assignmentids that can be upgraded
|
||||
* @return array of assignment ids
|
||||
*/
|
||||
function tool_assignmentupgrade_load_all_upgradable_assignmentids() {
|
||||
global $DB, $CFG;
|
||||
require_once($CFG->dirroot . '/mod/assign/locallib.php');
|
||||
// First find all the unique assignment types.
|
||||
$types = $DB->get_records_sql('SELECT
|
||||
plugin AS assignmenttype,
|
||||
value AS version
|
||||
FROM {config_plugins}
|
||||
WHERE
|
||||
name = ? AND
|
||||
plugin LIKE ?', array('version', 'assignment_%'));
|
||||
|
||||
$upgradabletypes = array();
|
||||
|
||||
foreach ($types as $assignment) {
|
||||
$shorttype = substr($assignment->assignmenttype, strlen('assignment_'));
|
||||
if (assign::can_upgrade_assignment($shorttype, $assignment->version)) {
|
||||
$upgradabletypes[] = $shorttype;
|
||||
}
|
||||
}
|
||||
|
||||
list($sql, $params) = $DB->get_in_or_equal($upgradabletypes);
|
||||
|
||||
$records = $DB->get_records_sql('SELECT id from {assignment} where assignmenttype ' . $sql, $params);
|
||||
$ids = array();
|
||||
foreach ($records as $record) {
|
||||
$ids[] = $record->id;
|
||||
}
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Upgrade a single assignment. This is used by both upgrade single and upgrade batch
|
||||
*
|
||||
* @param int $assignmentid - The assignment id to upgrade
|
||||
* @return array(string, boolean, string) -
|
||||
* The array contains
|
||||
* - the assignment summary (returned by tool_assignmentupgrade_get_assignment)
|
||||
* - success
|
||||
* - the upgrade log
|
||||
*/
|
||||
function tool_assignmentupgrade_upgrade_assignment($assignmentid) {
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/mod/assign/upgradelib.php');
|
||||
|
||||
$assignment_upgrader = new assign_upgrade_manager();
|
||||
$info = tool_assignmentupgrade_get_assignment($assignmentid);
|
||||
if ($info) {
|
||||
$log = '';
|
||||
$success = $assignment_upgrader->upgrade_assignment($assignmentid, $log);
|
||||
} else {
|
||||
$success = false;
|
||||
$log = get_string('assignmentnotfound', 'tool_assignmentupgrade', $assignmentid);
|
||||
$info = new stdClass();
|
||||
$info->name = get_string('unknown', 'tool_assignmentupgrade');
|
||||
$info->shortname = get_string('unknown', 'tool_assignmentupgrade');
|
||||
}
|
||||
|
||||
return array($info, $success, $log);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the information about a assignment to be upgraded.
|
||||
* @param int $assignmentid the assignment id.
|
||||
* @return stdClass the information about that assignment.
|
||||
*/
|
||||
function tool_assignmentupgrade_get_assignment($assignmentid) {
|
||||
global $DB;
|
||||
return $DB->get_record_sql("
|
||||
SELECT a.id, a.name, c.shortname, c.id AS courseid
|
||||
FROM {assignment} a
|
||||
JOIN {course} c ON c.id = a.course
|
||||
WHERE a.id = ?", array($assignmentid));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
M.tool_assignmentupgrade = {
|
||||
init_upgrade_table: function(Y) {
|
||||
|
||||
Y.use('node', function(Y) {
|
||||
checkboxes = Y.all('td.c0 input');
|
||||
checkboxes.each(function(node) {
|
||||
node.on('change', function(e) {
|
||||
rowelement = e.currentTarget.get('parentNode').get('parentNode');
|
||||
if (e.currentTarget.get('checked')) {
|
||||
rowelement.setAttribute('class', 'selectedrow');
|
||||
} else {
|
||||
rowelement.setAttribute('class', 'unselectedrow');
|
||||
}
|
||||
});
|
||||
|
||||
rowelement = node.get('parentNode').get('parentNode');
|
||||
if (node.get('checked')) {
|
||||
rowelement.setAttribute('class', 'selectedrow');
|
||||
} else {
|
||||
rowelement.setAttribute('class', 'unselectedrow');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var selectall = Y.one('th.c0 input');
|
||||
selectall.on('change', function(e) {
|
||||
if (e.currentTarget.get('checked')) {
|
||||
checkboxes = Y.all('td.c0 input');
|
||||
checkboxes.each(function(node) {
|
||||
rowelement = node.get('parentNode').get('parentNode');
|
||||
node.set('checked', true);
|
||||
rowelement.setAttribute('class', 'selectedrow');
|
||||
});
|
||||
} else {
|
||||
checkboxes = Y.all('td.c0 input');
|
||||
checkboxes.each(function(node) {
|
||||
rowelement = node.get('parentNode').get('parentNode');
|
||||
node.set('checked', false);
|
||||
rowelement.setAttribute('class', 'unselectedrow');
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
var upgradeselectedbutton = Y.one('#id_upgradeselected');
|
||||
upgradeselectedbutton.on('click', function(e) {
|
||||
checkboxes = Y.all('td.c0 input');
|
||||
var selectedassignments = [];
|
||||
checkboxes.each(function(node) {
|
||||
if (node.get('checked')) {
|
||||
selectedassignments[selectedassignments.length] = node.get('value');
|
||||
}
|
||||
});
|
||||
|
||||
operation = Y.one('#id_operation');
|
||||
assignmentsinput = Y.one('input.selectedassignments');
|
||||
assignmentsinput.set('value', selectedassignments.join(','));
|
||||
if (selectedassignments.length == 0) {
|
||||
alert(M.util.get_string('noassignmentsselected', 'tool_assignmentupgrade'));
|
||||
e.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
var perpage = Y.one('#id_perpage');
|
||||
perpage.on('change', function(e) {
|
||||
window.onbeforeunload = null;
|
||||
Y.one('.tool_assignmentupgrade_paginationform form').submit();
|
||||
});
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This file contains the forms to create and edit an instance of this module
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
/**
|
||||
* Assignment upgrade table display options
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_assignmentupgrade_pagination_form extends moodleform {
|
||||
/**
|
||||
* Define this form - called from the parent constructor
|
||||
*/
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
$instance = $this->_customdata;
|
||||
|
||||
$mform->addElement('header', 'general', get_string('assignmentsperpage', 'tool_assignmentupgrade'));
|
||||
// Visible elements.
|
||||
$options = array(10=>'10', 20=>'20', 50=>'50', 100=>'100');
|
||||
$mform->addElement('select', 'perpage', get_string('assignmentsperpage', 'assign'), $options);
|
||||
|
||||
// Hidden params.
|
||||
$mform->addElement('hidden', 'action', 'saveoptions');
|
||||
$mform->setType('action', PARAM_ALPHA);
|
||||
|
||||
// Buttons.
|
||||
$this->add_action_buttons(false, get_string('updatetable', 'tool_assignmentupgrade'));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,249 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Defines the renderer for the assignment upgrade helper plugin.
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Renderer for the assignment upgrade helper plugin.
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_assignmentupgrade_renderer extends plugin_renderer_base {
|
||||
|
||||
/**
|
||||
* Render the index page.
|
||||
* @param string $detected information about what sort of site was detected.
|
||||
* @param array $actions list of actions to show on this page.
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function index_page($detected, array $actions) {
|
||||
$output = '';
|
||||
$output .= $this->header();
|
||||
$output .= $this->heading(get_string('pluginname', 'tool_assignmentupgrade'));
|
||||
$output .= $this->box($detected);
|
||||
$output .= html_writer::start_tag('ul');
|
||||
foreach ($actions as $action) {
|
||||
$output .= html_writer::tag('li',
|
||||
html_writer::link($action->url, $action->name) . ' - ' .
|
||||
$action->description);
|
||||
}
|
||||
$output .= html_writer::end_tag('ul');
|
||||
$output .= $this->footer();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a page that is just a simple message.
|
||||
* @param string $message the message to display.
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function simple_message_page($message) {
|
||||
$output = '';
|
||||
$output .= $this->header();
|
||||
$output .= $this->heading($message);
|
||||
$output .= $this->back_to_index();
|
||||
$output .= $this->footer();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the confirm batch operation page
|
||||
* @param stdClass $data Submitted form data with list of assignments to upgrade
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function confirm_batch_operation_page(stdClass $data) {
|
||||
$output = '';
|
||||
$output .= $this->header();
|
||||
|
||||
$output .= $this->heading(get_string('confirmbatchupgrade', 'tool_assignmentupgrade'));
|
||||
$output .= $this->output->spacer(array(), true);
|
||||
|
||||
$output .= $this->container_start('tool_assignmentupgrade_confirmbatch');
|
||||
|
||||
$output .= $this->render(new tool_assignmentupgrade_batchoperationconfirm($data));
|
||||
$output .= $this->container_end();
|
||||
|
||||
$output .= $this->back_to_index();
|
||||
$output .= $this->footer();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the confirm batch continue / cancel links
|
||||
* @param tool_assignmentupgrade_batchoperationconfirm $confirm Wrapper class to determine the continue message and url
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function render_tool_assignmentupgrade_batchoperationconfirm(tool_assignmentupgrade_batchoperationconfirm $confirm) {
|
||||
$output = '';
|
||||
|
||||
if ($confirm->continueurl) {
|
||||
$output .= $this->output->confirm($confirm->continuemessage,
|
||||
$confirm->continueurl,
|
||||
tool_assignmentupgrade_url('listnotupgraded'));
|
||||
} else {
|
||||
$output .= $this->output->box($confirm->continuemessage);
|
||||
$output .= $this->output->continue_button(tool_assignmentupgrade_url('listnotupgraded'));
|
||||
}
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the list of assignments that still need to be upgraded page.
|
||||
* @param tool_assignmentupgrade_assignments_table $assignments of data about assignments.
|
||||
* @param tool_assignmentupgrade_batchoperations_form $batchform Submitted form with list of assignments to upgrade
|
||||
* @param tool_assignmentupgrade_pagination_form $paginationform Form which contains the preferences for paginating the table
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function assignment_list_page(tool_assignmentupgrade_assignments_table $assignments,
|
||||
tool_assignmentupgrade_batchoperations_form $batchform,
|
||||
tool_assignmentupgrade_pagination_form $paginationform) {
|
||||
$output = '';
|
||||
$output .= $this->header();
|
||||
$this->page->requires->js_init_call('M.tool_assignmentupgrade.init_upgrade_table', array());
|
||||
$this->page->requires->string_for_js('noassignmentsselected', 'tool_assignmentupgrade');
|
||||
|
||||
$output .= $this->heading(get_string('notupgradedtitle', 'tool_assignmentupgrade'));
|
||||
$output .= $this->box(get_string('notupgradedintro', 'tool_assignmentupgrade'));
|
||||
$output .= $this->output->spacer(array(), true);
|
||||
|
||||
$output .= $this->container_start('tool_assignmentupgrade_upgradetable');
|
||||
|
||||
$output .= $this->container_start('tool_assignmentupgrade_paginationform');
|
||||
$output .= $this->moodleform($paginationform);
|
||||
$output .= $this->container_end();
|
||||
|
||||
$output .= $this->flexible_table($assignments, $assignments->get_rows_per_page(), true);
|
||||
$output .= $this->container_end();
|
||||
|
||||
if ($assignments->anyupgradableassignments) {
|
||||
$output .= $this->container_start('tool_assignmentupgrade_batchform');
|
||||
$output .= $this->moodleform($batchform);
|
||||
$output .= $this->container_end();
|
||||
}
|
||||
|
||||
$output .= $this->back_to_index();
|
||||
$output .= $this->footer();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the result of an assignment conversion
|
||||
* @param stdClass $assignmentsummary data about the assignment to upgrade.
|
||||
* @param bool $success Set to true if the outcome of the conversion was a success
|
||||
* @param string $log The log from the conversion
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function convert_assignment_result($assignmentsummary, $success, $log) {
|
||||
$output = '';
|
||||
|
||||
$output .= $this->container_start('tool_assignmentupgrade_result');
|
||||
$output .= $this->container(get_string('upgradeassignmentsummary', 'tool_assignmentupgrade', $assignmentsummary));
|
||||
if (!$success) {
|
||||
$output .= $this->container(get_string('conversionfailed', 'tool_assignmentupgrade', $log));
|
||||
} else {
|
||||
$output .= $this->container(get_string('upgradeassignmentsuccess', 'tool_assignmentupgrade'));
|
||||
$url = new moodle_url('/course/view.php', array('id'=>$assignmentsummary->courseid));
|
||||
$output .= $this->container(html_writer::link($url, get_string('viewcourse', 'tool_assignmentupgrade')));
|
||||
}
|
||||
$output .= $this->container_end();
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render the are-you-sure page to confirm a manual upgrade.
|
||||
* @param stdClass $assignmentsummary data about the assignment to upgrade.
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function convert_assignment_are_you_sure($assignmentsummary) {
|
||||
$output = '';
|
||||
$output .= $this->header();
|
||||
$output .= $this->heading(get_string('areyousure', 'tool_assignmentupgrade'));
|
||||
|
||||
$params = array('id' => $assignmentsummary->id, 'confirmed' => 1, 'sesskey' => sesskey());
|
||||
$output .= $this->confirm(get_string('areyousuremessage', 'tool_assignmentupgrade', $assignmentsummary),
|
||||
new single_button(tool_assignmentupgrade_url('upgradesingle', $params), get_string('yes')),
|
||||
tool_assignmentupgrade_url('listnotupgraded'));
|
||||
|
||||
$output .= $this->footer();
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method dealing with the fact we can not just fetch the output of flexible_table
|
||||
*
|
||||
* @param flexible_table $table
|
||||
* @param int $rowsperpage
|
||||
* @param bool $displaylinks Show links in the table
|
||||
* @return string HTML
|
||||
*/
|
||||
protected function flexible_table(flexible_table $table, $rowsperpage, $displaylinks) {
|
||||
|
||||
$o = '';
|
||||
ob_start();
|
||||
$table->out($rowsperpage, $displaylinks);
|
||||
$o = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper method dealing with the fact we can not just fetch the output of moodleforms
|
||||
*
|
||||
* @param moodleform $mform
|
||||
* @return string HTML
|
||||
*/
|
||||
protected function moodleform(moodleform $mform) {
|
||||
|
||||
$o = '';
|
||||
ob_start();
|
||||
$mform->display();
|
||||
$o = ob_get_contents();
|
||||
ob_end_clean();
|
||||
|
||||
return $o;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render a link in a div, such as the 'Back to plugin main page' link.
|
||||
* @param string|moodle_url $url the link URL.
|
||||
* @param string $text the link text.
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function end_of_page_link($url, $text) {
|
||||
return html_writer::tag('div', html_writer::link($url, $text), array('class' => 'mdl-align'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Output a link back to the plugin index page.
|
||||
* @return string html to output.
|
||||
*/
|
||||
public function back_to_index() {
|
||||
return $this->end_of_page_link(tool_assignmentupgrade_url('index'), get_string('backtoindex', 'tool_assignmentupgrade'));
|
||||
}
|
||||
}
|
||||
@@ -15,21 +15,18 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Capability definitions for Nextcloud repository.
|
||||
* Adds this plugin to the admin menu.
|
||||
*
|
||||
* @package repository_nextcloud
|
||||
* @copyright 2017 Project seminar (Learnweb, University of Münster)
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
defined('MOODLE_INTERNAL') || die;
|
||||
|
||||
$capabilities = array(
|
||||
'repository/nextcloud:view' => array(
|
||||
'captype' => 'read',
|
||||
'contextlevel' => CONTEXT_MODULE,
|
||||
'archetypes' => array(
|
||||
'user' => CAP_ALLOW
|
||||
)
|
||||
)
|
||||
);
|
||||
if ($hassiteconfig) {
|
||||
// Needs this condition or there is error on login page.
|
||||
$ADMIN->add('root', new admin_externalpage('assignmentupgrade',
|
||||
get_string('pluginname', 'tool_assignmentupgrade'),
|
||||
new moodle_url('/admin/tool/assignmentupgrade/index.php')));
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
#page-admin-tool-assignmentupgrade-listnotupgraded .tool_assignmentupgrade_upgradetable .c0 {
|
||||
display: none;
|
||||
}
|
||||
|
||||
#page-admin-tool-assignmentupgrade-listnotupgraded.jsenabled .tool_assignmentupgrade_upgradetable .c0 {
|
||||
display: table-cell;
|
||||
}
|
||||
/*
|
||||
.gradingbatchoperationsform { display: none; }
|
||||
.jsenabled .gradingbatchoperationsform { display: block; }
|
||||
*/
|
||||
|
||||
#page-admin-tool-assignmentupgrade-listnotupgraded .tool_assignmentupgrade_upgradetable tr.selectedrow td {
|
||||
background-color: #fec;
|
||||
}
|
||||
|
||||
#page-admin-tool-assignmentupgrade-listnotupgraded .tool_assignmentupgrade_upgradetable tr.unselectedrow td {
|
||||
background-color: white;
|
||||
}
|
||||
|
||||
#page-admin-tool-assignmentupgrade-listnotupgraded .tool_assignmentupgrade_paginationform .hidden {
|
||||
display: none;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Privacy tests for tool_assignmentupgrade.
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @category test
|
||||
* @copyright 2018 Zig Tan <zig@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use \core_privacy\tests\provider_testcase;
|
||||
use \core_privacy\local\request\writer;
|
||||
use \tool_assignmentupgrade\privacy\provider;
|
||||
|
||||
/**
|
||||
* Unit tests for tool_assignmentupgrade/classes/privacy/policy
|
||||
*
|
||||
* @copyright 2018 Zig Tan <zig@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_assignmentupgrade_privacy_testcase extends provider_testcase {
|
||||
|
||||
/**
|
||||
* Overriding setUp() function to always reset after tests.
|
||||
*/
|
||||
public function setUp() {
|
||||
$this->resetAfterTest(true);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test for provider::test_export_user_preferences().
|
||||
*/
|
||||
public function test_export_user_preferences() {
|
||||
// Test setup.
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$this->setUser($user);
|
||||
|
||||
// Add a user home page preference for the User.
|
||||
set_user_preference('tool_assignmentupgrade_perpage', '100', $user);
|
||||
|
||||
// Test the user preference exists.
|
||||
$params = [
|
||||
'userid' => $user->id,
|
||||
'name' => 'tool_assignmentupgrade_perpage'
|
||||
];
|
||||
|
||||
// Test the user preferences export contains 1 user preference record for the User.
|
||||
provider::export_user_preferences($user->id);
|
||||
$contextuser = context_user::instance($user->id);
|
||||
$writer = writer::with_context($contextuser);
|
||||
$this->assertTrue($writer->has_any_data());
|
||||
|
||||
$exportedpreferences = $writer->get_user_preferences('tool_assignmentupgrade');
|
||||
$this->assertCount(1, (array) $exportedpreferences);
|
||||
$this->assertEquals('100', $exportedpreferences->perpage->value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This file contains the forms to create and edit an instance of this module
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die('Direct access to this script is forbidden.');
|
||||
|
||||
require_once($CFG->libdir.'/formslib.php');
|
||||
|
||||
/**
|
||||
* Assignment upgrade batch operations form.
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_assignmentupgrade_batchoperations_form extends moodleform {
|
||||
/**
|
||||
* Define this form - is called from parent constructor.
|
||||
*/
|
||||
public function definition() {
|
||||
$mform = $this->_form;
|
||||
$instance = $this->_customdata;
|
||||
|
||||
$mform->addElement('header', 'general', get_string('batchoperations', 'tool_assignmentupgrade'));
|
||||
// Visible elements.
|
||||
$mform->addElement('hidden', 'selectedassignments', '', array('class'=>'selectedassignments'));
|
||||
$mform->setType('selectedassignments', PARAM_SEQUENCE);
|
||||
|
||||
$mform->addElement('submit', 'upgradeselected', get_string('upgradeselected', 'tool_assignmentupgrade'));
|
||||
$mform->addElement('submit', 'upgradeall', get_string('upgradeall', 'tool_assignmentupgrade'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,182 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This file contains the definition for the grading table which subclassses easy_table
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir.'/tablelib.php');
|
||||
require_once($CFG->libdir.'/gradelib.php');
|
||||
require_once($CFG->dirroot.'/mod/assign/locallib.php');
|
||||
|
||||
/**
|
||||
* Extends table_sql to provide a table of assignment submissions
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot {@link http://www.netspot.com.au}
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_assignmentupgrade_assignments_table extends table_sql implements renderable {
|
||||
|
||||
/** @var int $perpage */
|
||||
private $perpage = 10;
|
||||
/** @var int $rownum (global index of current row in table) */
|
||||
private $rownum = -1;
|
||||
/** @var renderer_base for getting output */
|
||||
private $output = null;
|
||||
/** @var boolean anyupgradableassignments - True if there is one or more assignments that can upgraded */
|
||||
public $anyupgradableassignments = false;
|
||||
|
||||
/**
|
||||
* This table loads a list of the old assignment instances and tests them to see
|
||||
* if they can be upgraded
|
||||
*
|
||||
* @param int $perpage How many per page
|
||||
* @param int $rowoffset The starting row for pagination
|
||||
*/
|
||||
public function __construct($perpage, $rowoffset=0) {
|
||||
global $PAGE;
|
||||
parent::__construct('tool_assignmentupgrade_assignments');
|
||||
$this->perpage = $perpage;
|
||||
$this->output = $PAGE->get_renderer('tool_assignmentupgrade');
|
||||
|
||||
$this->define_baseurl(new moodle_url('/admin/tool/assignmentupgrade/listnotupgraded.php'));
|
||||
|
||||
$this->anyupgradableassignments = tool_assignmentupgrade_any_upgradable_assignments();
|
||||
|
||||
// Do some business - then set the sql.
|
||||
if ($rowoffset) {
|
||||
$this->rownum = $rowoffset - 1;
|
||||
}
|
||||
|
||||
$fields = 'a.id as id,
|
||||
a.name as name,
|
||||
a.assignmenttype as type,
|
||||
c.shortname as courseshortname,
|
||||
c.id as courseid,
|
||||
COUNT(s.id) as submissioncount';
|
||||
$from = '{assignment} a JOIN {course} c ON a.course = c.id ' .
|
||||
' LEFT JOIN {assignment_submissions} s ON a.id = s.assignment';
|
||||
|
||||
$where = '1 = 1';
|
||||
$where .= ' GROUP BY a.id, a.name, a.assignmenttype, c.shortname, c.id ';
|
||||
|
||||
$this->set_sql($fields, $from, $where, array());
|
||||
$this->set_count_sql('SELECT COUNT(*) FROM {assignment} a JOIN {course} c ON a.course = c.id', array());
|
||||
|
||||
$columns = array();
|
||||
$headers = array();
|
||||
|
||||
$columns[] = 'select';
|
||||
$headers[] = get_string('select', 'tool_assignmentupgrade') .
|
||||
'<div class="selectall">' .
|
||||
'<input type="checkbox" name="selectall" title="' . get_string('selectall') . '"/>' .
|
||||
'</div>';
|
||||
$columns[] = 'upgradable';
|
||||
$headers[] = get_string('upgradable', 'tool_assignmentupgrade');
|
||||
$columns[] = 'id';
|
||||
$headers[] = get_string('assignmentid', 'tool_assignmentupgrade');
|
||||
$columns[] = 'courseshortname';
|
||||
$headers[] = get_string('course');
|
||||
$columns[] = 'name';
|
||||
$headers[] = get_string('name');
|
||||
$columns[] = 'type';
|
||||
$headers[] = get_string('assignmenttype', 'tool_assignmentupgrade');
|
||||
$columns[] = 'submissioncount';
|
||||
$headers[] = get_string('submissions', 'tool_assignmentupgrade');
|
||||
|
||||
// Set the columns.
|
||||
$this->define_columns($columns);
|
||||
$this->define_headers($headers);
|
||||
$this->no_sorting('upgradable');
|
||||
$this->no_sorting('select');
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of rows to display on a single page
|
||||
*
|
||||
* @return int The number of rows per page
|
||||
*/
|
||||
public function get_rows_per_page() {
|
||||
return $this->perpage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format a link to the assignment instance
|
||||
*
|
||||
* @param stdClass $row
|
||||
* @return string
|
||||
*/
|
||||
public function col_name(stdClass $row) {
|
||||
$url = new moodle_url('/mod/assignment/view.php', array('a' => $row->id));
|
||||
return html_writer::link($url, $row->name);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Format a link to the upgrade single tool
|
||||
*
|
||||
* @param stdClass $row (contains cached result from previous upgradable check)
|
||||
* @return string
|
||||
*/
|
||||
public function col_upgradable(stdClass $row) {
|
||||
if ($row->upgradable) {
|
||||
$urlparams = array('id' => $row->id, 'sesskey' => sesskey());
|
||||
$url = new moodle_url('/admin/tool/assignmentupgrade/upgradesingleconfirm.php', $urlparams);
|
||||
return html_writer::link($url, get_string('supported', 'tool_assignmentupgrade'));
|
||||
} else {
|
||||
return get_string('notsupported', 'tool_assignmentupgrade');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert a checkbox for selecting the current row for batch operations
|
||||
*
|
||||
* @param stdClass $row
|
||||
* @return string
|
||||
*/
|
||||
public function col_select(stdClass $row) {
|
||||
global $CFG;
|
||||
$version = get_config('assignment_' . $row->type, 'version');
|
||||
require_once($CFG->dirroot . '/mod/assign/locallib.php');
|
||||
if (assign::can_upgrade_assignment($row->type, $version)) {
|
||||
$row->upgradable = true;
|
||||
return '<input type="checkbox" name="selectedassignment" value="' . $row->id . '"/>';
|
||||
}
|
||||
$row->upgradable = false;
|
||||
return '';
|
||||
}
|
||||
|
||||
/**
|
||||
* Override the table show_hide_link to not show for select column
|
||||
*
|
||||
* @param string $column the column name, index into various names.
|
||||
* @param int $index numerical index of the column.
|
||||
* @return string HTML fragment.
|
||||
*/
|
||||
protected function show_hide_link($column, $index) {
|
||||
if ($index > 0) {
|
||||
return parent::show_hide_link($column, $index);
|
||||
}
|
||||
return '';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,49 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Script to show all the assignments that have not been upgraded after the main upgrade.
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . '/../../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/locallib.php');
|
||||
|
||||
require_sesskey();
|
||||
|
||||
$assignmentid = required_param('id', PARAM_INT);
|
||||
|
||||
// This calls require_login and checks moodle/site:config.
|
||||
admin_externalpage_setup('assignmentupgrade',
|
||||
'',
|
||||
array(),
|
||||
tool_assignmentupgrade_url('upgradesingle', array('id' => $assignmentid)));
|
||||
|
||||
$PAGE->navbar->add(get_string('upgradesingle', 'tool_assignmentupgrade'));
|
||||
$renderer = $PAGE->get_renderer('tool_assignmentupgrade');
|
||||
|
||||
$log = '';
|
||||
list($summary, $success, $log) = tool_assignmentupgrade_upgrade_assignment($assignmentid);
|
||||
|
||||
echo $renderer->header();
|
||||
echo $renderer->heading(get_string('conversioncomplete', 'tool_assignmentupgrade'));
|
||||
echo $renderer->convert_assignment_result($summary, $success, $log);
|
||||
echo $renderer->continue_button(tool_assignmentupgrade_url('listnotupgraded'));
|
||||
echo $renderer->footer();
|
||||
@@ -0,0 +1,44 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Script to show all the assignments that have not been upgraded after the main upgrade.
|
||||
*
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
require_once(__DIR__ . '/../../../config.php');
|
||||
require_once($CFG->libdir . '/adminlib.php');
|
||||
require_once($CFG->dirroot . '/'.$CFG->admin.'/tool/assignmentupgrade/locallib.php');
|
||||
|
||||
require_sesskey();
|
||||
|
||||
$assignmentid = required_param('id', PARAM_INT);
|
||||
|
||||
// This calls require_login and checks moodle/site:config.
|
||||
admin_externalpage_setup('assignmentupgrade',
|
||||
'',
|
||||
array(),
|
||||
tool_assignmentupgrade_url('upgradesingle', array('id' => $assignmentid)));
|
||||
|
||||
$PAGE->navbar->add(get_string('upgradesingle', 'tool_assignmentupgrade'));
|
||||
$renderer = $PAGE->get_renderer('tool_assignmentupgrade');
|
||||
|
||||
$assignmentinfo = tool_assignmentupgrade_get_assignment($assignmentid);
|
||||
|
||||
echo $renderer->convert_assignment_are_you_sure($assignmentinfo);
|
||||
@@ -15,18 +15,16 @@
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* This file defines observers needed by the plugin.
|
||||
* Version details.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
|
||||
* @package tool_assignmentupgrade
|
||||
* @copyright 2012 NetSpot
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$observers = [
|
||||
[
|
||||
'eventname' => '\core\event\user_deleted',
|
||||
'callback' => '\tool_dataprivacy\event\user_deleted_observer::create_delete_data_request',
|
||||
],
|
||||
];
|
||||
$plugin->version = 2018051400;
|
||||
$plugin->requires = 2018050800;
|
||||
$plugin->component = 'tool_assignmentupgrade';
|
||||
$plugin->dependencies = array('mod_assign' => 2018050800);
|
||||
@@ -20,7 +20,7 @@ Feature: Manage availability conditions
|
||||
And the following config values are set as admin:
|
||||
| enableavailability | 1 |
|
||||
And I am on homepage
|
||||
And I navigate to "Plugins > Availability restrictions > Manage restrictions" in site administration
|
||||
And I navigate to "Manage restrictions" node in "Site administration > Plugins > Availability restrictions"
|
||||
|
||||
# Having clicked on it, I should also see the list of plugins.
|
||||
And I should see "Restriction by date"
|
||||
@@ -34,7 +34,7 @@ Feature: Manage availability conditions
|
||||
| Course 1 | C1 | topics |
|
||||
And I log in as "admin"
|
||||
And I am on site homepage
|
||||
When I navigate to "Plugins > Availability restrictions > Manage restrictions" in site administration
|
||||
When I navigate to "Manage restrictions" node in "Site administration > Plugins > Availability restrictions"
|
||||
|
||||
# Check the icon is there (it should be a Hide icon, meaning is currently visible).
|
||||
Then "Hide" "icon" should exist in the "Restriction by date" "table_row"
|
||||
|
||||
@@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2018120300;
|
||||
$plugin->requires = 2018112800;
|
||||
$plugin->version = 2018051400;
|
||||
$plugin->requires = 2018050800;
|
||||
$plugin->component = 'tool_availabilityconditions';
|
||||
|
||||
@@ -23,29 +23,29 @@
|
||||
*/
|
||||
|
||||
$string['aim'] = 'This administration tool helps developers and test writers to create .feature files describing Moodle\'s functionalities and run them automatically. Step definitions available for use in .feature files are listed below.';
|
||||
$string['allavailablesteps'] = 'All available step definitions';
|
||||
$string['allavailablesteps'] = 'All the available steps definitions';
|
||||
$string['errorbehatcommand'] = 'Error running behat CLI command. Try running "{$a} --help" manually from CLI to find out more about the problem.';
|
||||
$string['errorcomposer'] = 'Composer dependencies are not installed.';
|
||||
$string['errordataroot'] = '$CFG->behat_dataroot is not set or is invalid.';
|
||||
$string['errorsetconfig'] = '$CFG->behat_dataroot, $CFG->behat_prefix and $CFG->behat_wwwroot need to be set in config.php.';
|
||||
$string['erroruniqueconfig'] = '$CFG->behat_dataroot, $CFG->behat_prefix and $CFG->behat_wwwroot values need to be different than $CFG->dataroot, $CFG->prefix, $CFG->wwwroot, $CFG->phpunit_dataroot and $CFG->phpunit_prefix values.';
|
||||
$string['fieldvalueargument'] = 'Field value arguments';
|
||||
$string['fieldvalueargument_help'] = 'This argument should be completed by a field value. There are many field types, including simple ones like checkboxes, selects or textareas, or complex ones like date selectors. See the dev documentation <a href="http://docs.moodle.org/dev/Acceptance_testing" target="_blank">Acceptance_testing</a> for details of expected field values.';
|
||||
$string['fieldvalueargument_help'] = 'This argument should be completed by a field value, there are many field types, simple ones like checkboxes, selects or textareas or complex ones like date selectors. You can check <a href="http://docs.moodle.org/dev/Acceptance_testing#Providing_values_to_steps" target="_blank">Field values</a> to see the expected field value depending on the field type you provide.';
|
||||
$string['giveninfo'] = 'Given. Processes to set up the environment';
|
||||
$string['infoheading'] = 'Info';
|
||||
$string['installinfo'] = 'Read {$a} for installation and tests execution info';
|
||||
$string['newstepsinfo'] = 'Read {$a} for info about how to add new step definitions';
|
||||
$string['newstepsinfo'] = 'Read {$a} for info about how to add new steps definitions';
|
||||
$string['newtestsinfo'] = 'Read {$a} for info about how to write new tests';
|
||||
$string['nostepsdefinitions'] = 'There aren\'t any step definitions matching this filter';
|
||||
$string['nostepsdefinitions'] = 'There aren\'t steps definitions matching this filters';
|
||||
$string['pluginname'] = 'Acceptance testing';
|
||||
$string['stepsdefinitionscomponent'] = 'Area';
|
||||
$string['stepsdefinitionscontains'] = 'Contains';
|
||||
$string['stepsdefinitionsfilters'] = 'Step definitions';
|
||||
$string['stepsdefinitionsfilters'] = 'Steps definitions';
|
||||
$string['stepsdefinitionstype'] = 'Type';
|
||||
$string['theninfo'] = 'Then. Checkings to ensure the outcomes are the expected ones';
|
||||
$string['unknownexceptioninfo'] = 'There was a problem with Selenium or your browser. Please ensure you are using the latest version of Selenium. Error:';
|
||||
$string['viewsteps'] = 'Filter';
|
||||
$string['wheninfo'] = 'When. Action that provokes an event';
|
||||
$string['wheninfo'] = 'When. Actions that provokes an event';
|
||||
$string['wrongbehatsetup'] = 'Something is wrong with the behat setup and so step definitions cannot be listed: <b>{$a->errormsg}</b><br/><br/>Please check:<ul>
|
||||
<li>$CFG->behat_dataroot, $CFG->behat_prefix and $CFG->behat_wwwroot are set in config.php with different values from $CFG->dataroot, $CFG->prefix and $CFG->wwwroot.</li>
|
||||
<li>You ran "{$a->behatinit}" from your Moodle root directory.</li>
|
||||
|
||||
@@ -286,7 +286,7 @@ Feature: Set up contextual data for tests
|
||||
| student1 | CHSB |
|
||||
| student1 | CHC |
|
||||
When I log in as "admin"
|
||||
And I navigate to "Users > Accounts > Cohorts" in site administration
|
||||
And I navigate to "Cohorts" node in "Site administration > Users > Accounts"
|
||||
Then the following should exist in the "cohorts" table:
|
||||
| Name | Cohort size |
|
||||
| System cohort A | 1 |
|
||||
|
||||
@@ -34,7 +34,7 @@ Feature: Verify that all form fields values can be get and set
|
||||
| wiki | C1 | wiki1 | Test this one | Test this one | Test this one | collaborative | 0 |
|
||||
And I log in as "admin"
|
||||
And I am on "Course 1" course homepage
|
||||
And I navigate to "Reset" in current page administration
|
||||
And I navigate to "Reset" node in "Course administration"
|
||||
# Select (multi-select) - Checking "the select box should contain".
|
||||
And I expand all fieldsets
|
||||
And the "Unenrol users" select box should contain "No roles"
|
||||
@@ -131,12 +131,12 @@ Feature: Verify that all form fields values can be get and set
|
||||
And the field "two" matches value ""
|
||||
# Check if field xpath set/match works.
|
||||
And I am on "Course 1" course homepage
|
||||
And I navigate to "Edit settings" in current page administration
|
||||
And I navigate to "Edit settings" node in "Course administration"
|
||||
And I set the field with xpath "//input[@id='id_idnumber']" to "Course id number"
|
||||
And the field with xpath "//input[@name='idnumber']" matches value "Course id number"
|
||||
And the field with xpath "//input[@name='idnumber']" does not match value ""
|
||||
And I press "Save and display"
|
||||
And I navigate to "Edit settings" in current page administration
|
||||
And I navigate to "Edit settings" node in "Course administration"
|
||||
And the field "Course ID number" matches value "Course id number"
|
||||
|
||||
Scenario: with JS disabled all form fields getters and setters works as expected
|
||||
|
||||
@@ -7,11 +7,11 @@ Feature: List the system steps definitions
|
||||
Background:
|
||||
Given I am on homepage
|
||||
And I log in as "admin"
|
||||
And I navigate to "Development > Acceptance testing" in site administration
|
||||
And I navigate to "Acceptance testing" node in "Site administration > Development"
|
||||
|
||||
@javascript
|
||||
Scenario: Accessing the list
|
||||
Then I should see "Step definitions"
|
||||
Then I should see "Steps definitions"
|
||||
And I should not see "There aren't steps definitions matching this filter"
|
||||
|
||||
@javascript
|
||||
|
||||
@@ -0,0 +1,199 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Unit tests for behat manager.
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
global $CFG;
|
||||
require_once($CFG->dirroot . '/' . $CFG->admin .'/tool/behat/locallib.php');
|
||||
require_once($CFG->libdir . '/behat/classes/util.php');
|
||||
require_once($CFG->libdir . '/behat/classes/behat_config_manager.php');
|
||||
|
||||
/**
|
||||
* Behat manager tests.
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class tool_behat_manager_testcase extends advanced_testcase {
|
||||
|
||||
/**
|
||||
* behat_config_manager tests.
|
||||
*/
|
||||
public function test_merge_configs() {
|
||||
|
||||
// Simple default config.
|
||||
$array1 = array(
|
||||
'the' => 'same',
|
||||
'simple' => 'value',
|
||||
'array' => array(
|
||||
'one' => 'arrayvalue1',
|
||||
'two' => 'arrayvalue2'
|
||||
)
|
||||
);
|
||||
|
||||
// Simple override.
|
||||
$array2 = array(
|
||||
'simple' => 'OVERRIDDEN1',
|
||||
'array' => array(
|
||||
'one' => 'OVERRIDDEN2'
|
||||
),
|
||||
'newprofile' => array(
|
||||
'anotherlevel' => array(
|
||||
'andanotherone' => array(
|
||||
'list1',
|
||||
'list2'
|
||||
)
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
$array = testable_behat_config_manager::merge_config($array1, $array2);
|
||||
$this->assertDebuggingCalled("Use of merge_config is deprecated, please see behat_config_util");
|
||||
|
||||
// Overrides are applied.
|
||||
$this->assertEquals('OVERRIDDEN1', $array['simple']);
|
||||
$this->assertEquals('OVERRIDDEN2', $array['array']['one']);
|
||||
|
||||
// Other values are respected.
|
||||
$this->assertNotEmpty($array['array']['two']);
|
||||
|
||||
// Completely new nodes are added.
|
||||
$this->assertNotEmpty($array['newprofile']);
|
||||
$this->assertNotEmpty($array['newprofile']['anotherlevel']['andanotherone']);
|
||||
$this->assertEquals('list1', $array['newprofile']['anotherlevel']['andanotherone'][0]);
|
||||
$this->assertEquals('list2', $array['newprofile']['anotherlevel']['andanotherone'][1]);
|
||||
|
||||
// Complex override changing vectors to scalars and scalars to vectors.
|
||||
$array2 = array(
|
||||
'simple' => array(
|
||||
'simple' => 'should',
|
||||
'be' => 'overridden',
|
||||
'by' => 'this-array'
|
||||
),
|
||||
'array' => 'one'
|
||||
);
|
||||
|
||||
$array = testable_behat_config_manager::merge_config($array1, $array2);
|
||||
$this->assertDebuggingCalled("Use of merge_config is deprecated, please see behat_config_util");
|
||||
|
||||
// Overrides applied.
|
||||
$this->assertNotEmpty($array['simple']);
|
||||
$this->assertNotEmpty($array['array']);
|
||||
$this->assertTrue(is_array($array['simple']));
|
||||
$this->assertFalse(is_array($array['array']));
|
||||
|
||||
// Other values are maintained.
|
||||
$this->assertEquals('same', $array['the']);
|
||||
}
|
||||
|
||||
/**
|
||||
* behat_config_manager tests.
|
||||
*/
|
||||
public function test_config_file_contents() {
|
||||
global $CFG;
|
||||
|
||||
$this->resetAfterTest(true);
|
||||
|
||||
// Skip tests if behat is not installed.
|
||||
$vendorpath = $CFG->dirroot . '/vendor';
|
||||
if (!file_exists($vendorpath . '/autoload.php') || !is_dir($vendorpath . '/behat')) {
|
||||
$this->markTestSkipped('Behat not installed.');
|
||||
}
|
||||
|
||||
// Add some fake test url.
|
||||
$CFG->behat_wwwroot = 'http://example.com/behat';
|
||||
|
||||
// To avoid user value at config.php level.
|
||||
unset($CFG->behat_config);
|
||||
|
||||
// List.
|
||||
$features = array(
|
||||
'feature1',
|
||||
'feature2',
|
||||
'feature3'
|
||||
);
|
||||
|
||||
// Associative array.
|
||||
$stepsdefinitions = array(
|
||||
'micarro' => '/me/lo/robaron',
|
||||
'anoche' => '/cuando/yo/dormia'
|
||||
);
|
||||
|
||||
$contents = testable_behat_config_manager::get_config_file_contents($features, $stepsdefinitions);
|
||||
$this->assertDebuggingCalled("Use of get_config_file_contents is deprecated, please see behat_config_util");
|
||||
|
||||
// YAML decides when is is necessary to wrap strings between single quotes, so not controlled
|
||||
// values like paths should not be asserted including the key name as they would depend on the
|
||||
// directories values.
|
||||
$this->assertContains($CFG->dirroot,
|
||||
$contents['default']['extensions']['Moodle\BehatExtension']['moodledirroot']);
|
||||
|
||||
// Not quoted strings.
|
||||
$this->assertEquals('/me/lo/robaron',
|
||||
$contents['default']['extensions']['Moodle\BehatExtension']['steps_definitions']['micarro']);
|
||||
|
||||
// YAML uses single quotes to wrap URL strings.
|
||||
$this->assertEquals($CFG->behat_wwwroot, $contents['default']['extensions']['Behat\MinkExtension']['base_url']);
|
||||
|
||||
// Lists.
|
||||
$this->assertEquals('feature1', $contents['default']['suites']['default']['paths'][0]);
|
||||
$this->assertEquals('feature3', $contents['default']['suites']['default']['paths'][2]);
|
||||
|
||||
unset($CFG->behat_wwwroot);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Allows access to internal methods without exposing them.
|
||||
*
|
||||
* @package tool_behat
|
||||
* @copyright 2012 David Monllaó
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class testable_behat_config_manager extends behat_config_manager {
|
||||
|
||||
/**
|
||||
* Allow access to protected method
|
||||
* @see parent::merge_config()
|
||||
* @param mixed $config
|
||||
* @param mixed $localconfig
|
||||
* @return mixed
|
||||
*/
|
||||
public static function merge_config($config, $localconfig) {
|
||||
return parent::merge_config($config, $localconfig);
|
||||
}
|
||||
|
||||
/**
|
||||
* Allow access to protected method
|
||||
* @see parent::get_config_file_contents()
|
||||
* @param array $features
|
||||
* @param array $stepsdefinitions
|
||||
* @return string
|
||||
*/
|
||||
public static function get_config_file_contents($features, $stepsdefinitions) {
|
||||
return parent::get_config_file_contents($features, $stepsdefinitions);
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2018120300; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2018112800; // Requires this Moodle version
|
||||
$plugin->version = 2018051400; // The current plugin version (Date: YYYYMMDDXX)
|
||||
$plugin->requires = 2018050800; // Requires this Moodle version
|
||||
$plugin->component = 'tool_behat'; // Full name of the plugin (used for diagnostics)
|
||||
|
||||
@@ -24,6 +24,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2018120300; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2018112800; // Requires this Moodle version.
|
||||
$plugin->version = 2018051400; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2018050800; // Requires this Moodle version.
|
||||
$plugin->component = 'tool_capability'; // Full name of the plugin (used for diagnostics).
|
||||
|
||||
@@ -30,8 +30,6 @@ use core_privacy\local\request\context;
|
||||
use core_privacy\local\request\contextlist;
|
||||
use core_privacy\local\request\transform;
|
||||
use core_privacy\local\request\writer;
|
||||
use core_privacy\local\request\userlist;
|
||||
use \core_privacy\local\request\approved_userlist;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -41,10 +39,7 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @copyright 2018 Zig Tan <zig@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class provider implements
|
||||
\core_privacy\local\metadata\provider,
|
||||
\core_privacy\local\request\core_userlist_provider,
|
||||
\core_privacy\local\request\plugin\provider {
|
||||
class provider implements \core_privacy\local\metadata\provider, \core_privacy\local\request\plugin\provider {
|
||||
|
||||
/**
|
||||
* Returns meta data about this system.
|
||||
@@ -80,25 +75,15 @@ class provider implements
|
||||
public static function get_contexts_for_userid(int $userid) : contextlist {
|
||||
$contextlist = new contextlist();
|
||||
|
||||
// When we process user deletions and expiries, we always delete from the user context.
|
||||
// As a result the cohort role assignments would be deleted, which has a knock-on effect with courses
|
||||
// as roles may change and data may be removed earlier than it should be.
|
||||
|
||||
// Retrieve the context associated with tool_cohortroles records.
|
||||
$sql = "SELECT DISTINCT c.contextid
|
||||
FROM {tool_cohortroles} tc
|
||||
JOIN {cohort} c
|
||||
ON tc.cohortid = c.id
|
||||
JOIN {context} ctx
|
||||
ON ctx.id = c.contextid
|
||||
WHERE tc.userid = :userid
|
||||
AND (ctx.contextlevel = :contextlevel1
|
||||
OR ctx.contextlevel = :contextlevel2)";
|
||||
// Retrieve the User context associated with tool_cohortroles records.
|
||||
$sql = "SELECT DISTINCT c.id
|
||||
FROM {context} c
|
||||
JOIN {tool_cohortroles} cr ON cr.userid = c.instanceid AND c.contextlevel = :contextuser
|
||||
WHERE cr.userid = :userid";
|
||||
|
||||
$params = [
|
||||
'userid' => $userid,
|
||||
'contextlevel1' => CONTEXT_SYSTEM,
|
||||
'contextlevel2' => CONTEXT_COURSECAT
|
||||
'contextuser' => CONTEXT_USER,
|
||||
'userid' => $userid
|
||||
];
|
||||
|
||||
$contextlist->add_from_sql($sql, $params);
|
||||
@@ -106,40 +91,6 @@ class provider implements
|
||||
return $contextlist;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of users within a specific context.
|
||||
*
|
||||
* @param userlist $userlist The userlist containing the list of users who have data in this context/plugin combination.
|
||||
*/
|
||||
public static function get_users_in_context(userlist $userlist) {
|
||||
$context = $userlist->get_context();
|
||||
|
||||
// When we process user deletions and expiries, we always delete from the user context.
|
||||
// As a result the cohort role assignments would be deleted, which has a knock-on effect with courses
|
||||
// as roles may change and data may be removed earlier than it should be.
|
||||
|
||||
$allowedcontextlevels = [
|
||||
CONTEXT_SYSTEM,
|
||||
CONTEXT_COURSECAT
|
||||
];
|
||||
|
||||
if (!in_array($context->contextlevel, $allowedcontextlevels)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$sql = "SELECT tc.userid as userid
|
||||
FROM {tool_cohortroles} tc
|
||||
JOIN {cohort} c
|
||||
ON tc.cohortid = c.id
|
||||
WHERE c.contextid = :contextid";
|
||||
|
||||
$params = [
|
||||
'contextid' => $context->id
|
||||
];
|
||||
|
||||
$userlist->add_from_sql('userid', $sql, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Export all user data for the specified user, in the specified contexts.
|
||||
*
|
||||
@@ -148,28 +99,24 @@ class provider implements
|
||||
public static function export_user_data(approved_contextlist $contextlist) {
|
||||
global $DB;
|
||||
|
||||
// Remove contexts different from SYSTEM or COURSECAT.
|
||||
$contextids = array_reduce($contextlist->get_contexts(), function($carry, $context) {
|
||||
if ($context->contextlevel == CONTEXT_SYSTEM || $context->contextlevel == CONTEXT_COURSECAT) {
|
||||
$carry[] = $context->id;
|
||||
}
|
||||
return $carry;
|
||||
}, []);
|
||||
|
||||
if (empty($contextids)) {
|
||||
// If the user has tool_cohortroles data, then only the User context should be present so get the first context.
|
||||
$contexts = $contextlist->get_contexts();
|
||||
if (count($contexts) == 0) {
|
||||
return;
|
||||
}
|
||||
$context = reset($contexts);
|
||||
|
||||
$userid = $contextlist->get_user()->id;
|
||||
|
||||
list($contextsql, $contextparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED);
|
||||
// Sanity check that context is at the User context level, then get the userid.
|
||||
if ($context->contextlevel !== CONTEXT_USER) {
|
||||
return;
|
||||
}
|
||||
$userid = $context->instanceid;
|
||||
|
||||
// Retrieve the tool_cohortroles records created for the user.
|
||||
$sql = "SELECT cr.id as cohortroleid,
|
||||
$sql = 'SELECT cr.id as cohortroleid,
|
||||
c.name as cohortname,
|
||||
c.idnumber as cohortidnumber,
|
||||
c.description as cohortdescription,
|
||||
c.contextid as contextid,
|
||||
r.shortname as roleshortname,
|
||||
cr.userid as userid,
|
||||
cr.timecreated as timecreated,
|
||||
@@ -177,13 +124,13 @@ class provider implements
|
||||
FROM {tool_cohortroles} cr
|
||||
JOIN {cohort} c ON c.id = cr.cohortid
|
||||
JOIN {role} r ON r.id = cr.roleid
|
||||
WHERE cr.userid = :userid
|
||||
AND c.contextid {$contextsql}";
|
||||
WHERE cr.userid = :userid';
|
||||
|
||||
$params = ['userid' => $userid] + $contextparams;
|
||||
$params = [
|
||||
'userid' => $userid
|
||||
];
|
||||
|
||||
$cohortroles = $DB->get_records_sql($sql, $params);
|
||||
|
||||
foreach ($cohortroles as $cohortrole) {
|
||||
// The tool_cohortroles data export is organised in:
|
||||
// {User Context}/Cohort roles management/{cohort name}/{role shortname}/data.json.
|
||||
@@ -203,8 +150,6 @@ class provider implements
|
||||
'timemodified' => transform::datetime($cohortrole->timemodified)
|
||||
];
|
||||
|
||||
$context = \context::instance_by_id($cohortrole->contextid);
|
||||
|
||||
writer::with_context($context)->export_data($subcontext, $data);
|
||||
}
|
||||
}
|
||||
@@ -217,70 +162,14 @@ class provider implements
|
||||
public static function delete_data_for_all_users_in_context(\context $context) {
|
||||
global $DB;
|
||||
|
||||
// When we process user deletions and expiries, we always delete from the user context.
|
||||
// As a result the cohort role assignments would be deleted, which has a knock-on effect with courses
|
||||
// as roles may change and data may be removed earlier than it should be.
|
||||
|
||||
$allowedcontextlevels = [
|
||||
CONTEXT_SYSTEM,
|
||||
CONTEXT_COURSECAT
|
||||
];
|
||||
|
||||
if (!in_array($context->contextlevel, $allowedcontextlevels)) {
|
||||
// Sanity check that context is at the User context level, then get the userid.
|
||||
if ($context->contextlevel !== CONTEXT_USER) {
|
||||
return;
|
||||
}
|
||||
$userid = $context->instanceid;
|
||||
|
||||
$cohortids = $DB->get_fieldset_select('cohort', 'id', 'contextid = :contextid',
|
||||
['contextid' => $context->id]);
|
||||
|
||||
// Delete the tool_cohortroles records created in the specific context.
|
||||
$DB->delete_records_list('tool_cohortroles', 'cohortid', $cohortids);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete multiple users within a single context.
|
||||
*
|
||||
* @param approved_userlist $userlist The approved context and user information to delete information for.
|
||||
*/
|
||||
public static function delete_data_for_users(approved_userlist $userlist) {
|
||||
global $DB;
|
||||
|
||||
// When we process user deletions and expiries, we always delete from the user context.
|
||||
// As a result the cohort role assignments would be deleted, which has a knock-on effect with courses
|
||||
// as roles may change and data may be removed earlier than it should be.
|
||||
|
||||
$userids = $userlist->get_userids();
|
||||
|
||||
if (empty($userids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$context = $userlist->get_context();
|
||||
|
||||
$allowedcontextlevels = [
|
||||
CONTEXT_SYSTEM,
|
||||
CONTEXT_COURSECAT
|
||||
];
|
||||
|
||||
if (!in_array($context->contextlevel, $allowedcontextlevels)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$cohortids = $DB->get_fieldset_select('cohort', 'id', 'contextid = :contextid',
|
||||
['contextid' => $context->id]);
|
||||
|
||||
if (empty($cohortids)) {
|
||||
return;
|
||||
}
|
||||
|
||||
list($cohortsql, $cohortparams) = $DB->get_in_or_equal($cohortids, SQL_PARAMS_NAMED);
|
||||
list($usersql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED);
|
||||
|
||||
$params = $cohortparams + $userparams;
|
||||
$select = "cohortid {$cohortsql} AND userid {$usersql}";
|
||||
|
||||
// Delete the tool_cohortroles records created in the specific context for an approved list of users.
|
||||
$DB->delete_records_select('tool_cohortroles', $select, $params);
|
||||
// Delete the tool_cohortroles records created for the userid.
|
||||
$DB->delete_records('tool_cohortroles', ['userid' => $userid]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -291,38 +180,21 @@ class provider implements
|
||||
public static function delete_data_for_user(approved_contextlist $contextlist) {
|
||||
global $DB;
|
||||
|
||||
// When we process user deletions and expiries, we always delete from the user context.
|
||||
// As a result the cohort role assignments would be deleted, which has a knock-on effect with courses
|
||||
// as roles may change and data may be removed earlier than it should be.
|
||||
|
||||
// Remove contexts different from SYSTEM or COURSECAT.
|
||||
$contextids = array_reduce($contextlist->get_contexts(), function($carry, $context) {
|
||||
if ($context->contextlevel == CONTEXT_SYSTEM || $context->contextlevel == CONTEXT_COURSECAT) {
|
||||
$carry[] = $context->id;
|
||||
}
|
||||
return $carry;
|
||||
}, []);
|
||||
|
||||
if (empty($contextids)) {
|
||||
// If the user has tool_cohortroles data, then only the User context should be present so get the first context.
|
||||
$contexts = $contextlist->get_contexts();
|
||||
if (count($contexts) == 0) {
|
||||
return;
|
||||
}
|
||||
$context = reset($contexts);
|
||||
|
||||
$userid = $contextlist->get_user()->id;
|
||||
|
||||
list($contextsql, $contextparams) = $DB->get_in_or_equal($contextids, SQL_PARAMS_NAMED);
|
||||
$selectcontext = "contextid {$contextsql}";
|
||||
// Get the cohorts in the specified contexts.
|
||||
$cohortids = $DB->get_fieldset_select('cohort', 'id', $selectcontext, $contextparams);
|
||||
|
||||
if (empty($cohortids)) {
|
||||
// Sanity check that context is at the User context level, then get the userid.
|
||||
if ($context->contextlevel !== CONTEXT_USER) {
|
||||
return;
|
||||
}
|
||||
|
||||
list($cohortsql, $cohortparams) = $DB->get_in_or_equal($cohortids, SQL_PARAMS_NAMED);
|
||||
$selectcohort = "cohortid {$cohortsql} AND userid = :userid";
|
||||
$params = ['userid' => $userid] + $cohortparams;
|
||||
$userid = $context->instanceid;
|
||||
|
||||
// Delete the tool_cohortroles records created for the userid.
|
||||
$DB->delete_records_select('tool_cohortroles', $selectcohort, $params);
|
||||
$DB->delete_records('tool_cohortroles', ['userid' => $userid]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -30,7 +30,6 @@ use \core_privacy\local\request\writer;
|
||||
use \core_privacy\local\request\approved_contextlist;
|
||||
use \tool_cohortroles\api;
|
||||
use \tool_cohortroles\privacy\provider;
|
||||
use core_privacy\local\request\approved_userlist;
|
||||
|
||||
/**
|
||||
* Unit tests for the tool_cohortroles implementation of the privacy API.
|
||||
@@ -58,36 +57,22 @@ class tool_cohortroles_privacy_testcase extends \core_privacy\tests\provider_tes
|
||||
$this->setUser($user);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create course category.
|
||||
$coursecategory = $this->getDataGenerator()->create_category();
|
||||
$coursecategoryctx = \context_coursecat::instance($coursecategory->id);
|
||||
$systemctx = context_system::instance();
|
||||
// Create course.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$coursectx = \context_course::instance($course->id);
|
||||
|
||||
$this->setup_test_scenario_data($user->id, $systemctx, 1);
|
||||
$this->setup_test_scenario_data($user->id, $coursecategoryctx, 1, 'Sausage roll 2',
|
||||
'sausageroll2');
|
||||
$this->setup_test_scenario_data($user->id, $coursectx, 1, 'Sausage roll 3',
|
||||
'sausageroll3');
|
||||
$nocohortroles = 3;
|
||||
$this->setup_test_scenario_data($user->id, $nocohortroles);
|
||||
|
||||
// Test the User's assigned cohortroles matches 3.
|
||||
$cohortroles = $DB->get_records('tool_cohortroles', ['userid' => $user->id]);
|
||||
$this->assertCount(3, $cohortroles);
|
||||
$this->assertCount($nocohortroles, $cohortroles);
|
||||
|
||||
// Test the User's retrieved contextlist returns only the system and course category context.
|
||||
// Test the User's retrieved contextlist contains only one context.
|
||||
$contextlist = provider::get_contexts_for_userid($user->id);
|
||||
$contexts = $contextlist->get_contexts();
|
||||
$this->assertCount(2, $contexts);
|
||||
$this->assertCount(1, $contexts);
|
||||
|
||||
$contextlevels = array_column($contexts, 'contextlevel');
|
||||
$expected = [
|
||||
CONTEXT_SYSTEM,
|
||||
CONTEXT_COURSECAT
|
||||
];
|
||||
// Test the User's contexts equal the system and course category context.
|
||||
$this->assertEquals($expected, $contextlevels, '', 0, 10, true);
|
||||
// Test the User's contexts equal the User's own context.
|
||||
$context = reset($contexts);
|
||||
$this->assertEquals(CONTEXT_USER, $context->contextlevel);
|
||||
$this->assertEquals($user->id, $context->instanceid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -99,45 +84,26 @@ class tool_cohortroles_privacy_testcase extends \core_privacy\tests\provider_tes
|
||||
$this->setUser($user);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create course category.
|
||||
$coursecategory = $this->getDataGenerator()->create_category();
|
||||
$coursecategoryctx = \context_coursecat::instance($coursecategory->id);
|
||||
$systemctx = context_system::instance();
|
||||
// Create course.
|
||||
$course = $this->getDataGenerator()->create_course();
|
||||
$coursectx = \context_course::instance($course->id);
|
||||
$nocohortroles = 3;
|
||||
$this->setup_test_scenario_data($user->id, $nocohortroles);
|
||||
|
||||
$this->setup_test_scenario_data($user->id, $systemctx, 1);
|
||||
$this->setup_test_scenario_data($user->id, $coursecategoryctx, 1, 'Sausage roll 2',
|
||||
'sausageroll2');
|
||||
$this->setup_test_scenario_data($user->id, $coursectx, 1, 'Sausage roll 3',
|
||||
'sausageroll3');
|
||||
|
||||
// Test the User's retrieved contextlist contains two contexts.
|
||||
// Test the User's retrieved contextlist contains only one context.
|
||||
$contextlist = provider::get_contexts_for_userid($user->id);
|
||||
$contexts = $contextlist->get_contexts();
|
||||
$this->assertCount(2, $contexts);
|
||||
$this->assertCount(1, $contexts);
|
||||
|
||||
// Add a system, course category and course context to the approved context list.
|
||||
$approvedcontextids = [
|
||||
$systemctx->id,
|
||||
$coursecategoryctx->id,
|
||||
$coursectx->id
|
||||
];
|
||||
// Test the User's contexts equal the User's own context.
|
||||
$context = reset($contexts);
|
||||
$this->assertEquals(CONTEXT_USER, $context->contextlevel);
|
||||
$this->assertEquals($user->id, $context->instanceid);
|
||||
|
||||
// Retrieve the User's tool_cohortroles data.
|
||||
$approvedcontextlist = new approved_contextlist($user, 'tool_cohortroles', $approvedcontextids);
|
||||
$approvedcontextlist = new approved_contextlist($user, 'tool_cohortroles', $contextlist->get_contextids());
|
||||
provider::export_user_data($approvedcontextlist);
|
||||
|
||||
// Test the tool_cohortroles data is exported at the system context level.
|
||||
$writer = writer::with_context($systemctx);
|
||||
// Test the tool_cohortroles data is exported at the User context level.
|
||||
$writer = writer::with_context($context);
|
||||
$this->assertTrue($writer->has_any_data());
|
||||
// Test the tool_cohortroles data is exported at the course category context level.
|
||||
$writer = writer::with_context($coursecategoryctx);
|
||||
$this->assertTrue($writer->has_any_data());
|
||||
// Test the tool_cohortroles data is not exported at the course context level.
|
||||
$writer = writer::with_context($coursectx);
|
||||
$this->assertFalse($writer->has_any_data());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -151,52 +117,29 @@ class tool_cohortroles_privacy_testcase extends \core_privacy\tests\provider_tes
|
||||
$this->setUser($user);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create course category.
|
||||
$coursecategory = $this->getDataGenerator()->create_category();
|
||||
$coursecategoryctx = \context_coursecat::instance($coursecategory->id);
|
||||
$systemctx = context_system::instance();
|
||||
$nocohortroles = 4;
|
||||
$this->setup_test_scenario_data($user->id, $nocohortroles);
|
||||
|
||||
$this->setup_test_scenario_data($user->id, $systemctx, 1);
|
||||
$this->setup_test_scenario_data($user->id, $coursecategoryctx, 1, 'Sausage roll 2',
|
||||
'sausageroll2');
|
||||
|
||||
// Test the User's assigned cohortroles matches 2.
|
||||
// Test the User's assigned cohortroles matches 4.
|
||||
$cohortroles = $DB->get_records('tool_cohortroles', ['userid' => $user->id]);
|
||||
$this->assertCount(2, $cohortroles);
|
||||
$this->assertCount($nocohortroles, $cohortroles);
|
||||
|
||||
// Test the User's retrieved contextlist contains two contexts.
|
||||
$contextlist = provider::get_contexts_for_userid($user->id);
|
||||
$contexts = $contextlist->get_contexts();
|
||||
$this->assertCount(2, $contexts);
|
||||
|
||||
// Make sure the user data is only being deleted in within the system and course category context.
|
||||
$usercontext = context_user::instance($user->id);
|
||||
// Delete all the User's records in mdl_tool_cohortroles table by the user context.
|
||||
provider::delete_data_for_all_users_in_context($usercontext);
|
||||
|
||||
// Test the cohort roles records in mdl_tool_cohortroles table is still present.
|
||||
$cohortroles = $DB->get_records('tool_cohortroles', ['userid' => $user->id]);
|
||||
$this->assertCount(2, $cohortroles);
|
||||
|
||||
// Delete all the User's records in mdl_tool_cohortroles table by the specified system context.
|
||||
provider::delete_data_for_all_users_in_context($systemctx);
|
||||
|
||||
// The user data in the system context should be deleted.
|
||||
// Test the User's retrieved contextlist contains one context (course category).
|
||||
// Test the User's retrieved contextlist contains only one context.
|
||||
$contextlist = provider::get_contexts_for_userid($user->id);
|
||||
$contexts = $contextlist->get_contexts();
|
||||
$this->assertCount(1, $contexts);
|
||||
|
||||
// Delete all the User's records in mdl_tool_cohortroles table by the specified course category context.
|
||||
provider::delete_data_for_all_users_in_context($coursecategoryctx);
|
||||
// Test the User's contexts equal the User's own context.
|
||||
$context = reset($contexts);
|
||||
$this->assertEquals(CONTEXT_USER, $context->contextlevel);
|
||||
$this->assertEquals($user->id, $context->instanceid);
|
||||
|
||||
// Delete all the User's records in mdl_tool_cohortroles table by the specified User context.
|
||||
provider::delete_data_for_all_users_in_context($context);
|
||||
|
||||
// Test the cohort roles records in mdl_tool_cohortroles table is equals zero.
|
||||
$cohortroles = $DB->get_records('tool_cohortroles', ['userid' => $user->id]);
|
||||
$this->assertCount(0, $cohortroles);
|
||||
|
||||
$contextlist = provider::get_contexts_for_userid($user->id);
|
||||
$contexts = $contextlist->get_contexts();
|
||||
$this->assertCount(0, $contexts);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -210,35 +153,24 @@ class tool_cohortroles_privacy_testcase extends \core_privacy\tests\provider_tes
|
||||
$this->setUser($user);
|
||||
$this->setAdminUser();
|
||||
|
||||
// Create course category.
|
||||
$coursecategory = $this->getDataGenerator()->create_category();
|
||||
$coursecategoryctx = \context_coursecat::instance($coursecategory->id);
|
||||
$systemctx = context_system::instance();
|
||||
$nocohortroles = 4;
|
||||
$this->setup_test_scenario_data($user->id, $nocohortroles);
|
||||
|
||||
$this->setup_test_scenario_data($user->id, $systemctx, 1);
|
||||
$this->setup_test_scenario_data($user->id, $coursecategoryctx, 1, 'Sausage roll 2',
|
||||
'sausageroll2');
|
||||
|
||||
// Test the User's assigned cohortroles matches 2.
|
||||
// Test the User's assigned cohortroles matches 4.
|
||||
$cohortroles = $DB->get_records('tool_cohortroles', ['userid' => $user->id]);
|
||||
$this->assertCount(2, $cohortroles);
|
||||
$this->assertCount($nocohortroles, $cohortroles);
|
||||
|
||||
// Test the User's retrieved contextlist contains two contexts.
|
||||
// Test the User's retrieved contextlist contains only one context.
|
||||
$contextlist = provider::get_contexts_for_userid($user->id);
|
||||
$contexts = $contextlist->get_contexts();
|
||||
$this->assertCount(2, $contexts);
|
||||
$this->assertCount(1, $contexts);
|
||||
|
||||
// Make sure the user data is only being deleted in within the system and the course category contexts.
|
||||
$usercontext = context_user::instance($user->id);
|
||||
// Delete all the User's records in mdl_tool_cohortroles table by the specified approved context list.
|
||||
$approvedcontextlist = new approved_contextlist($user, 'tool_cohortroles', [$usercontext->id]);
|
||||
provider::delete_data_for_user($approvedcontextlist);
|
||||
// Test the User's contexts equal the User's own context.
|
||||
$context = reset($contexts);
|
||||
$this->assertEquals(CONTEXT_USER, $context->contextlevel);
|
||||
$this->assertEquals($user->id, $context->instanceid);
|
||||
|
||||
// Test the cohort roles records in mdl_tool_cohortroles table are still present.
|
||||
$cohortroles = $DB->get_records('tool_cohortroles', ['userid' => $user->id]);
|
||||
$this->assertCount(2, $cohortroles);
|
||||
|
||||
// Delete all the User's records in mdl_tool_cohortroles table by the specified approved context list.
|
||||
// Delete all the User's records in mdl_tool_cohortroles table by the specified User approved context list.
|
||||
$approvedcontextlist = new approved_contextlist($user, 'tool_cohortroles', $contextlist->get_contextids());
|
||||
provider::delete_data_for_user($approvedcontextlist);
|
||||
|
||||
@@ -247,124 +179,19 @@ class tool_cohortroles_privacy_testcase extends \core_privacy\tests\provider_tes
|
||||
$this->assertCount(0, $cohortroles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that only users within a course context are fetched.
|
||||
*/
|
||||
public function test_get_users_in_context() {
|
||||
$component = 'tool_cohortroles';
|
||||
|
||||
// Create a user.
|
||||
$user = $this->getDataGenerator()->create_user();
|
||||
$usercontext = context_user::instance($user->id);
|
||||
|
||||
// Create course category.
|
||||
$coursecategory = $this->getDataGenerator()->create_category();
|
||||
$coursecategoryctx = \context_coursecat::instance($coursecategory->id);
|
||||
$systemctx = context_system::instance();
|
||||
|
||||
$this->setAdminUser();
|
||||
|
||||
$userlist = new \core_privacy\local\request\userlist($systemctx, $component);
|
||||
provider::get_users_in_context($userlist);
|
||||
$this->assertCount(0, $userlist);
|
||||
|
||||
$this->setup_test_scenario_data($user->id, $systemctx, 1);
|
||||
$this->setup_test_scenario_data($user->id, $coursecategoryctx, 1, 'Sausage roll 2',
|
||||
'sausageroll2');
|
||||
|
||||
// The list of users within the system context should contain user.
|
||||
provider::get_users_in_context($userlist);
|
||||
$this->assertCount(1, $userlist);
|
||||
$this->assertTrue(in_array($user->id, $userlist->get_userids()));
|
||||
|
||||
// The list of users within the course category context should contain user.
|
||||
$userlist = new \core_privacy\local\request\userlist($coursecategoryctx, $component);
|
||||
provider::get_users_in_context($userlist);
|
||||
$this->assertCount(1, $userlist);
|
||||
$this->assertTrue(in_array($user->id, $userlist->get_userids()));
|
||||
|
||||
// The list of users within the user context should be empty.
|
||||
$userlist2 = new \core_privacy\local\request\userlist($usercontext, $component);
|
||||
provider::get_users_in_context($userlist2);
|
||||
$this->assertCount(0, $userlist2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that data for users in approved userlist is deleted.
|
||||
*/
|
||||
public function test_delete_data_for_users() {
|
||||
$component = 'tool_cohortroles';
|
||||
|
||||
// Create user1.
|
||||
$user1 = $this->getDataGenerator()->create_user();
|
||||
// Create user2.
|
||||
$user2 = $this->getDataGenerator()->create_user();
|
||||
// Create user3.
|
||||
$user3 = $this->getDataGenerator()->create_user();
|
||||
$usercontext3 = context_user::instance($user3->id);
|
||||
|
||||
// Create course category.
|
||||
$coursecategory = $this->getDataGenerator()->create_category();
|
||||
$coursecategoryctx = \context_coursecat::instance($coursecategory->id);
|
||||
$systemctx = context_system::instance();
|
||||
|
||||
$this->setAdminUser();
|
||||
|
||||
$this->setup_test_scenario_data($user1->id, $systemctx, 1);
|
||||
$this->setup_test_scenario_data($user2->id, $systemctx, 1, 'Sausage roll 2',
|
||||
'sausageroll2');
|
||||
$this->setup_test_scenario_data($user3->id, $coursecategoryctx, 1, 'Sausage roll 3',
|
||||
'sausageroll3');
|
||||
|
||||
$userlist1 = new \core_privacy\local\request\userlist($systemctx, $component);
|
||||
provider::get_users_in_context($userlist1);
|
||||
$this->assertCount(2, $userlist1);
|
||||
$this->assertTrue(in_array($user1->id, $userlist1->get_userids()));
|
||||
$this->assertTrue(in_array($user2->id, $userlist1->get_userids()));
|
||||
|
||||
// Convert $userlist1 into an approved_contextlist.
|
||||
$approvedlist1 = new approved_userlist($systemctx, $component, [$user1->id]);
|
||||
// Delete using delete_data_for_user.
|
||||
provider::delete_data_for_users($approvedlist1);
|
||||
|
||||
// Re-fetch users in systemcontext.
|
||||
$userlist1 = new \core_privacy\local\request\userlist($systemctx, $component);
|
||||
provider::get_users_in_context($userlist1);
|
||||
// The user data of user1in systemcontext should be deleted.
|
||||
// The user data of user2 in systemcontext should be still present.
|
||||
$this->assertCount(1, $userlist1);
|
||||
$this->assertTrue(in_array($user2->id, $userlist1->get_userids()));
|
||||
|
||||
// Convert $userlist1 into an approved_contextlist in the user context.
|
||||
$approvedlist2 = new approved_userlist($usercontext3, $component, $userlist1->get_userids());
|
||||
// Delete using delete_data_for_user.
|
||||
provider::delete_data_for_users($approvedlist2);
|
||||
// Re-fetch users in systemcontext.
|
||||
$userlist1 = new \core_privacy\local\request\userlist($systemctx, $component);
|
||||
provider::get_users_in_context($userlist1);
|
||||
// The user data in systemcontext should not be deleted.
|
||||
$this->assertCount(1, $userlist1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Helper function to setup tool_cohortroles records for testing a specific user.
|
||||
*
|
||||
* @param int $userid The ID of the user used for testing.
|
||||
* @param int $nocohortroles The number of tool_cohortroles to create for the user.
|
||||
* @param string $rolename The name of the role to be created.
|
||||
* @param string $roleshortname The short name of the role to be created.
|
||||
* @throws \core_competency\invalid_persistent_exception
|
||||
* @throws coding_exception
|
||||
*/
|
||||
protected function setup_test_scenario_data($userid, $context, $nocohortroles, $rolename = 'Sausage Roll',
|
||||
$roleshortname = 'sausageroll') {
|
||||
$roleid = create_role($rolename, $roleshortname, 'mmmm');
|
||||
|
||||
$result = new \stdClass();
|
||||
$result->contextid = $context->id;
|
||||
protected function setup_test_scenario_data($userid, $nocohortroles) {
|
||||
$roleid = create_role('Sausage Roll', 'sausageroll', 'mmmm');
|
||||
|
||||
for ($c = 0; $c < $nocohortroles; $c++) {
|
||||
$cohort = $this->getDataGenerator()->create_cohort($result);
|
||||
$cohort = $this->getDataGenerator()->create_cohort();
|
||||
|
||||
$params = (object)array(
|
||||
'userid' => $userid,
|
||||
|
||||
@@ -25,8 +25,8 @@
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
|
||||
$plugin->version = 2018120300; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2018112800; // Requires this Moodle version.
|
||||
$plugin->version = 2018051400; // The current plugin version (Date: YYYYMMDDXX).
|
||||
$plugin->requires = 2018050800; // Requires this Moodle version.
|
||||
$plugin->component = 'tool_cohortroles'; // Full name of the plugin (used for diagnostics).
|
||||
|
||||
$plugin->dependencies = array(
|
||||
|
||||
@@ -41,8 +41,5 @@ function xmldb_tool_customlang_upgrade($oldversion) {
|
||||
// Automatically generated Moodle v3.5.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
// Automatically generated Moodle v3.6.0 release upgrade line.
|
||||
// Put any upgrade step following this.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -25,6 +25,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
$plugin->version = 2018120300;
|
||||
$plugin->requires = 2018112800;
|
||||
$plugin->version = 2018051400;
|
||||
$plugin->requires = 2018050800;
|
||||
$plugin->component = 'tool_customlang'; // Full name of the plugin (used for diagnostics)
|
||||
|
||||
@@ -1 +0,0 @@
|
||||
define(["jquery","core/ajax","core/notification","core/str","core/modal_factory","core/modal_events","core/templates"],function(a,b,c,d,e,f,g){function h(b,d,h,j,k,l,m,n){null!==h&&l.forEach(function(a){a.id===h&&(a.selected=!0)}),null!==j&&m.forEach(function(a){a.id===j&&(a.selected=!0)});var o={contextlevel:d,categoryoptions:l,purposeoptions:m};null!==n&&n.length&&(null===k?o.newactivitydefaults=!0:n.forEach(function(a){k===a.name&&(a.selected=!0)}),o.modemodule=!0,o.activityoptions=n),e.create({title:b,body:g.render("tool_dataprivacy/category_purpose_form",o),type:e.types.SAVE_CANCEL,large:!0}).then(function(b){return b.getRoot().on(f.save,function(){var b=a("#activity"),c="undefined"!=typeof b?b.val():null,d=a("#override"),e="undefined"!=typeof d&&d.is(":checked");i(a("#contextlevel").val(),a("#category").val(),a("#purpose").val(),c,e)}),b.getRoot().on(f.hidden,function(){b.destroy()}),b.show(),b})["catch"](c.exception)}function i(a,c,d,e,f){var g={methodname:"tool_dataprivacy_set_context_defaults",args:{contextlevel:a,category:c,purpose:d,override:f,activity:e}};b.call([g])[0].done(function(a){a.result&&window.location.reload()})}var j={EDIT_LEVEL_DEFAULTS:'[data-action="edit-level-defaults"]',NEW_ACTIVITY_DEFAULTS:'[data-action="new-activity-defaults"]',EDIT_ACTIVITY_DEFAULTS:'[data-action="edit-activity-defaults"]',DELETE_ACTIVITY_DEFAULTS:'[data-action="delete-activity-defaults"]'},k=-1,l=function(){this.registerEvents()};return l.prototype.registerEvents=function(){a(j.EDIT_LEVEL_DEFAULTS).click(function(e){e.preventDefault();var f=a(this),g=f.data("contextlevel"),i=f.data("category"),j=f.data("purpose"),k=[{methodname:"tool_dataprivacy_get_category_options",args:{}},{methodname:"tool_dataprivacy_get_purpose_options",args:{}}],l=b.call(k),m=d.get_string("editdefaults","tool_dataprivacy",a("#defaults-header").text());a.when(l[0],l[1],m).then(function(a,b,c){var d=a.options,e=b.options;return h(c,g,i,j,null,d,e,null),!0})["catch"](c.exception)}),a(j.NEW_ACTIVITY_DEFAULTS).click(function(e){e.preventDefault();var f=a(this),g=f.data("contextlevel"),i=[{methodname:"tool_dataprivacy_get_category_options",args:{}},{methodname:"tool_dataprivacy_get_purpose_options",args:{}},{methodname:"tool_dataprivacy_get_activity_options",args:{nodefaults:!0}}],j=b.call(i),k=d.get_string("addnewdefaults","tool_dataprivacy");a.when(j[0],j[1],j[2],k).then(function(a,b,c,d){var e=a.options,f=b.options,i=c.options;return h(d,g,null,null,null,e,f,i),!0})["catch"](c.exception)}),a(j.EDIT_ACTIVITY_DEFAULTS).click(function(e){e.preventDefault();var f=a(this),g=f.data("contextlevel"),i=f.data("category"),j=f.data("purpose"),k=f.data("activityname"),l=[{methodname:"tool_dataprivacy_get_category_options",args:{}},{methodname:"tool_dataprivacy_get_purpose_options",args:{}},{methodname:"tool_dataprivacy_get_activity_options",args:{}}],m=b.call(l),n=d.get_string("editmoduledefaults","tool_dataprivacy");a.when(m[0],m[1],m[2],n).then(function(a,b,c,d){var e=a.options,f=b.options,l=c.options;return h(d,g,i,j,k,e,f,l),!0})["catch"](c.exception)}),a(j.DELETE_ACTIVITY_DEFAULTS).click(function(b){b.preventDefault();var h=a(this),j=h.data("contextlevel"),l=h.data("activityname"),m=h.data("activitydisplayname"),n=k,o=k;e.create({title:d.get_string("deletedefaults","tool_dataprivacy",m),body:g.render("tool_dataprivacy/delete_activity_defaults",{activityname:m}),type:e.types.SAVE_CANCEL,large:!0}).then(function(a){return a.setSaveButtonText(d.get_string("delete")),a.getRoot().on(f.save,function(){i(j,n,o,l,!1)}),a.getRoot().on(f.hidden,function(){a.destroy()}),a.show(),!0})["catch"](c.exception)})},{init:function(){return new l}}});
|
||||
+1
-1
@@ -1 +1 @@
|
||||
define([],function(){return{approve:"tool_dataprivacy-data_request:approve",bulkApprove:"tool_dataprivacy-data_request:bulk_approve",deny:"tool_dataprivacy-data_request:deny",bulkDeny:"tool_dataprivacy-data_request:bulk_deny",complete:"tool_dataprivacy-data_request:complete"}});
|
||||
define([],function(){return{approve:"tool_dataprivacy-data_request:approve",deny:"tool_dataprivacy-data_request:deny",complete:"tool_dataprivacy-data_request:complete"}});
|
||||
+1
-1
@@ -1 +1 @@
|
||||
define(["jquery","core/ajax","core/notification","core/str","core/modal_factory","core/modal_events","core/templates","tool_dataprivacy/data_request_modal","tool_dataprivacy/events"],function(a,b,c,d,e,f,g,h,i){function j(a){return{wsfunction:"tool_dataprivacy_approve_data_request",wsparams:{requestid:a}}}function k(a){return{wsfunction:"tool_dataprivacy_bulk_approve_data_requests",wsparams:{requestids:a}}}function l(a){return{wsfunction:"tool_dataprivacy_deny_data_request",wsparams:{requestid:a}}}function m(a){return{wsfunction:"tool_dataprivacy_bulk_deny_data_requests",wsparams:{requestids:a}}}function n(a){return{wsfunction:"tool_dataprivacy_mark_complete",wsparams:{requestid:a}}}function o(a,b){var g=[];switch(a){case i.approve:g=[{key:"approverequest",component:"tool_dataprivacy"},{key:"confirmapproval",component:"tool_dataprivacy"}];break;case i.bulkApprove:g=[{key:"bulkapproverequests",component:"tool_dataprivacy"},{key:"confirmbulkapproval",component:"tool_dataprivacy"}];break;case i.deny:g=[{key:"denyrequest",component:"tool_dataprivacy"},{key:"confirmdenial",component:"tool_dataprivacy"}];break;case i.bulkDeny:g=[{key:"bulkdenyrequests",component:"tool_dataprivacy"},{key:"confirmbulkdenial",component:"tool_dataprivacy"}];break;case i.complete:g=[{key:"markcomplete",component:"tool_dataprivacy"},{key:"confirmcompletion",component:"tool_dataprivacy"}]}var h="";d.get_strings(g).then(function(a){h=a[0];var b=a[1];return e.create({title:h,body:b,type:e.types.SAVE_CANCEL})}).then(function(a){a.setSaveButtonText(h),a.getRoot().on(f.save,function(){p(b.wsfunction,b.wsparams)}),a.getRoot().on(f.hidden,function(){a.destroy()}),a.show()})["catch"](c.exception)}function p(a,d){var e={methodname:a,args:d};b.call([e])[0].done(function(a){a.result?window.location.reload():c.addNotification({message:a.warnings[0].message,type:"error"})}).fail(c.exception)}var q={APPROVE_REQUEST:'[data-action="approve"]',DENY_REQUEST:'[data-action="deny"]',VIEW_REQUEST:'[data-action="view"]',MARK_COMPLETE:'[data-action="complete"]',CHANGE_BULK_ACTION:'[id="bulk-action"]',CONFIRM_BULK_ACTION:'[id="confirm-bulk-action"]',SELECT_ALL:'[data-action="selectall"]'},r={APPROVE:1,DENY:2},s={SELECT_REQUEST:".selectrequests"},t=function(){this.registerEvents()};return t.prototype.registerEvents=function(){a(q.VIEW_REQUEST).click(function(d){d.preventDefault();var k=a(this).data("requestid"),m={requestid:k},n={methodname:"tool_dataprivacy_get_data_request",args:m},q=b.call([n]);a.when(q[0]).then(function(a){return a.result?a.result:(c.addNotification({message:a.warnings[0].message,type:"error"}),!1)}).then(function(a){var b=g.render("tool_dataprivacy/request_details",a),c={approvedeny:a.approvedeny,canmarkcomplete:a.canmarkcomplete};return e.create({title:a.typename,body:b,type:h.TYPE,large:!0,templateContext:c})}).then(function(a){a.getRoot().on(i.approve,function(){o(i.approve,j(k))}),a.getRoot().on(i.deny,function(){o(i.deny,l(k))}),a.getRoot().on(i.complete,function(){var a={requestid:k};p("tool_dataprivacy_mark_complete",a)}),a.getRoot().on(f.hidden,function(){a.destroy()}),a.show()})["catch"](c.exception)}),a(q.APPROVE_REQUEST).click(function(b){b.preventDefault();var c=a(this).data("requestid");o(i.approve,j(c))}),a(q.DENY_REQUEST).click(function(b){b.preventDefault();var c=a(this).data("requestid");o(i.deny,l(c))}),a(q.MARK_COMPLETE).click(function(b){b.preventDefault();var c=a(this).data("requestid");o(i.complete,n(c))}),a(q.CONFIRM_BULK_ACTION).click(function(){var b=[],e="",f={},g=[{key:"selectbulkaction",component:"tool_dataprivacy"},{key:"selectdatarequests",component:"tool_dataprivacy"},{key:"ok"}],h=parseInt(a("#bulk-action").val());if(h!=r.APPROVE&&h!=r.DENY)return void d.get_strings(g).done(function(a){c.alert("",a[0],a[2])}).fail(c.exception);if(a(".selectrequests:checked").each(function(){b.push(a(this).val())}),b.length<1)return void d.get_strings(g).done(function(a){c.alert("",a[1],a[2])}).fail(c.exception);switch(h){case r.APPROVE:e=i.bulkApprove,f=k(b);break;case r.DENY:e=i.bulkDeny,f=m(b)}o(e,f)}),a(q.SELECT_ALL).change(function(b){b.preventDefault();var c=a(this).is(":checked");a(s.SELECT_REQUEST).prop("checked",c)})},t});
|
||||
define(["jquery","core/ajax","core/notification","core/str","core/modal_factory","core/modal_events","core/templates","tool_dataprivacy/data_request_modal","tool_dataprivacy/events"],function(a,b,c,d,e,f,g,h,i){function j(a,b){var g=[],h="",j={requestid:b};switch(a){case i.approve:g=[{key:"approverequest",component:"tool_dataprivacy"},{key:"confirmapproval",component:"tool_dataprivacy"}],h="tool_dataprivacy_approve_data_request";break;case i.deny:g=[{key:"denyrequest",component:"tool_dataprivacy"},{key:"confirmdenial",component:"tool_dataprivacy"}],h="tool_dataprivacy_deny_data_request";break;case i.complete:g=[{key:"markcomplete",component:"tool_dataprivacy"},{key:"confirmcompletion",component:"tool_dataprivacy"}],h="tool_dataprivacy_mark_complete"}var l="";d.get_strings(g).then(function(a){l=a[0];var b=a[1];return e.create({title:l,body:b,type:e.types.SAVE_CANCEL})}).then(function(a){a.setSaveButtonText(l),a.getRoot().on(f.save,function(){k(h,j)}),a.getRoot().on(f.hidden,function(){a.destroy()}),a.show()})["catch"](c.exception)}function k(a,d){var e={methodname:a,args:d};b.call([e])[0].done(function(a){a.result?window.location.reload():c.addNotification({message:a.warnings[0].message,type:"error"})}).fail(c.exception)}var l={APPROVE_REQUEST:'[data-action="approve"]',DENY_REQUEST:'[data-action="deny"]',VIEW_REQUEST:'[data-action="view"]',MARK_COMPLETE:'[data-action="complete"]'},m=function(){this.registerEvents()};return m.prototype.registerEvents=function(){a(l.VIEW_REQUEST).click(function(d){d.preventDefault();var l=a(this).data("requestid"),m={requestid:l},n={methodname:"tool_dataprivacy_get_data_request",args:m},o=b.call([n]);a.when(o[0]).then(function(a){return a.result?a.result:(c.addNotification({message:a.warnings[0].message,type:"error"}),!1)}).then(function(a){var b=g.render("tool_dataprivacy/request_details",a),c={approvedeny:a.approvedeny,canmarkcomplete:a.canmarkcomplete};return e.create({title:a.typename,body:b,type:h.TYPE,large:!0,templateContext:c})}).then(function(a){a.getRoot().on(i.approve,function(){j(i.approve,l)}),a.getRoot().on(i.deny,function(){j(i.deny,l)}),a.getRoot().on(i.complete,function(){var a={requestid:l};k("tool_dataprivacy_mark_complete",a)}),a.getRoot().on(f.hidden,function(){a.destroy()}),a.show()})["catch"](c.exception)}),a(l.APPROVE_REQUEST).click(function(b){b.preventDefault();var c=a(this).data("requestid");j(i.approve,c)}),a(l.DENY_REQUEST).click(function(b){b.preventDefault();var c=a(this).data("requestid");j(i.deny,c)}),a(l.MARK_COMPLETE).click(function(b){b.preventDefault(),j(i.complete,a(this).data("requestid"))})},m});
|
||||
@@ -1,315 +0,0 @@
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* AMD module for data registry defaults actions.
|
||||
*
|
||||
* @module tool_dataprivacy/defaultsactions
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 Jun Pataleta
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
define([
|
||||
'jquery',
|
||||
'core/ajax',
|
||||
'core/notification',
|
||||
'core/str',
|
||||
'core/modal_factory',
|
||||
'core/modal_events',
|
||||
'core/templates'],
|
||||
function($, Ajax, Notification, Str, ModalFactory, ModalEvents, Templates) {
|
||||
|
||||
/**
|
||||
* List of action selectors.
|
||||
*
|
||||
* @type {{EDIT_LEVEL_DEFAULTS: string}}
|
||||
* @type {{NEW_ACTIVITY_DEFAULTS: string}}
|
||||
* @type {{EDIT_ACTIVITY_DEFAULTS: string}}
|
||||
* @type {{DELETE_ACTIVITY_DEFAULTS: string}}
|
||||
*/
|
||||
var ACTIONS = {
|
||||
EDIT_LEVEL_DEFAULTS: '[data-action="edit-level-defaults"]',
|
||||
NEW_ACTIVITY_DEFAULTS: '[data-action="new-activity-defaults"]',
|
||||
EDIT_ACTIVITY_DEFAULTS: '[data-action="edit-activity-defaults"]',
|
||||
DELETE_ACTIVITY_DEFAULTS: '[data-action="delete-activity-defaults"]'
|
||||
};
|
||||
|
||||
/** @type {{INHERIT: Number}} **/
|
||||
var INHERIT = -1;
|
||||
|
||||
/**
|
||||
* DefaultsActions class.
|
||||
*/
|
||||
var DefaultsActions = function() {
|
||||
this.registerEvents();
|
||||
};
|
||||
|
||||
/**
|
||||
* Register event listeners.
|
||||
*/
|
||||
DefaultsActions.prototype.registerEvents = function() {
|
||||
$(ACTIONS.EDIT_LEVEL_DEFAULTS).click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var button = $(this);
|
||||
var contextLevel = button.data('contextlevel');
|
||||
var category = button.data('category');
|
||||
var purpose = button.data('purpose');
|
||||
|
||||
// Get options.
|
||||
var requests = [
|
||||
{methodname: 'tool_dataprivacy_get_category_options', args: {}},
|
||||
{methodname: 'tool_dataprivacy_get_purpose_options', args: {}}
|
||||
];
|
||||
|
||||
var promises = Ajax.call(requests);
|
||||
var titlePromise = Str.get_string('editdefaults', 'tool_dataprivacy', $('#defaults-header').text());
|
||||
$.when(promises[0], promises[1], titlePromise).then(function(categoryResponse, purposeResponse, title) {
|
||||
var categories = categoryResponse.options;
|
||||
var purposes = purposeResponse.options;
|
||||
showDefaultsFormModal(title, contextLevel, category, purpose, null, categories, purposes, null);
|
||||
|
||||
return true;
|
||||
}).catch(Notification.exception);
|
||||
});
|
||||
|
||||
$(ACTIONS.NEW_ACTIVITY_DEFAULTS).click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var button = $(this);
|
||||
var contextLevel = button.data('contextlevel');
|
||||
|
||||
// Get options.
|
||||
var requests = [
|
||||
{methodname: 'tool_dataprivacy_get_category_options', args: {}},
|
||||
{methodname: 'tool_dataprivacy_get_purpose_options', args: {}},
|
||||
{methodname: 'tool_dataprivacy_get_activity_options', args: {'nodefaults': true}}
|
||||
];
|
||||
|
||||
var promises = Ajax.call(requests);
|
||||
var titlePromise = Str.get_string('addnewdefaults', 'tool_dataprivacy');
|
||||
|
||||
$.when(promises[0], promises[1], promises[2], titlePromise).then(
|
||||
function(categoryResponse, purposeResponse, activityResponse, title) {
|
||||
var categories = categoryResponse.options;
|
||||
var purposes = purposeResponse.options;
|
||||
var activities = activityResponse.options;
|
||||
|
||||
showDefaultsFormModal(title, contextLevel, null, null, null, categories, purposes, activities);
|
||||
|
||||
return true;
|
||||
|
||||
}).catch(Notification.exception);
|
||||
}
|
||||
);
|
||||
|
||||
$(ACTIONS.EDIT_ACTIVITY_DEFAULTS).click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var button = $(this);
|
||||
var contextLevel = button.data('contextlevel');
|
||||
var category = button.data('category');
|
||||
var purpose = button.data('purpose');
|
||||
var activity = button.data('activityname');
|
||||
|
||||
// Get options.
|
||||
var requests = [
|
||||
{methodname: 'tool_dataprivacy_get_category_options', args: {}},
|
||||
{methodname: 'tool_dataprivacy_get_purpose_options', args: {}},
|
||||
{methodname: 'tool_dataprivacy_get_activity_options', args: {}}
|
||||
];
|
||||
|
||||
var promises = Ajax.call(requests);
|
||||
var titlePromise = Str.get_string('editmoduledefaults', 'tool_dataprivacy');
|
||||
|
||||
$.when(promises[0], promises[1], promises[2], titlePromise).then(
|
||||
function(categoryResponse, purposeResponse, activityResponse, title) {
|
||||
var categories = categoryResponse.options;
|
||||
var purposes = purposeResponse.options;
|
||||
var activities = activityResponse.options;
|
||||
|
||||
showDefaultsFormModal(title, contextLevel, category, purpose, activity, categories, purposes, activities);
|
||||
|
||||
return true;
|
||||
|
||||
}).catch(Notification.exception);
|
||||
}
|
||||
);
|
||||
|
||||
$(ACTIONS.DELETE_ACTIVITY_DEFAULTS).click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var button = $(this);
|
||||
var contextLevel = button.data('contextlevel');
|
||||
var activity = button.data('activityname');
|
||||
var activityDisplayName = button.data('activitydisplayname');
|
||||
// Set category and purpose to inherit (-1).
|
||||
var category = INHERIT;
|
||||
var purpose = INHERIT;
|
||||
|
||||
ModalFactory.create({
|
||||
title: Str.get_string('deletedefaults', 'tool_dataprivacy', activityDisplayName),
|
||||
body: Templates.render('tool_dataprivacy/delete_activity_defaults', {"activityname": activityDisplayName}),
|
||||
type: ModalFactory.types.SAVE_CANCEL,
|
||||
large: true
|
||||
}).then(function(modal) {
|
||||
modal.setSaveButtonText(Str.get_string('delete'));
|
||||
|
||||
// Handle save event.
|
||||
modal.getRoot().on(ModalEvents.save, function() {
|
||||
setContextDefaults(contextLevel, category, purpose, activity, false);
|
||||
});
|
||||
|
||||
// Handle hidden event.
|
||||
modal.getRoot().on(ModalEvents.hidden, function() {
|
||||
// Destroy when hidden.
|
||||
modal.destroy();
|
||||
});
|
||||
|
||||
modal.show();
|
||||
|
||||
return true;
|
||||
}).catch(Notification.exception);
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Prepares and renders the modal for setting the defaults for the given context level/plugin.
|
||||
*
|
||||
* @param {String} title The modal's title.
|
||||
* @param {Number} contextLevel The context level to set defaults for.
|
||||
* @param {Number} category The current category ID.
|
||||
* @param {Number} purpose The current purpose ID.
|
||||
* @param {String} activity The plugin name of the activity. Optional.
|
||||
* @param {Array} categoryOptions The list of category options.
|
||||
* @param {Array} purposeOptions The list of purpose options.
|
||||
* @param {Array} activityOptions The list of activity options. Optional.
|
||||
*/
|
||||
function showDefaultsFormModal(title, contextLevel, category, purpose, activity,
|
||||
categoryOptions, purposeOptions, activityOptions) {
|
||||
|
||||
if (category !== null) {
|
||||
categoryOptions.forEach(function(currentValue) {
|
||||
if (currentValue.id === category) {
|
||||
currentValue.selected = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (purpose !== null) {
|
||||
purposeOptions.forEach(function(currentValue) {
|
||||
if (currentValue.id === purpose) {
|
||||
currentValue.selected = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
var templateContext = {
|
||||
"contextlevel": contextLevel,
|
||||
"categoryoptions": categoryOptions,
|
||||
"purposeoptions": purposeOptions
|
||||
};
|
||||
|
||||
// Check the activityOptions parameter that was passed.
|
||||
if (activityOptions !== null && activityOptions.length) {
|
||||
// Check the activity parameter that was passed.
|
||||
if (activity === null) {
|
||||
// We're setting a new defaults for a module.
|
||||
templateContext.newactivitydefaults = true;
|
||||
|
||||
} else {
|
||||
// Edit mode. Set selection.
|
||||
activityOptions.forEach(function(currentValue) {
|
||||
if (activity === currentValue.name) {
|
||||
currentValue.selected = true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
templateContext.modemodule = true;
|
||||
templateContext.activityoptions = activityOptions;
|
||||
}
|
||||
|
||||
ModalFactory.create({
|
||||
title: title,
|
||||
body: Templates.render('tool_dataprivacy/category_purpose_form', templateContext),
|
||||
type: ModalFactory.types.SAVE_CANCEL,
|
||||
large: true
|
||||
}).then(function(modal) {
|
||||
|
||||
// Handle save event.
|
||||
modal.getRoot().on(ModalEvents.save, function() {
|
||||
var activity = $('#activity');
|
||||
var activityVal = typeof activity !== 'undefined' ? activity.val() : null;
|
||||
var override = $('#override');
|
||||
var overrideVal = typeof override !== 'undefined' ? override.is(':checked') : false;
|
||||
|
||||
setContextDefaults($('#contextlevel').val(), $('#category').val(), $('#purpose').val(), activityVal, overrideVal);
|
||||
});
|
||||
|
||||
// Handle hidden event.
|
||||
modal.getRoot().on(ModalEvents.hidden, function() {
|
||||
// Destroy when hidden.
|
||||
modal.destroy();
|
||||
});
|
||||
|
||||
modal.show();
|
||||
|
||||
return modal;
|
||||
}).catch(Notification.exception);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls a the tool_dataprivacy_set_context_defaults WS function.
|
||||
*
|
||||
* @param {Number} contextLevel The context level.
|
||||
* @param {Number} category The category ID.
|
||||
* @param {Number} purpose The purpose ID.
|
||||
* @param {String} activity The plugin name of the activity module.
|
||||
* @param {Boolean} override Whether to override custom instances.
|
||||
*/
|
||||
function setContextDefaults(contextLevel, category, purpose, activity, override) {
|
||||
var request = {
|
||||
methodname: 'tool_dataprivacy_set_context_defaults',
|
||||
args: {
|
||||
'contextlevel': contextLevel,
|
||||
'category': category,
|
||||
'purpose': purpose,
|
||||
'override': override,
|
||||
'activity': activity
|
||||
}
|
||||
};
|
||||
|
||||
Ajax.call([request])[0].done(function(data) {
|
||||
if (data.result) {
|
||||
window.location.reload();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
return /** @alias module:tool_dataprivacy/defaultsactions */ {
|
||||
// Public variables and functions.
|
||||
|
||||
/**
|
||||
* Initialise the module.
|
||||
*
|
||||
* @method init
|
||||
* @return {DefaultsActions}
|
||||
*/
|
||||
'init': function() {
|
||||
return new DefaultsActions();
|
||||
}
|
||||
};
|
||||
});
|
||||
@@ -25,9 +25,7 @@
|
||||
define([], function() {
|
||||
return {
|
||||
approve: 'tool_dataprivacy-data_request:approve',
|
||||
bulkApprove: 'tool_dataprivacy-data_request:bulk_approve',
|
||||
deny: 'tool_dataprivacy-data_request:deny',
|
||||
bulkDeny: 'tool_dataprivacy-data_request:bulk_deny',
|
||||
complete: 'tool_dataprivacy-data_request:complete'
|
||||
};
|
||||
});
|
||||
|
||||
@@ -40,38 +40,12 @@ function($, Ajax, Notification, Str, ModalFactory, ModalEvents, Templates, Modal
|
||||
* @type {{DENY_REQUEST: string}}
|
||||
* @type {{VIEW_REQUEST: string}}
|
||||
* @type {{MARK_COMPLETE: string}}
|
||||
* @type {{CHANGE_BULK_ACTION: string}}
|
||||
* @type {{CONFIRM_BULK_ACTION: string}}
|
||||
* @type {{SELECT_ALL: string}}
|
||||
*/
|
||||
var ACTIONS = {
|
||||
APPROVE_REQUEST: '[data-action="approve"]',
|
||||
DENY_REQUEST: '[data-action="deny"]',
|
||||
VIEW_REQUEST: '[data-action="view"]',
|
||||
MARK_COMPLETE: '[data-action="complete"]',
|
||||
CHANGE_BULK_ACTION: '[id="bulk-action"]',
|
||||
CONFIRM_BULK_ACTION: '[id="confirm-bulk-action"]',
|
||||
SELECT_ALL: '[data-action="selectall"]'
|
||||
};
|
||||
|
||||
/**
|
||||
* List of available bulk actions.
|
||||
*
|
||||
* @type {{APPROVE: number}}
|
||||
* @type {{DENY: number}}
|
||||
*/
|
||||
var BULK_ACTIONS = {
|
||||
APPROVE: 1,
|
||||
DENY: 2
|
||||
};
|
||||
|
||||
/**
|
||||
* List of selectors.
|
||||
*
|
||||
* @type {{SELECT_REQUEST: string}}
|
||||
*/
|
||||
var SELECTORS = {
|
||||
SELECT_REQUEST: '.selectrequests'
|
||||
MARK_COMPLETE: '[data-action="complete"]'
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -129,12 +103,12 @@ function($, Ajax, Notification, Str, ModalFactory, ModalEvents, Templates, Modal
|
||||
}).then(function(modal) {
|
||||
// Handle approve event.
|
||||
modal.getRoot().on(DataPrivacyEvents.approve, function() {
|
||||
showConfirmation(DataPrivacyEvents.approve, approveEventWsData(requestId));
|
||||
showConfirmation(DataPrivacyEvents.approve, requestId);
|
||||
});
|
||||
|
||||
// Handle deny event.
|
||||
modal.getRoot().on(DataPrivacyEvents.deny, function() {
|
||||
showConfirmation(DataPrivacyEvents.deny, denyEventWsData(requestId));
|
||||
showConfirmation(DataPrivacyEvents.deny, requestId);
|
||||
});
|
||||
|
||||
// Handle send event.
|
||||
@@ -163,158 +137,34 @@ function($, Ajax, Notification, Str, ModalFactory, ModalEvents, Templates, Modal
|
||||
e.preventDefault();
|
||||
|
||||
var requestId = $(this).data('requestid');
|
||||
showConfirmation(DataPrivacyEvents.approve, approveEventWsData(requestId));
|
||||
showConfirmation(DataPrivacyEvents.approve, requestId);
|
||||
});
|
||||
|
||||
$(ACTIONS.DENY_REQUEST).click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var requestId = $(this).data('requestid');
|
||||
showConfirmation(DataPrivacyEvents.deny, denyEventWsData(requestId));
|
||||
showConfirmation(DataPrivacyEvents.deny, requestId);
|
||||
});
|
||||
|
||||
$(ACTIONS.MARK_COMPLETE).click(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var requestId = $(this).data('requestid');
|
||||
showConfirmation(DataPrivacyEvents.complete, completeEventWsData(requestId));
|
||||
});
|
||||
|
||||
$(ACTIONS.CONFIRM_BULK_ACTION).click(function() {
|
||||
var requestIds = [];
|
||||
var actionEvent = '';
|
||||
var wsdata = {};
|
||||
var bulkActionKeys = [
|
||||
{
|
||||
key: 'selectbulkaction',
|
||||
component: 'tool_dataprivacy'
|
||||
},
|
||||
{
|
||||
key: 'selectdatarequests',
|
||||
component: 'tool_dataprivacy'
|
||||
},
|
||||
{
|
||||
key: 'ok'
|
||||
}
|
||||
];
|
||||
|
||||
var bulkaction = parseInt($('#bulk-action').val());
|
||||
|
||||
if (bulkaction != BULK_ACTIONS.APPROVE && bulkaction != BULK_ACTIONS.DENY) {
|
||||
Str.get_strings(bulkActionKeys).done(function(langStrings) {
|
||||
Notification.alert('', langStrings[0], langStrings[2]);
|
||||
}).fail(Notification.exception);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$(".selectrequests:checked").each(function() {
|
||||
requestIds.push($(this).val());
|
||||
});
|
||||
|
||||
if (requestIds.length < 1) {
|
||||
Str.get_strings(bulkActionKeys).done(function(langStrings) {
|
||||
Notification.alert('', langStrings[1], langStrings[2]);
|
||||
}).fail(Notification.exception);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
switch (bulkaction) {
|
||||
case BULK_ACTIONS.APPROVE:
|
||||
actionEvent = DataPrivacyEvents.bulkApprove;
|
||||
wsdata = bulkApproveEventWsData(requestIds);
|
||||
break;
|
||||
case BULK_ACTIONS.DENY:
|
||||
actionEvent = DataPrivacyEvents.bulkDeny;
|
||||
wsdata = bulkDenyEventWsData(requestIds);
|
||||
}
|
||||
|
||||
showConfirmation(actionEvent, wsdata);
|
||||
});
|
||||
|
||||
$(ACTIONS.SELECT_ALL).change(function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
var selectAll = $(this).is(':checked');
|
||||
$(SELECTORS.SELECT_REQUEST).prop('checked', selectAll);
|
||||
showConfirmation(DataPrivacyEvents.complete, $(this).data('requestid'));
|
||||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the webservice data for the approve request action.
|
||||
*
|
||||
* @param {Number} requestId The ID of the request.
|
||||
* @return {Object}
|
||||
*/
|
||||
function approveEventWsData(requestId) {
|
||||
return {
|
||||
'wsfunction': 'tool_dataprivacy_approve_data_request',
|
||||
'wsparams': {'requestid': requestId}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the webservice data for the bulk approve request action.
|
||||
*
|
||||
* @param {Array} requestIds The array of request ID's.
|
||||
* @return {Object}
|
||||
*/
|
||||
function bulkApproveEventWsData(requestIds) {
|
||||
return {
|
||||
'wsfunction': 'tool_dataprivacy_bulk_approve_data_requests',
|
||||
'wsparams': {'requestids': requestIds}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the webservice data for the deny request action.
|
||||
*
|
||||
* @param {Number} requestId The ID of the request.
|
||||
* @return {Object}
|
||||
*/
|
||||
function denyEventWsData(requestId) {
|
||||
return {
|
||||
'wsfunction': 'tool_dataprivacy_deny_data_request',
|
||||
'wsparams': {'requestid': requestId}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the webservice data for the bulk deny request action.
|
||||
*
|
||||
* @param {Array} requestIds The array of request ID's.
|
||||
* @return {Object}
|
||||
*/
|
||||
function bulkDenyEventWsData(requestIds) {
|
||||
return {
|
||||
'wsfunction': 'tool_dataprivacy_bulk_deny_data_requests',
|
||||
'wsparams': {'requestids': requestIds}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the webservice data for the complete request action.
|
||||
*
|
||||
* @param {Number} requestId The ID of the request.
|
||||
* @return {Object}
|
||||
*/
|
||||
function completeEventWsData(requestId) {
|
||||
return {
|
||||
'wsfunction': 'tool_dataprivacy_mark_complete',
|
||||
'wsparams': {'requestid': requestId}
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the confirmation dialogue.
|
||||
*
|
||||
* @param {String} action The action name.
|
||||
* @param {Object} wsdata Object containing ws data.
|
||||
* @param {Number} requestId The request ID.
|
||||
*/
|
||||
function showConfirmation(action, wsdata) {
|
||||
function showConfirmation(action, requestId) {
|
||||
var keys = [];
|
||||
|
||||
var wsfunction = '';
|
||||
var params = {
|
||||
'requestid': requestId
|
||||
};
|
||||
switch (action) {
|
||||
case DataPrivacyEvents.approve:
|
||||
keys = [
|
||||
@@ -327,18 +177,7 @@ function($, Ajax, Notification, Str, ModalFactory, ModalEvents, Templates, Modal
|
||||
component: 'tool_dataprivacy'
|
||||
}
|
||||
];
|
||||
break;
|
||||
case DataPrivacyEvents.bulkApprove:
|
||||
keys = [
|
||||
{
|
||||
key: 'bulkapproverequests',
|
||||
component: 'tool_dataprivacy'
|
||||
},
|
||||
{
|
||||
key: 'confirmbulkapproval',
|
||||
component: 'tool_dataprivacy'
|
||||
}
|
||||
];
|
||||
wsfunction = 'tool_dataprivacy_approve_data_request';
|
||||
break;
|
||||
case DataPrivacyEvents.deny:
|
||||
keys = [
|
||||
@@ -351,18 +190,7 @@ function($, Ajax, Notification, Str, ModalFactory, ModalEvents, Templates, Modal
|
||||
component: 'tool_dataprivacy'
|
||||
}
|
||||
];
|
||||
break;
|
||||
case DataPrivacyEvents.bulkDeny:
|
||||
keys = [
|
||||
{
|
||||
key: 'bulkdenyrequests',
|
||||
component: 'tool_dataprivacy'
|
||||
},
|
||||
{
|
||||
key: 'confirmbulkdenial',
|
||||
component: 'tool_dataprivacy'
|
||||
}
|
||||
];
|
||||
wsfunction = 'tool_dataprivacy_deny_data_request';
|
||||
break;
|
||||
case DataPrivacyEvents.complete:
|
||||
keys = [
|
||||
@@ -375,6 +203,7 @@ function($, Ajax, Notification, Str, ModalFactory, ModalEvents, Templates, Modal
|
||||
component: 'tool_dataprivacy'
|
||||
}
|
||||
];
|
||||
wsfunction = 'tool_dataprivacy_mark_complete';
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -392,7 +221,7 @@ function($, Ajax, Notification, Str, ModalFactory, ModalEvents, Templates, Modal
|
||||
|
||||
// Handle save event.
|
||||
modal.getRoot().on(ModalEvents.save, function() {
|
||||
handleSave(wsdata.wsfunction, wsdata.wsparams);
|
||||
handleSave(wsfunction, params);
|
||||
});
|
||||
|
||||
// Handle hidden event.
|
||||
|
||||
@@ -33,7 +33,6 @@ $title = get_string('editcategories', 'tool_dataprivacy');
|
||||
|
||||
$output = $PAGE->get_renderer('tool_dataprivacy');
|
||||
echo $output->header();
|
||||
echo $output->heading($title);
|
||||
|
||||
$categories = \tool_dataprivacy\api::get_categories();
|
||||
$renderable = new \tool_dataprivacy\output\categories($categories);
|
||||
|
||||
@@ -24,7 +24,7 @@
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
use coding_exception;
|
||||
use context_helper;
|
||||
use context_course;
|
||||
use context_system;
|
||||
use core\invalid_persistent_exception;
|
||||
use core\message\message;
|
||||
@@ -39,8 +39,8 @@ use required_capability_exception;
|
||||
use stdClass;
|
||||
use tool_dataprivacy\external\data_request_exporter;
|
||||
use tool_dataprivacy\local\helper;
|
||||
use tool_dataprivacy\task\initiate_data_request_task;
|
||||
use tool_dataprivacy\task\process_data_request_task;
|
||||
use tool_dataprivacy\data_request;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
@@ -64,6 +64,9 @@ class api {
|
||||
/** Newly submitted and we haven't yet started finding out where they have data. */
|
||||
const DATAREQUEST_STATUS_PENDING = 0;
|
||||
|
||||
/** Newly submitted and we have started to find the location of data. */
|
||||
const DATAREQUEST_STATUS_PREPROCESSING = 1;
|
||||
|
||||
/** Metadata ready and awaiting review and approval by the Data Protection officer. */
|
||||
const DATAREQUEST_STATUS_AWAITING_APPROVAL = 2;
|
||||
|
||||
@@ -91,12 +94,6 @@ class api {
|
||||
/** Data delete request completed, account is removed. */
|
||||
const DATAREQUEST_STATUS_DELETED = 10;
|
||||
|
||||
/** Approve data request. */
|
||||
const DATAREQUEST_ACTION_APPROVE = 1;
|
||||
|
||||
/** Reject data request. */
|
||||
const DATAREQUEST_ACTION_REJECT = 2;
|
||||
|
||||
/**
|
||||
* Determines whether the user can contact the site's Data Protection Officer via Moodle.
|
||||
*
|
||||
@@ -108,14 +105,18 @@ class api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the current user has the capability to manage data requests.
|
||||
* Check's whether the current user has the capability to manage data requests.
|
||||
*
|
||||
* @param int $userid The user ID.
|
||||
* @return bool
|
||||
* @throws coding_exception
|
||||
* @throws dml_exception
|
||||
*/
|
||||
public static function can_manage_data_requests($userid) {
|
||||
// Privacy officers can manage data requests.
|
||||
return self::is_site_dpo($userid);
|
||||
$context = context_system::instance();
|
||||
|
||||
// A user can manage data requests if he/she has the site DPO role and has the capability to manage data requests.
|
||||
return self::is_site_dpo($userid) && has_capability('tool/dataprivacy:managedatarequests', $context, $userid);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -135,31 +136,6 @@ class api {
|
||||
require_capability('tool/dataprivacy:managedataregistry', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the list of configured privacy officer roles.
|
||||
*
|
||||
* Every time this function is called, it checks each role if they have the 'managedatarequests' capability and removes
|
||||
* any role that doesn't have the required capability anymore.
|
||||
*
|
||||
* @return int[]
|
||||
* @throws dml_exception
|
||||
*/
|
||||
public static function get_assigned_privacy_officer_roles() {
|
||||
$roleids = [];
|
||||
|
||||
// Get roles from config.
|
||||
$configroleids = explode(',', str_replace(' ', '', get_config('tool_dataprivacy', 'dporoles')));
|
||||
if (!empty($configroleids)) {
|
||||
// Fetch roles that have the capability to manage data requests.
|
||||
$capableroles = array_keys(get_roles_with_capability('tool/dataprivacy:managedatarequests'));
|
||||
|
||||
// Extract the configured roles that have the capability from the list of capable roles.
|
||||
$roleids = array_intersect($capableroles, $configroleids);
|
||||
}
|
||||
|
||||
return $roleids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the role shortnames of Data Protection Officer roles.
|
||||
*
|
||||
@@ -168,7 +144,7 @@ class api {
|
||||
public static function get_dpo_role_names() : array {
|
||||
global $DB;
|
||||
|
||||
$dporoleids = self::get_assigned_privacy_officer_roles();
|
||||
$dporoleids = explode(',', str_replace(' ', '', get_config('tool_dataprivacy', 'dporoles')));
|
||||
$dponames = array();
|
||||
|
||||
if (!empty($dporoleids)) {
|
||||
@@ -180,15 +156,20 @@ class api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches the list of users with the Privacy Officer role.
|
||||
* Fetches the list of users with the Data Protection Officer role.
|
||||
*
|
||||
* @throws dml_exception
|
||||
*/
|
||||
public static function get_site_dpos() {
|
||||
// Get role(s) that can manage data requests.
|
||||
$dporoles = self::get_assigned_privacy_officer_roles();
|
||||
$dporoles = explode(',', get_config('tool_dataprivacy', 'dporoles'));
|
||||
|
||||
$dpos = [];
|
||||
$context = context_system::instance();
|
||||
foreach ($dporoles as $roleid) {
|
||||
if (empty($roleid)) {
|
||||
continue;
|
||||
}
|
||||
$allnames = get_all_user_name_fields(true, 'u');
|
||||
$fields = 'u.id, u.confirmed, u.username, '. $allnames . ', ' .
|
||||
'u.maildisplay, u.mailformat, u.maildigest, u.email, u.emailstop, u.city, '.
|
||||
@@ -208,14 +189,15 @@ class api {
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a given user is a site Privacy Officer.
|
||||
* Checks whether a given user is a site DPO.
|
||||
*
|
||||
* @param int $userid The user ID.
|
||||
* @return bool
|
||||
* @throws dml_exception
|
||||
*/
|
||||
public static function is_site_dpo($userid) {
|
||||
$dpos = self::get_site_dpos();
|
||||
return array_key_exists($userid, $dpos) || is_siteadmin();
|
||||
return array_key_exists($userid, $dpos);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -224,60 +206,49 @@ class api {
|
||||
* @param int $foruser The user whom the request is being made for.
|
||||
* @param int $type The request type.
|
||||
* @param string $comments Request comments.
|
||||
* @param int $creationmethod The creation method of the data request.
|
||||
* @param bool $notify Notify DPOs of this pending request.
|
||||
* @return data_request
|
||||
* @throws invalid_persistent_exception
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public static function create_data_request($foruser, $type, $comments = '',
|
||||
$creationmethod = data_request::DATAREQUEST_CREATION_MANUAL,
|
||||
$notify = null
|
||||
) {
|
||||
public static function create_data_request($foruser, $type, $comments = '') {
|
||||
global $USER;
|
||||
|
||||
if (null === $notify) {
|
||||
// Only if notifications have not been decided by caller.
|
||||
if ( data_request::DATAREQUEST_CREATION_AUTO == $creationmethod) {
|
||||
// If the request was automatically created, then do not notify unless explicitly set.
|
||||
$notify = false;
|
||||
} else {
|
||||
$notify = true;
|
||||
}
|
||||
}
|
||||
|
||||
$datarequest = new data_request();
|
||||
// The user the request is being made for.
|
||||
$datarequest->set('userid', $foruser);
|
||||
|
||||
// The cron is considered to be a guest user when it creates a data request.
|
||||
// NOTE: This should probably be changed. We should leave the default value for $requestinguser if
|
||||
// the request is not explicitly created by a specific user.
|
||||
$requestinguser = (isguestuser() && $creationmethod == data_request::DATAREQUEST_CREATION_AUTO) ?
|
||||
get_admin()->id : $USER->id;
|
||||
$requestinguser = $USER->id;
|
||||
// Check when the user is making a request on behalf of another.
|
||||
if ($requestinguser != $foruser) {
|
||||
if (self::is_site_dpo($requestinguser)) {
|
||||
// The user making the request is a DPO. Should be fine.
|
||||
$datarequest->set('dpo', $requestinguser);
|
||||
} else {
|
||||
// If not a DPO, only users with the capability to make data requests for the user should be allowed.
|
||||
// (e.g. users with the Parent role, etc).
|
||||
if (!self::can_create_data_request_for_user($foruser)) {
|
||||
$forusercontext = \context_user::instance($foruser);
|
||||
throw new required_capability_exception($forusercontext,
|
||||
'tool/dataprivacy:makedatarequestsforchildren', 'nopermissions', '');
|
||||
}
|
||||
}
|
||||
}
|
||||
// The user making the request.
|
||||
$datarequest->set('requestedby', $requestinguser);
|
||||
// Set status.
|
||||
$datarequest->set('status', self::DATAREQUEST_STATUS_AWAITING_APPROVAL);
|
||||
$datarequest->set('status', self::DATAREQUEST_STATUS_PENDING);
|
||||
// Set request type.
|
||||
$datarequest->set('type', $type);
|
||||
// Set request comments.
|
||||
$datarequest->set('comments', $comments);
|
||||
// Set the creation method.
|
||||
$datarequest->set('creationmethod', $creationmethod);
|
||||
|
||||
// Store subject access request.
|
||||
$datarequest->create();
|
||||
|
||||
if ($notify) {
|
||||
// Get the list of the site Data Protection Officers.
|
||||
$dpos = api::get_site_dpos();
|
||||
|
||||
// Email the data request to the Data Protection Officer(s)/Admin(s).
|
||||
foreach ($dpos as $dpo) {
|
||||
api::notify_dpo($dpo, $datarequest);
|
||||
}
|
||||
}
|
||||
// Fire an ad hoc task to initiate the data request process.
|
||||
$task = new initiate_data_request_task();
|
||||
$task->set_custom_data(['requestid' => $datarequest->get('id')]);
|
||||
manager::queue_adhoc_task($task, true);
|
||||
|
||||
return $datarequest;
|
||||
}
|
||||
@@ -292,7 +263,6 @@ class api {
|
||||
* @param int $userid The User ID.
|
||||
* @param int[] $statuses The status filters.
|
||||
* @param int[] $types The request type filters.
|
||||
* @param int[] $creationmethods The request creation method filters.
|
||||
* @param string $sort The order by clause.
|
||||
* @param int $offset Amount of records to skip.
|
||||
* @param int $limit Amount of records to fetch.
|
||||
@@ -300,8 +270,7 @@ class api {
|
||||
* @throws coding_exception
|
||||
* @throws dml_exception
|
||||
*/
|
||||
public static function get_data_requests($userid = 0, $statuses = [], $types = [], $creationmethods = [],
|
||||
$sort = '', $offset = 0, $limit = 0) {
|
||||
public static function get_data_requests($userid = 0, $statuses = [], $types = [], $sort = '', $offset = 0, $limit = 0) {
|
||||
global $DB, $USER;
|
||||
$results = [];
|
||||
$sqlparams = [];
|
||||
@@ -325,13 +294,6 @@ class api {
|
||||
$sqlparams = array_merge($sqlparams, $typeparams);
|
||||
}
|
||||
|
||||
// Set request creation method filter.
|
||||
if (!empty($creationmethods)) {
|
||||
list($typeinsql, $typeparams) = $DB->get_in_or_equal($creationmethods, SQL_PARAMS_NAMED);
|
||||
$sqlconditions[] = "creationmethod $typeinsql";
|
||||
$sqlparams = array_merge($sqlparams, $typeparams);
|
||||
}
|
||||
|
||||
if ($userid) {
|
||||
// Get the data requests for the user or data requests made by the user.
|
||||
$sqlconditions[] = "(userid = :userid OR requestedby = :requestedby)";
|
||||
@@ -374,7 +336,7 @@ class api {
|
||||
|
||||
if (!empty($expiredrequests)) {
|
||||
data_request::expire($expiredrequests);
|
||||
$results = self::get_data_requests($userid, $statuses, $types, $creationmethods, $sort, $offset, $limit);
|
||||
$results = self::get_data_requests($userid, $statuses, $types, $sort, $offset, $limit);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -387,12 +349,11 @@ class api {
|
||||
* @param int $userid The User ID.
|
||||
* @param int[] $statuses The status filters.
|
||||
* @param int[] $types The request type filters.
|
||||
* @param int[] $creationmethods The request creation method filters.
|
||||
* @return int
|
||||
* @throws coding_exception
|
||||
* @throws dml_exception
|
||||
*/
|
||||
public static function get_data_requests_count($userid = 0, $statuses = [], $types = [], $creationmethods = []) {
|
||||
public static function get_data_requests_count($userid = 0, $statuses = [], $types = []) {
|
||||
global $DB, $USER;
|
||||
$count = 0;
|
||||
$sqlparams = [];
|
||||
@@ -406,11 +367,6 @@ class api {
|
||||
$sqlconditions[] = "type $typeinsql";
|
||||
$sqlparams = array_merge($sqlparams, $typeparams);
|
||||
}
|
||||
if (!empty($creationmethods)) {
|
||||
list($typeinsql, $typeparams) = $DB->get_in_or_equal($creationmethods, SQL_PARAMS_NAMED);
|
||||
$sqlconditions[] = "creationmethod $typeinsql";
|
||||
$sqlparams = array_merge($sqlparams, $typeparams);
|
||||
}
|
||||
if ($userid) {
|
||||
// Get the data requests for the user or data requests made by the user.
|
||||
$sqlconditions[] = "(userid = :userid OR requestedby = :requestedby)";
|
||||
@@ -469,8 +425,8 @@ class api {
|
||||
self::DATAREQUEST_STATUS_EXPIRED,
|
||||
self::DATAREQUEST_STATUS_DELETED,
|
||||
];
|
||||
list($insql, $inparams) = $DB->get_in_or_equal($nonpendingstatuses, SQL_PARAMS_NAMED, 'st', false);
|
||||
$select = "type = :type AND userid = :userid AND status {$insql}";
|
||||
list($insql, $inparams) = $DB->get_in_or_equal($nonpendingstatuses, SQL_PARAMS_NAMED);
|
||||
$select = 'type = :type AND userid = :userid AND status NOT ' . $insql;
|
||||
$params = array_merge([
|
||||
'type' => $type,
|
||||
'userid' => $userid
|
||||
@@ -479,48 +435,6 @@ class api {
|
||||
return data_request::record_exists_select($select, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Find whether any ongoing requests exist for a set of users.
|
||||
*
|
||||
* @param array $userids
|
||||
* @return array
|
||||
*/
|
||||
public static function find_ongoing_request_types_for_users(array $userids) : array {
|
||||
global $DB;
|
||||
|
||||
if (empty($userids)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
// Check if the user already has an incomplete data request of the same type.
|
||||
$nonpendingstatuses = [
|
||||
self::DATAREQUEST_STATUS_COMPLETE,
|
||||
self::DATAREQUEST_STATUS_CANCELLED,
|
||||
self::DATAREQUEST_STATUS_REJECTED,
|
||||
self::DATAREQUEST_STATUS_DOWNLOAD_READY,
|
||||
self::DATAREQUEST_STATUS_EXPIRED,
|
||||
self::DATAREQUEST_STATUS_DELETED,
|
||||
];
|
||||
list($statusinsql, $statusparams) = $DB->get_in_or_equal($nonpendingstatuses, SQL_PARAMS_NAMED, 'st', false);
|
||||
list($userinsql, $userparams) = $DB->get_in_or_equal($userids, SQL_PARAMS_NAMED, 'us');
|
||||
|
||||
$select = "userid {$userinsql} AND status {$statusinsql}";
|
||||
$params = array_merge($statusparams, $userparams);
|
||||
|
||||
$requests = $DB->get_records_select(data_request::TABLE, $select, $params, 'userid', 'id, userid, type');
|
||||
|
||||
$returnval = [];
|
||||
foreach ($userids as $userid) {
|
||||
$returnval[$userid] = (object) [];
|
||||
}
|
||||
|
||||
foreach ($requests as $request) {
|
||||
$returnval[$request->userid]->{$request->type} = true;
|
||||
}
|
||||
|
||||
return $returnval;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determines whether a request is active or not based on its status.
|
||||
*
|
||||
@@ -617,6 +531,11 @@ class api {
|
||||
// Update the status and the DPO.
|
||||
$result = self::update_request_status($requestid, self::DATAREQUEST_STATUS_APPROVED, $USER->id);
|
||||
|
||||
// Approve all the contexts attached to the request.
|
||||
// Currently, approving the request implicitly approves all associated contexts, but this may change in future, allowing
|
||||
// users to selectively approve certain contexts only.
|
||||
self::update_request_contexts_with_status($requestid, contextlist_context::STATUS_APPROVED);
|
||||
|
||||
// Fire an ad hoc task to initiate the data request process.
|
||||
$task = new process_data_request_task();
|
||||
$task->set_custom_data(['requestid' => $requestid]);
|
||||
@@ -700,8 +619,6 @@ class api {
|
||||
'requestedby' => $requestedby->fullname,
|
||||
'requesttype' => $typetext,
|
||||
'requestdate' => userdate($requestdata->timecreated),
|
||||
'requestorigin' => $SITE->fullname,
|
||||
'requestoriginurl' => new moodle_url('/'),
|
||||
'requestcomments' => $requestdata->messagehtml,
|
||||
'datarequestsurl' => $datarequestsurl
|
||||
];
|
||||
@@ -727,31 +644,16 @@ class api {
|
||||
/**
|
||||
* Checks whether a non-DPO user can make a data request for another user.
|
||||
*
|
||||
* @param int $user The user ID of the target user.
|
||||
* @param int $requester The user ID of the user making the request.
|
||||
* @return bool
|
||||
* @param int $user The user ID of the target user.
|
||||
* @param int $requester The user ID of the user making the request.
|
||||
* @return bool
|
||||
* @throws coding_exception
|
||||
*/
|
||||
public static function can_create_data_request_for_user($user, $requester = null) {
|
||||
$usercontext = \context_user::instance($user);
|
||||
|
||||
return has_capability('tool/dataprivacy:makedatarequestsforchildren', $usercontext, $requester);
|
||||
}
|
||||
|
||||
/**
|
||||
* Require that the current user can make a data request for the specified other user.
|
||||
*
|
||||
* @param int $user The user ID of the target user.
|
||||
* @param int $requester The user ID of the user making the request.
|
||||
* @return bool
|
||||
*/
|
||||
public static function require_can_create_data_request_for_user($user, $requester = null) {
|
||||
$usercontext = \context_user::instance($user);
|
||||
|
||||
require_capability('tool/dataprivacy:makedatarequestsforchildren', $usercontext, $requester);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether a user can download a data request.
|
||||
*
|
||||
@@ -807,6 +709,8 @@ class api {
|
||||
* @return \tool_dataprivacy\purpose.
|
||||
*/
|
||||
public static function create_purpose(stdClass $record) {
|
||||
self::check_can_manage_data_registry();
|
||||
|
||||
$purpose = new purpose(0, $record);
|
||||
$purpose->create();
|
||||
|
||||
@@ -820,6 +724,8 @@ class api {
|
||||
* @return \tool_dataprivacy\purpose.
|
||||
*/
|
||||
public static function update_purpose(stdClass $record) {
|
||||
self::check_can_manage_data_registry();
|
||||
|
||||
if (!isset($record->sensitivedatareasons)) {
|
||||
$record->sensitivedatareasons = '';
|
||||
}
|
||||
@@ -839,6 +745,8 @@ class api {
|
||||
* @return bool
|
||||
*/
|
||||
public static function delete_purpose($id) {
|
||||
self::check_can_manage_data_registry();
|
||||
|
||||
$purpose = new purpose($id);
|
||||
if ($purpose->is_used()) {
|
||||
throw new \moodle_exception('Purpose with id ' . $id . ' can not be deleted because it is used.');
|
||||
@@ -852,6 +760,8 @@ class api {
|
||||
* @return \tool_dataprivacy\purpose[]
|
||||
*/
|
||||
public static function get_purposes() {
|
||||
self::check_can_manage_data_registry();
|
||||
|
||||
return purpose::get_records([], 'name', 'ASC');
|
||||
}
|
||||
|
||||
@@ -862,6 +772,8 @@ class api {
|
||||
* @return \tool_dataprivacy\category.
|
||||
*/
|
||||
public static function create_category(stdClass $record) {
|
||||
self::check_can_manage_data_registry();
|
||||
|
||||
$category = new category(0, $record);
|
||||
$category->create();
|
||||
|
||||
@@ -875,6 +787,8 @@ class api {
|
||||
* @return \tool_dataprivacy\category.
|
||||
*/
|
||||
public static function update_category(stdClass $record) {
|
||||
self::check_can_manage_data_registry();
|
||||
|
||||
$category = new category($record->id);
|
||||
$category->from_record($record);
|
||||
|
||||
@@ -890,6 +804,8 @@ class api {
|
||||
* @return bool
|
||||
*/
|
||||
public static function delete_category($id) {
|
||||
self::check_can_manage_data_registry();
|
||||
|
||||
$category = new category($id);
|
||||
if ($category->is_used()) {
|
||||
throw new \moodle_exception('Category with id ' . $id . ' can not be deleted because it is used.');
|
||||
@@ -903,6 +819,8 @@ class api {
|
||||
* @return \tool_dataprivacy\category[]
|
||||
*/
|
||||
public static function get_categories() {
|
||||
self::check_can_manage_data_registry();
|
||||
|
||||
return category::get_records([], 'name', 'ASC');
|
||||
}
|
||||
|
||||
@@ -913,6 +831,8 @@ class api {
|
||||
* @return \tool_dataprivacy\context_instance
|
||||
*/
|
||||
public static function set_context_instance($record) {
|
||||
self::check_can_manage_data_registry($record->contextid);
|
||||
|
||||
if ($instance = context_instance::get_record_by_contextid($record->contextid, false)) {
|
||||
// Update.
|
||||
$instance->from_record($record);
|
||||
@@ -939,6 +859,7 @@ class api {
|
||||
* @return null
|
||||
*/
|
||||
public static function unset_context_instance(context_instance $instance) {
|
||||
self::check_can_manage_data_registry($instance->get('contextid'));
|
||||
$instance->delete();
|
||||
}
|
||||
|
||||
@@ -952,6 +873,9 @@ class api {
|
||||
public static function set_contextlevel($record) {
|
||||
global $DB;
|
||||
|
||||
// Only manager at system level can set this.
|
||||
self::check_can_manage_data_registry();
|
||||
|
||||
if ($record->contextlevel != CONTEXT_SYSTEM && $record->contextlevel != CONTEXT_USER) {
|
||||
throw new \coding_exception('Only context system and context user can set a contextlevel ' .
|
||||
'purpose and retention');
|
||||
@@ -982,7 +906,8 @@ class api {
|
||||
* @param int $forcedvalue Use this categoryid value as if this was this context instance category.
|
||||
* @return category|false
|
||||
*/
|
||||
public static function get_effective_context_category(\context $context, $forcedvalue = false) {
|
||||
public static function get_effective_context_category(\context $context, $forcedvalue=false) {
|
||||
self::check_can_manage_data_registry($context->id);
|
||||
if (!data_registry::defaults_set()) {
|
||||
return false;
|
||||
}
|
||||
@@ -997,7 +922,8 @@ class api {
|
||||
* @param int $forcedvalue Use this purposeid value as if this was this context instance purpose.
|
||||
* @return purpose|false
|
||||
*/
|
||||
public static function get_effective_context_purpose(\context $context, $forcedvalue = false) {
|
||||
public static function get_effective_context_purpose(\context $context, $forcedvalue=false) {
|
||||
self::check_can_manage_data_registry($context->id);
|
||||
if (!data_registry::defaults_set()) {
|
||||
return false;
|
||||
}
|
||||
@@ -1009,14 +935,16 @@ class api {
|
||||
* Returns the effective category given a context level.
|
||||
*
|
||||
* @param int $contextlevel
|
||||
* @param int $forcedvalue Use this categoryid value as if this was this context level category.
|
||||
* @return category|false
|
||||
*/
|
||||
public static function get_effective_contextlevel_category($contextlevel) {
|
||||
public static function get_effective_contextlevel_category($contextlevel, $forcedvalue=false) {
|
||||
self::check_can_manage_data_registry(\context_system::instance()->id);
|
||||
if (!data_registry::defaults_set()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return data_registry::get_effective_contextlevel_value($contextlevel, 'category');
|
||||
return data_registry::get_effective_contextlevel_value($contextlevel, 'category', $forcedvalue);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1027,6 +955,7 @@ class api {
|
||||
* @return purpose|false
|
||||
*/
|
||||
public static function get_effective_contextlevel_purpose($contextlevel, $forcedvalue=false) {
|
||||
self::check_can_manage_data_registry(\context_system::instance()->id);
|
||||
if (!data_registry::defaults_set()) {
|
||||
return false;
|
||||
}
|
||||
@@ -1041,6 +970,8 @@ class api {
|
||||
* @return \tool_dataprivacy\expired_context
|
||||
*/
|
||||
public static function create_expired_context($contextid) {
|
||||
self::check_can_manage_data_registry();
|
||||
|
||||
$record = (object)[
|
||||
'contextid' => $contextid,
|
||||
'status' => expired_context::STATUS_EXPIRED,
|
||||
@@ -1058,6 +989,8 @@ class api {
|
||||
* @return bool True on success.
|
||||
*/
|
||||
public static function delete_expired_context($id) {
|
||||
self::check_can_manage_data_registry();
|
||||
|
||||
$expiredcontext = new expired_context($id);
|
||||
return $expiredcontext->delete();
|
||||
}
|
||||
@@ -1070,156 +1003,142 @@ class api {
|
||||
* @return null
|
||||
*/
|
||||
public static function set_expired_context_status(expired_context $expiredctx, $status) {
|
||||
self::check_can_manage_data_registry();
|
||||
|
||||
$expiredctx->set('status', $status);
|
||||
$expiredctx->save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all contextlists having at least one approved context, and returns them as in a contextlist_collection.
|
||||
* Adds the contexts from the contextlist_collection to the request with the status provided.
|
||||
*
|
||||
* @param contextlist_collection $collection The collection of unapproved contextlist objects.
|
||||
* @param \stdClass $foruser The target user
|
||||
* @param int $type The purpose of the collection
|
||||
* @return contextlist_collection The collection of approved_contextlist objects.
|
||||
* @param contextlist_collection $clcollection a collection of contextlists for all components.
|
||||
* @param int $requestid the id of the request.
|
||||
* @param int $status the status to set the contexts to.
|
||||
*/
|
||||
public static function get_approved_contextlist_collection_for_collection(contextlist_collection $collection,
|
||||
\stdClass $foruser, int $type) : contextlist_collection {
|
||||
public static function add_request_contexts_with_status(contextlist_collection $clcollection, int $requestid, int $status) {
|
||||
$request = new data_request($requestid);
|
||||
foreach ($clcollection as $contextlist) {
|
||||
// Convert the \core_privacy\local\request\contextlist into a contextlist persistent and store it.
|
||||
$clp = \tool_dataprivacy\contextlist::from_contextlist($contextlist);
|
||||
$clp->create();
|
||||
$contextlistid = $clp->get('id');
|
||||
|
||||
// Create the approved contextlist collection object.
|
||||
$approvedcollection = new contextlist_collection($collection->get_userid());
|
||||
$isconfigured = data_registry::defaults_set();
|
||||
|
||||
foreach ($collection as $contextlist) {
|
||||
$contextids = [];
|
||||
foreach ($contextlist as $context) {
|
||||
if ($isconfigured && self::DATAREQUEST_TYPE_DELETE == $type) {
|
||||
// Data can only be deleted from it if the context is either expired, or unprotected.
|
||||
// Note: We can only check whether a context is expired or unprotected if the site is configured and
|
||||
// defaults are set appropriately. If they are not, we treat all contexts as though they are
|
||||
// unprotected.
|
||||
$purpose = static::get_effective_context_purpose($context);
|
||||
if (!expired_contexts_manager::is_context_expired_or_unprotected_for_user($context, $foruser)) {
|
||||
// Store the associated contexts in the contextlist.
|
||||
foreach ($contextlist->get_contextids() as $contextid) {
|
||||
if ($request->get('type') == static::DATAREQUEST_TYPE_DELETE) {
|
||||
$context = \context::instance_by_id($contextid);
|
||||
if (($purpose = static::get_effective_context_purpose($context)) && !empty($purpose->get('protected'))) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$contextids[] = $context->id;
|
||||
$context = new contextlist_context();
|
||||
$context->set('contextid', $contextid)
|
||||
->set('contextlistid', $contextlistid)
|
||||
->set('status', $status)
|
||||
->create();
|
||||
}
|
||||
|
||||
// The data for the last component contextlist won't have been written yet, so write it now.
|
||||
if (!empty($contextids)) {
|
||||
$approvedcollection->add_contextlist(
|
||||
new approved_contextlist($foruser, $contextlist->get_component(), $contextids)
|
||||
);
|
||||
// Create the relation to the request.
|
||||
$requestcontextlist = request_contextlist::create_relation($requestid, $contextlistid);
|
||||
$requestcontextlist->create();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the status of all contexts associated with the request.
|
||||
*
|
||||
* @param int $requestid the requestid to which the contexts belong.
|
||||
* @param int $status the status to set to.
|
||||
* @throws \dml_exception if the requestid is invalid.
|
||||
* @throws \moodle_exception if the status is invalid.
|
||||
*/
|
||||
public static function update_request_contexts_with_status(int $requestid, int $status) {
|
||||
// Validate contextlist_context status using the persistent's attribute validation.
|
||||
$contextlistcontext = new contextlist_context();
|
||||
$contextlistcontext->set('status', $status);
|
||||
if (array_key_exists('status', $contextlistcontext->get_errors())) {
|
||||
throw new moodle_exception("Invalid contextlist_context status: $status");
|
||||
}
|
||||
|
||||
// Validate requestid using the persistent's record validation.
|
||||
// A dml_exception is thrown if the record is missing.
|
||||
$datarequest = new data_request($requestid);
|
||||
|
||||
// Bulk update the status of the request contexts.
|
||||
global $DB;
|
||||
|
||||
$select = "SELECT ctx.id as id
|
||||
FROM {" . request_contextlist::TABLE . "} rcl
|
||||
JOIN {" . contextlist::TABLE . "} cl ON rcl.contextlistid = cl.id
|
||||
JOIN {" . contextlist_context::TABLE . "} ctx ON cl.id = ctx.contextlistid
|
||||
WHERE rcl.requestid = ?";
|
||||
|
||||
// Fetch records IDs to be updated and update by chunks, if applicable (limit of 1000 records per update).
|
||||
$limit = 1000;
|
||||
$idstoupdate = $DB->get_fieldset_sql($select, [$requestid]);
|
||||
$count = count($idstoupdate);
|
||||
$idchunks = $idstoupdate;
|
||||
if ($count > $limit) {
|
||||
$idchunks = array_chunk($idstoupdate, $limit);
|
||||
}
|
||||
$transaction = $DB->start_delegated_transaction();
|
||||
$initialparams = [$status];
|
||||
foreach ($idchunks as $chunk) {
|
||||
list($insql, $inparams) = $DB->get_in_or_equal($chunk);
|
||||
$update = "UPDATE {" . contextlist_context::TABLE . "}
|
||||
SET status = ?
|
||||
WHERE id $insql";
|
||||
$params = array_merge($initialparams, $inparams);
|
||||
$DB->execute($update, $params);
|
||||
}
|
||||
$transaction->allow_commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Finds all request contextlists having at least on approved context, and returns them as in a contextlist_collection.
|
||||
*
|
||||
* @param data_request $request the data request with which the contextlists are associated.
|
||||
* @return contextlist_collection the collection of approved_contextlist objects.
|
||||
*/
|
||||
public static function get_approved_contextlist_collection_for_request(data_request $request) : contextlist_collection {
|
||||
$foruser = core_user::get_user($request->get('userid'));
|
||||
|
||||
// Fetch all approved contextlists and create the core_privacy\local\request\contextlist objects here.
|
||||
global $DB;
|
||||
$sql = "SELECT cl.component, ctx.contextid
|
||||
FROM {" . request_contextlist::TABLE . "} rcl
|
||||
JOIN {" . contextlist::TABLE . "} cl ON rcl.contextlistid = cl.id
|
||||
JOIN {" . contextlist_context::TABLE . "} ctx ON cl.id = ctx.contextlistid
|
||||
WHERE rcl.requestid = ?
|
||||
AND ctx.status = ?
|
||||
ORDER BY cl.component, ctx.contextid";
|
||||
|
||||
// Create the approved contextlist collection object.
|
||||
$lastcomponent = null;
|
||||
$approvedcollection = new contextlist_collection($foruser->id);
|
||||
|
||||
$rs = $DB->get_recordset_sql($sql, [$request->get('id'), contextlist_context::STATUS_APPROVED]);
|
||||
foreach ($rs as $record) {
|
||||
// If we encounter a new component, and we've built up contexts for the last, then add the approved_contextlist for the
|
||||
// last (the one we've just finished with) and reset the context array for the next one.
|
||||
if ($lastcomponent != $record->component) {
|
||||
if (!empty($contexts)) {
|
||||
$approvedcollection->add_contextlist(new approved_contextlist($foruser, $lastcomponent, $contexts));
|
||||
}
|
||||
$contexts = [];
|
||||
}
|
||||
|
||||
$contexts[] = $record->contextid;
|
||||
$lastcomponent = $record->component;
|
||||
}
|
||||
$rs->close();
|
||||
|
||||
// The data for the last component contextlist won't have been written yet, so write it now.
|
||||
if (!empty($contexts)) {
|
||||
$approvedcollection->add_contextlist(new approved_contextlist($foruser, $lastcomponent, $contexts));
|
||||
}
|
||||
|
||||
return $approvedcollection;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the default category and purpose for a given context level (and optionally, a plugin).
|
||||
*
|
||||
* @param int $contextlevel The context level.
|
||||
* @param int $categoryid The ID matching the category.
|
||||
* @param int $purposeid The ID matching the purpose record.
|
||||
* @param int $activity The name of the activity that we're making a defaults configuration for.
|
||||
* @param bool $override Whether to override the purpose/categories of existing instances to these defaults.
|
||||
* @return boolean True if set/unset config succeeds. Otherwise, it throws an exception.
|
||||
*/
|
||||
public static function set_context_defaults($contextlevel, $categoryid, $purposeid, $activity = null, $override = false) {
|
||||
global $DB;
|
||||
|
||||
// Get the class name associated with this context level.
|
||||
$classname = context_helper::get_class_for_level($contextlevel);
|
||||
list($purposevar, $categoryvar) = data_registry::var_names_from_context($classname, $activity);
|
||||
|
||||
// Check the default category to be set.
|
||||
if ($categoryid == context_instance::INHERIT) {
|
||||
unset_config($categoryvar, 'tool_dataprivacy');
|
||||
|
||||
} else {
|
||||
// Make sure the given category ID exists first.
|
||||
$categorypersistent = new category($categoryid);
|
||||
$categorypersistent->read();
|
||||
|
||||
// Then set the new default value.
|
||||
set_config($categoryvar, $categoryid, 'tool_dataprivacy');
|
||||
}
|
||||
|
||||
// Check the default purpose to be set.
|
||||
if ($purposeid == context_instance::INHERIT) {
|
||||
// If the defaults is set to inherit, just unset the config value.
|
||||
unset_config($purposevar, 'tool_dataprivacy');
|
||||
|
||||
} else {
|
||||
// Make sure the given purpose ID exists first.
|
||||
$purposepersistent = new purpose($purposeid);
|
||||
$purposepersistent->read();
|
||||
|
||||
// Then set the new default value.
|
||||
set_config($purposevar, $purposeid, 'tool_dataprivacy');
|
||||
}
|
||||
|
||||
// Unset instances that have been assigned with custom purpose and category, if override was specified.
|
||||
if ($override) {
|
||||
// We'd like to find context IDs that we want to unset.
|
||||
$statements = ["SELECT c.id as contextid FROM {context} c"];
|
||||
// Based on this context level.
|
||||
$params = ['contextlevel' => $contextlevel];
|
||||
|
||||
if ($contextlevel == CONTEXT_MODULE) {
|
||||
// If we're deleting module context instances, we need to make sure the instance ID is in the course modules table.
|
||||
$statements[] = "JOIN {course_modules} cm ON cm.id = c.instanceid";
|
||||
// And that the module is listed on the modules table.
|
||||
$statements[] = "JOIN {modules} m ON m.id = cm.module";
|
||||
|
||||
if ($activity) {
|
||||
// If we're overriding for an activity module, make sure that the context instance matches that activity.
|
||||
$statements[] = "AND m.name = :modname";
|
||||
$params['modname'] = $activity;
|
||||
}
|
||||
}
|
||||
// Make sure this context instance exists in the tool_dataprivacy_ctxinstance table.
|
||||
$statements[] = "JOIN {tool_dataprivacy_ctxinstance} tdc ON tdc.contextid = c.id";
|
||||
// And that the context level of this instance matches the given context level.
|
||||
$statements[] = "WHERE c.contextlevel = :contextlevel";
|
||||
|
||||
// Build our SQL query by gluing the statements.
|
||||
$sql = implode("\n", $statements);
|
||||
|
||||
// Get the context records matching our query.
|
||||
$contextids = $DB->get_fieldset_sql($sql, $params);
|
||||
|
||||
// Delete the matching context instances.
|
||||
foreach ($contextids as $contextid) {
|
||||
if ($instance = context_instance::get_record_by_contextid($contextid, false)) {
|
||||
self::unset_context_instance($instance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Format the supplied date interval as a retention period.
|
||||
*
|
||||
* @param \DateInterval $interval
|
||||
* @return string
|
||||
*/
|
||||
public static function format_retention_period(\DateInterval $interval) : string {
|
||||
// It is one or another.
|
||||
if ($interval->y) {
|
||||
$formattedtime = get_string('numyears', 'moodle', $interval->format('%y'));
|
||||
} else if ($interval->m) {
|
||||
$formattedtime = get_string('nummonths', 'moodle', $interval->format('%m'));
|
||||
} else if ($interval->d) {
|
||||
$formattedtime = get_string('numdays', 'moodle', $interval->format('%d'));
|
||||
} else {
|
||||
$formattedtime = get_string('retentionperiodzero', 'tool_dataprivacy');
|
||||
}
|
||||
|
||||
return $formattedtime;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,64 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Contains the contextlist persistent.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core\persistent;
|
||||
|
||||
/**
|
||||
* The contextlist persistent.
|
||||
*
|
||||
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class contextlist extends persistent {
|
||||
|
||||
/** The table name this persistent object maps to. */
|
||||
const TABLE = 'tool_dataprivacy_contextlist';
|
||||
|
||||
/**
|
||||
* Return the definition of the properties of this model.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function define_properties() {
|
||||
return [
|
||||
'component' => [
|
||||
'type' => PARAM_TEXT
|
||||
]
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new contextlist persistent from an instance of \core_privacy\local\request\contextlist.
|
||||
*
|
||||
* @param \core_privacy\local\request\contextlist $contextlist the core privacy contextlist.
|
||||
* @return contextlist a contextlist persistent.
|
||||
*/
|
||||
public static function from_contextlist(\core_privacy\local\request\contextlist $contextlist) : contextlist {
|
||||
$contextlistpersistent = new contextlist();
|
||||
return $contextlistpersistent->set('component', $contextlist->get_component());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Contains the contextlist_context persistent.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core\persistent;
|
||||
|
||||
/**
|
||||
* The contextlist_context persistent.
|
||||
*
|
||||
* @copyright 2018 Jake Dallimore <jrhdallimore@gmail.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class contextlist_context extends persistent {
|
||||
|
||||
/** The table name this persistent object maps to. */
|
||||
const TABLE = 'tool_dataprivacy_ctxlst_ctx';
|
||||
|
||||
/** This context is pending approval. */
|
||||
const STATUS_PENDING = 0;
|
||||
|
||||
/** This context has been approved. */
|
||||
const STATUS_APPROVED = 1;
|
||||
|
||||
/** This context has been rejected. */
|
||||
const STATUS_REJECTED = 2;
|
||||
|
||||
/**
|
||||
* Return the definition of the properties of this model.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected static function define_properties() {
|
||||
return [
|
||||
'contextid' => [
|
||||
'type' => PARAM_INT
|
||||
],
|
||||
'contextlistid' => [
|
||||
'type' => PARAM_INT
|
||||
],
|
||||
'status' => [
|
||||
'choices' => [
|
||||
self::STATUS_PENDING,
|
||||
self::STATUS_APPROVED,
|
||||
self::STATUS_REJECTED,
|
||||
],
|
||||
'default' => self::STATUS_PENDING,
|
||||
'type' => PARAM_INT
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -28,10 +28,15 @@
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
use coding_exception;
|
||||
use core\persistent;
|
||||
use tool_dataprivacy\purpose;
|
||||
use tool_dataprivacy\category;
|
||||
use tool_dataprivacy\contextlevel;
|
||||
use tool_dataprivacy\context_instance;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
require_once($CFG->libdir . '/coursecatlib.php');
|
||||
|
||||
/**
|
||||
* Data registry business logic methods. Mostly internal stuff.
|
||||
*
|
||||
@@ -39,25 +44,28 @@ defined('MOODLE_INTERNAL') || die();
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class data_registry {
|
||||
|
||||
/**
|
||||
* @var array Inheritance between context levels.
|
||||
*/
|
||||
private static $contextlevelinheritance = [
|
||||
CONTEXT_USER => [CONTEXT_SYSTEM],
|
||||
CONTEXT_COURSECAT => [CONTEXT_SYSTEM],
|
||||
CONTEXT_COURSE => [CONTEXT_COURSECAT, CONTEXT_SYSTEM],
|
||||
CONTEXT_MODULE => [CONTEXT_COURSE, CONTEXT_COURSECAT, CONTEXT_SYSTEM],
|
||||
CONTEXT_BLOCK => [CONTEXT_COURSE, CONTEXT_COURSECAT, CONTEXT_SYSTEM],
|
||||
];
|
||||
|
||||
/**
|
||||
* Returns purpose and category var names from a context class name
|
||||
*
|
||||
* @param string $classname The context level's class.
|
||||
* @param string $pluginname The name of the plugin associated with the context level.
|
||||
* @param string $classname
|
||||
* @return string[]
|
||||
*/
|
||||
public static function var_names_from_context($classname, $pluginname = '') {
|
||||
$pluginname = trim($pluginname);
|
||||
if (!empty($pluginname)) {
|
||||
$categoryvar = $classname . '_' . $pluginname . '_category';
|
||||
$purposevar = $classname . '_' . $pluginname . '_purpose';
|
||||
} else {
|
||||
$categoryvar = $classname . '_category';
|
||||
$purposevar = $classname . '_purpose';
|
||||
}
|
||||
public static function var_names_from_context($classname) {
|
||||
return [
|
||||
$purposevar,
|
||||
$categoryvar
|
||||
$classname . '_purpose',
|
||||
$classname . '_category',
|
||||
];
|
||||
}
|
||||
|
||||
@@ -66,35 +74,22 @@ class data_registry {
|
||||
*
|
||||
* The caller code is responsible of checking that $contextlevel is an integer.
|
||||
*
|
||||
* @param int $contextlevel The context level.
|
||||
* @param string $pluginname The name of the plugin associated with the context level.
|
||||
* @return int[]|false[]
|
||||
* @param int $contextlevel
|
||||
* @return int|false[]
|
||||
*/
|
||||
public static function get_defaults($contextlevel, $pluginname = '') {
|
||||
public static function get_defaults($contextlevel) {
|
||||
|
||||
$classname = \context_helper::get_class_for_level($contextlevel);
|
||||
list($purposevar, $categoryvar) = self::var_names_from_context($classname, $pluginname);
|
||||
list($purposevar, $categoryvar) = self::var_names_from_context($classname);
|
||||
|
||||
$purposeid = get_config('tool_dataprivacy', $purposevar);
|
||||
$categoryid = get_config('tool_dataprivacy', $categoryvar);
|
||||
|
||||
if (!empty($pluginname)) {
|
||||
list($purposevar, $categoryvar) = self::var_names_from_context($classname);
|
||||
// If the plugin-level doesn't have a default purpose set, try the context level.
|
||||
if ($purposeid == false) {
|
||||
$purposeid = get_config('tool_dataprivacy', $purposevar);
|
||||
}
|
||||
|
||||
// If the plugin-level doesn't have a default category set, try the context level.
|
||||
if ($categoryid == false) {
|
||||
$categoryid = get_config('tool_dataprivacy', $categoryvar);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($purposeid)) {
|
||||
$purposeid = context_instance::NOTSET;
|
||||
$purposeid = false;
|
||||
}
|
||||
if (empty($categoryid)) {
|
||||
$categoryid = context_instance::NOTSET;
|
||||
$categoryid = false;
|
||||
}
|
||||
|
||||
return [$purposeid, $categoryid];
|
||||
@@ -118,17 +113,17 @@ class data_registry {
|
||||
/**
|
||||
* Returns all site categories that are visible to the current user.
|
||||
*
|
||||
* @return \core_course_category[]
|
||||
* @return \coursecat[]
|
||||
*/
|
||||
public static function get_site_categories() {
|
||||
global $DB;
|
||||
|
||||
if (method_exists('\core_course_category', 'get_all')) {
|
||||
$categories = \core_course_category::get_all(['returnhidden' => true]);
|
||||
if (method_exists('\coursecat', 'get_all')) {
|
||||
$categories = \coursecat::get_all(['returnhidden' => true]);
|
||||
} else {
|
||||
// Fallback (to be removed once this gets integrated into master).
|
||||
$ids = $DB->get_fieldset_select('course_categories', 'id', '');
|
||||
$categories = \core_course_category::get_many($ids);
|
||||
$categories = \coursecat::get_many($ids);
|
||||
}
|
||||
|
||||
foreach ($categories as $key => $category) {
|
||||
@@ -152,8 +147,8 @@ class data_registry {
|
||||
|
||||
if ($contextcourse = $context->get_course_context(false)) {
|
||||
// Below course level we look at module or block level roles + course-assigned roles.
|
||||
$courseroles = get_roles_used_in_context($contextcourse, false);
|
||||
$roles = $courseroles + get_roles_used_in_context($context, false);
|
||||
$courseroles = get_roles_with_assignment_on_context($contextcourse);
|
||||
$roles = $courseroles + get_roles_with_assignment_on_context($context);
|
||||
} else {
|
||||
// We list category + system for others (we don't work with user instances so no need to work about them).
|
||||
$roles = get_roles_used_in_context($context);
|
||||
@@ -176,93 +171,55 @@ class data_registry {
|
||||
* @param int|false $forcedvalue Use this value as if this was this context instance value.
|
||||
* @return persistent|false It return a 'purpose' instance or a 'category' instance, depending on $element
|
||||
*/
|
||||
public static function get_effective_context_value(\context $context, $element, $forcedvalue = false) {
|
||||
global $DB;
|
||||
public static function get_effective_context_value(\context $context, $element, $forcedvalue=false) {
|
||||
|
||||
if ($element !== 'purpose' && $element !== 'category') {
|
||||
throw new coding_exception('Only \'purpose\' and \'category\' are supported.');
|
||||
}
|
||||
$fieldname = $element . 'id';
|
||||
|
||||
if (!empty($forcedvalue) && ($forcedvalue == context_instance::INHERIT)) {
|
||||
// Do not include the current context when calculating the value.
|
||||
// This has the effect that an inheritted value is calculated.
|
||||
$parentcontextids = $context->get_parent_context_ids(false);
|
||||
} else if (!empty($forcedvalue) && ($forcedvalue != context_instance::NOTSET)) {
|
||||
return self::get_element_instance($element, $forcedvalue);
|
||||
} else {
|
||||
// Fetch all parent contexts, including self.
|
||||
$parentcontextids = $context->get_parent_context_ids(true);
|
||||
}
|
||||
list($insql, $inparams) = $DB->get_in_or_equal($parentcontextids, SQL_PARAMS_NAMED);
|
||||
$inparams['contextmodule'] = CONTEXT_MODULE;
|
||||
if ($forcedvalue === false) {
|
||||
$instance = context_instance::get_record_by_contextid($context->id, false);
|
||||
|
||||
if ('purpose' === $element) {
|
||||
$elementjoin = 'LEFT JOIN {tool_dataprivacy_purpose} ele ON ctxins.purposeid = ele.id';
|
||||
$elementfields = purpose::get_sql_fields('ele', 'ele');
|
||||
} else {
|
||||
$elementjoin = 'LEFT JOIN {tool_dataprivacy_category} ele ON ctxins.categoryid = ele.id';
|
||||
$elementfields = category::get_sql_fields('ele', 'ele');
|
||||
}
|
||||
$contextfields = \context_helper::get_preload_record_columns_sql('ctx');
|
||||
$fields = implode(', ', ['ctx.id', 'm.name AS modname', $contextfields, $elementfields]);
|
||||
|
||||
$sql = "SELECT $fields
|
||||
FROM {context} ctx
|
||||
LEFT JOIN {tool_dataprivacy_ctxinstance} ctxins ON ctx.id = ctxins.contextid
|
||||
LEFT JOIN {course_modules} cm ON ctx.contextlevel = :contextmodule AND ctx.instanceid = cm.id
|
||||
LEFT JOIN {modules} m ON m.id = cm.module
|
||||
{$elementjoin}
|
||||
WHERE ctx.id {$insql}
|
||||
ORDER BY ctx.path DESC";
|
||||
$contextinstances = $DB->get_records_sql($sql, $inparams);
|
||||
|
||||
// Check whether this context is a user context, or a child of a user context.
|
||||
// All children of a User context share the same context and cannot be set individually.
|
||||
foreach ($contextinstances as $record) {
|
||||
\context_helper::preload_from_record($record);
|
||||
$parent = \context::instance_by_id($record->id, false);
|
||||
|
||||
if ($parent->contextlevel == CONTEXT_USER) {
|
||||
// Use the context level value for the user.
|
||||
return self::get_effective_contextlevel_value(CONTEXT_USER, $element);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($contextinstances as $record) {
|
||||
$parent = \context::instance_by_id($record->id, false);
|
||||
|
||||
$checkcontextlevel = false;
|
||||
if (empty($record->eleid)) {
|
||||
$checkcontextlevel = true;
|
||||
}
|
||||
|
||||
if (!empty($forcedvalue) && context_instance::NOTSET == $forcedvalue) {
|
||||
$checkcontextlevel = true;
|
||||
}
|
||||
|
||||
if ($checkcontextlevel) {
|
||||
// Check for a value at the contextlevel
|
||||
$forplugin = empty($record->modname) ? '' : $record->modname;
|
||||
list($purposeid, $categoryid) = self::get_effective_default_contextlevel_purpose_and_category(
|
||||
$parent->contextlevel, false, false, $forplugin);
|
||||
|
||||
$instancevalue = $$fieldname;
|
||||
|
||||
if (context_instance::NOTSET != $instancevalue && context_instance::INHERIT != $instancevalue) {
|
||||
// There is an actual value. Return it.
|
||||
return self::get_element_instance($element, $instancevalue);
|
||||
}
|
||||
if (!$instance) {
|
||||
// If the instance does not have a value defaults to not set, so we grab the context level default as its value.
|
||||
$instancevalue = context_instance::NOTSET;
|
||||
} else {
|
||||
$elementclass = "\\tool_dataprivacy\\{$element}";
|
||||
$instance = new $elementclass(null, $elementclass::extract_record($record, 'ele'));
|
||||
$instance->validate();
|
||||
$instancevalue = $instance->get($fieldname);
|
||||
}
|
||||
} else {
|
||||
$instancevalue = $forcedvalue;
|
||||
}
|
||||
|
||||
return $instance;
|
||||
// Not set.
|
||||
if ($instancevalue == context_instance::NOTSET) {
|
||||
|
||||
// The effective value varies depending on the context level.
|
||||
if ($context->contextlevel == CONTEXT_USER) {
|
||||
// Use the context level value as we don't allow people to set specific instances values.
|
||||
return self::get_effective_contextlevel_value($context->contextlevel, $element);
|
||||
} else {
|
||||
// Use the default context level value.
|
||||
list($purposeid, $categoryid) = self::get_effective_default_contextlevel_purpose_and_category(
|
||||
$context->contextlevel
|
||||
);
|
||||
return self::get_element_instance($element, $$fieldname);
|
||||
}
|
||||
}
|
||||
|
||||
throw new coding_exception('Something went wrong, system defaults should be set and we should already have a value.');
|
||||
// Specific value for this context instance.
|
||||
if ($instancevalue != context_instance::INHERIT) {
|
||||
return self::get_element_instance($element, $instancevalue);
|
||||
}
|
||||
|
||||
// This context is using inherited so let's return the parent effective value.
|
||||
$parentcontext = $context->get_parent_context();
|
||||
if (!$parentcontext) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// The forced value should not be transmitted to parent contexts.
|
||||
return self::get_effective_context_value($parentcontext, $element);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -274,9 +231,11 @@ class data_registry {
|
||||
*
|
||||
* @param int $contextlevel
|
||||
* @param string $element 'category' or 'purpose'
|
||||
* @param int $forcedvalue Use this value as if this was this context level purpose.
|
||||
* @return \tool_dataprivacy\purpose|false
|
||||
*/
|
||||
public static function get_effective_contextlevel_value($contextlevel, $element) {
|
||||
public static function get_effective_contextlevel_value($contextlevel, $element, $forcedvalue = false) {
|
||||
|
||||
if ($element !== 'purpose' && $element !== 'category') {
|
||||
throw new coding_exception('Only \'purpose\' and \'category\' are supported.');
|
||||
}
|
||||
@@ -287,30 +246,53 @@ class data_registry {
|
||||
'have a purpose or a category.');
|
||||
}
|
||||
|
||||
list($purposeid, $categoryid) = self::get_effective_default_contextlevel_purpose_and_category($contextlevel);
|
||||
if ($forcedvalue === false) {
|
||||
$instance = contextlevel::get_record_by_contextlevel($contextlevel, false);
|
||||
if (!$instance) {
|
||||
// If the context level does not have a value defaults to not set, so we grab the context level default as
|
||||
// its value.
|
||||
$instancevalue = context_instance::NOTSET;
|
||||
} else {
|
||||
$instancevalue = $instance->get($fieldname);
|
||||
}
|
||||
} else {
|
||||
$instancevalue = $forcedvalue;
|
||||
}
|
||||
|
||||
// Note: The $$fieldname points to either $purposeid, or $categoryid.
|
||||
if (context_instance::NOTSET != $$fieldname && context_instance::INHERIT != $$fieldname) {
|
||||
// There is a specific value set.
|
||||
// Not set -> Use the default context level value.
|
||||
if ($instancevalue == context_instance::NOTSET) {
|
||||
list($purposeid, $categoryid) = self::get_effective_default_contextlevel_purpose_and_category($contextlevel);
|
||||
return self::get_element_instance($element, $$fieldname);
|
||||
}
|
||||
|
||||
throw new coding_exception('Something went wrong, system defaults should be set and we should already have a value.');
|
||||
// Specific value for this context instance.
|
||||
if ($instancevalue != context_instance::INHERIT) {
|
||||
return self::get_element_instance($element, $instancevalue);
|
||||
}
|
||||
|
||||
if ($contextlevel == CONTEXT_SYSTEM) {
|
||||
throw new coding_exception('Something went wrong, system defaults should be set and we should already have a value.');
|
||||
}
|
||||
|
||||
// If we reach this point is that we are inheriting so get the parent context level and repeat.
|
||||
$parentcontextlevel = reset(self::$contextlevelinheritance[$contextlevel]);
|
||||
|
||||
// Forced value are intentionally not passed as the force value should only affect the immediate context level.
|
||||
return self::get_effective_contextlevel_value($parentcontextlevel, $element);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the effective default purpose and category for a context level.
|
||||
*
|
||||
* @param int $contextlevel
|
||||
* @param int|bool $forcedpurposevalue Use this value as if this was this context level purpose.
|
||||
* @param int|bool $forcedcategoryvalue Use this value as if this was this context level category.
|
||||
* @param string $component The name of the component to check.
|
||||
* @param int $forcedpurposevalue Use this value as if this was this context level purpose.
|
||||
* @param int $forcedcategoryvalue Use this value as if this was this context level category.
|
||||
* @return int[]
|
||||
*/
|
||||
public static function get_effective_default_contextlevel_purpose_and_category($contextlevel, $forcedpurposevalue = false,
|
||||
$forcedcategoryvalue = false, $component = '') {
|
||||
// Get the defaults for this context level.
|
||||
list($purposeid, $categoryid) = self::get_defaults($contextlevel, $component);
|
||||
$forcedcategoryvalue = false) {
|
||||
|
||||
list($purposeid, $categoryid) = self::get_defaults($contextlevel);
|
||||
|
||||
// Honour forced values.
|
||||
if ($forcedpurposevalue) {
|
||||
@@ -320,19 +302,37 @@ class data_registry {
|
||||
$categoryid = $forcedcategoryvalue;
|
||||
}
|
||||
|
||||
if ($contextlevel == CONTEXT_USER) {
|
||||
// Only user context levels inherit from a parent context level.
|
||||
list($parentpurposeid, $parentcategoryid) = self::get_defaults(CONTEXT_SYSTEM);
|
||||
// Not set == INHERIT for defaults.
|
||||
if ($purposeid == context_instance::INHERIT || $purposeid == context_instance::NOTSET) {
|
||||
$purposeid = false;
|
||||
}
|
||||
if ($categoryid == context_instance::INHERIT || $categoryid == context_instance::NOTSET) {
|
||||
$categoryid = false;
|
||||
}
|
||||
|
||||
if (context_instance::INHERIT == $purposeid || context_instance::NOTSET == $purposeid) {
|
||||
$purposeid = (int)$parentpurposeid;
|
||||
}
|
||||
if ($contextlevel != CONTEXT_SYSTEM && ($purposeid === false || $categoryid === false)) {
|
||||
foreach (self::$contextlevelinheritance[$contextlevel] as $parent) {
|
||||
|
||||
if (context_instance::INHERIT == $categoryid || context_instance::NOTSET == $categoryid) {
|
||||
$categoryid = $parentcategoryid;
|
||||
list($parentpurposeid, $parentcategoryid) = self::get_defaults($parent);
|
||||
// Not set == INHERIT for defaults.
|
||||
if ($parentpurposeid == context_instance::INHERIT || $parentpurposeid == context_instance::NOTSET) {
|
||||
$parentpurposeid = false;
|
||||
}
|
||||
if ($parentcategoryid == context_instance::INHERIT || $parentcategoryid == context_instance::NOTSET) {
|
||||
$parentcategoryid = false;
|
||||
}
|
||||
|
||||
if ($purposeid === false && $parentpurposeid) {
|
||||
$purposeid = $parentpurposeid;
|
||||
}
|
||||
|
||||
if ($categoryid === false && $parentcategoryid) {
|
||||
$categoryid = $parentcategoryid;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// They may still be false, but we return anyway.
|
||||
return [$purposeid, $categoryid];
|
||||
}
|
||||
|
||||
@@ -345,6 +345,7 @@ class data_registry {
|
||||
* @return \core\persistent
|
||||
*/
|
||||
private static function get_element_instance($element, $id) {
|
||||
|
||||
if ($element !== 'purpose' && $element !== 'category') {
|
||||
throw new coding_exception('No other elements than purpose and category are allowed');
|
||||
}
|
||||
|
||||
@@ -21,9 +21,7 @@
|
||||
* @copyright 2018 Jun Pataleta
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core\persistent;
|
||||
@@ -39,12 +37,6 @@ class data_request extends persistent {
|
||||
/** The table name this persistent object maps to. */
|
||||
const TABLE = 'tool_dataprivacy_request';
|
||||
|
||||
/** Data request created manually. */
|
||||
const DATAREQUEST_CREATION_MANUAL = 0;
|
||||
|
||||
/** Data request created automatically. */
|
||||
const DATAREQUEST_CREATION_AUTO = 1;
|
||||
|
||||
/**
|
||||
* Return the definition of the properties of this model.
|
||||
*
|
||||
@@ -83,9 +75,10 @@ class data_request extends persistent {
|
||||
'type' => PARAM_INT
|
||||
],
|
||||
'status' => [
|
||||
'default' => api::DATAREQUEST_STATUS_AWAITING_APPROVAL,
|
||||
'default' => api::DATAREQUEST_STATUS_PENDING,
|
||||
'choices' => [
|
||||
api::DATAREQUEST_STATUS_PENDING,
|
||||
api::DATAREQUEST_STATUS_PREPROCESSING,
|
||||
api::DATAREQUEST_STATUS_AWAITING_APPROVAL,
|
||||
api::DATAREQUEST_STATUS_APPROVED,
|
||||
api::DATAREQUEST_STATUS_PROCESSING,
|
||||
@@ -118,14 +111,6 @@ class data_request extends persistent {
|
||||
'type' => PARAM_INT,
|
||||
'default' => FORMAT_PLAIN
|
||||
],
|
||||
'creationmethod' => [
|
||||
'default' => self::DATAREQUEST_CREATION_MANUAL,
|
||||
'choices' => [
|
||||
self::DATAREQUEST_CREATION_MANUAL,
|
||||
self::DATAREQUEST_CREATION_AUTO
|
||||
],
|
||||
'type' => PARAM_INT
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
@@ -159,6 +144,8 @@ class data_request extends persistent {
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Fetch completed data requests which are due to expire.
|
||||
*
|
||||
@@ -223,73 +210,4 @@ class data_request extends persistent {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this request is in a state appropriate for reset/resubmission.
|
||||
*
|
||||
* Note: This does not check whether any other completed requests exist for this user.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_resettable() : bool {
|
||||
if (api::DATAREQUEST_TYPE_OTHERS == $this->get('type')) {
|
||||
// It is not possible to reset 'other' reqeusts.
|
||||
return false;
|
||||
}
|
||||
|
||||
$resettable = [
|
||||
api::DATAREQUEST_STATUS_APPROVED => true,
|
||||
api::DATAREQUEST_STATUS_REJECTED => true,
|
||||
];
|
||||
|
||||
return isset($resettable[$this->get('status')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this request is 'active'.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_active() : bool {
|
||||
$active = [
|
||||
api::DATAREQUEST_STATUS_APPROVED => true,
|
||||
];
|
||||
|
||||
return isset($active[$this->get('status')]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Reject this request and resubmit it as a fresh request.
|
||||
*
|
||||
* Note: This does not check whether any other completed requests exist for this user.
|
||||
*
|
||||
* @return self
|
||||
*/
|
||||
public function resubmit_request() : data_request {
|
||||
if ($this->is_active()) {
|
||||
$this->set('status', api::DATAREQUEST_STATUS_REJECTED)->save();
|
||||
}
|
||||
|
||||
if (!$this->is_resettable()) {
|
||||
throw new \moodle_exception('cannotreset', 'tool_dataprivacy');
|
||||
}
|
||||
|
||||
$currentdata = $this->to_record();
|
||||
unset($currentdata->id);
|
||||
|
||||
// Clone the original request, but do not notify.
|
||||
$clone = api::create_data_request(
|
||||
$this->get('userid'),
|
||||
$this->get('type'),
|
||||
$this->get('comments'),
|
||||
$this->get('creationmethod'),
|
||||
false
|
||||
);
|
||||
$clone->set('comments', $this->get('comments'));
|
||||
$clone->set('dpo', $this->get('dpo'));
|
||||
$clone->set('requestedby', $this->get('requestedby'));
|
||||
$clone->save();
|
||||
|
||||
return $clone;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Event observers supported by this module.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
|
||||
namespace tool_dataprivacy\event;
|
||||
|
||||
use \tool_dataprivacy\api;
|
||||
use \tool_dataprivacy\data_request;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Event observers supported by this module.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 Mihail Geshoski <mihail@moodle.com>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class user_deleted_observer {
|
||||
|
||||
/**
|
||||
* Create user data deletion request when the user is deleted.
|
||||
*
|
||||
* @param \core\event\user_deleted $event
|
||||
*/
|
||||
public static function create_delete_data_request(\core\event\user_deleted $event) {
|
||||
// Automatic creation of deletion requests must be enabled.
|
||||
if (get_config('tool_dataprivacy', 'automaticdeletionrequests')) {
|
||||
$requesttypes = [api::DATAREQUEST_TYPE_DELETE];
|
||||
$requeststatuses = [api::DATAREQUEST_STATUS_COMPLETE, api::DATAREQUEST_STATUS_DELETED];
|
||||
|
||||
$hasongoingdeleterequests = api::has_ongoing_request($event->objectid, $requesttypes[0]);
|
||||
$hascompleteddeleterequest = (api::get_data_requests_count($event->objectid, $requeststatuses,
|
||||
$requesttypes) > 0) ? true : false;
|
||||
|
||||
if (!$hasongoingdeleterequests && !$hascompleteddeleterequest) {
|
||||
api::create_data_request($event->objectid, $requesttypes[0],
|
||||
get_string('datarequestcreatedupondelete', 'tool_dataprivacy'),
|
||||
data_request::DATAREQUEST_CREATION_AUTO);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,27 +60,12 @@ class expired_context extends \core\persistent {
|
||||
* @return array
|
||||
*/
|
||||
protected static function define_properties() {
|
||||
return [
|
||||
'contextid' => [
|
||||
return array(
|
||||
'contextid' => array(
|
||||
'type' => PARAM_INT,
|
||||
'description' => 'The context id.',
|
||||
],
|
||||
'defaultexpired' => [
|
||||
'type' => PARAM_INT,
|
||||
'description' => 'Whether to default retention period for the purpose has been reached',
|
||||
'default' => 1,
|
||||
],
|
||||
'expiredroles' => [
|
||||
'type' => PARAM_TEXT,
|
||||
'description' => 'This list of roles to include during deletion',
|
||||
'default' => '',
|
||||
],
|
||||
'unexpiredroles' => [
|
||||
'type' => PARAM_TEXT,
|
||||
'description' => 'This list of roles to exclude during deletion',
|
||||
'default' => '',
|
||||
],
|
||||
'status' => [
|
||||
),
|
||||
'status' => array(
|
||||
'choices' => [
|
||||
self::STATUS_EXPIRED,
|
||||
self::STATUS_APPROVED,
|
||||
@@ -88,8 +73,8 @@ class expired_context extends \core\persistent {
|
||||
],
|
||||
'type' => PARAM_INT,
|
||||
'description' => 'The deletion status of the context.',
|
||||
],
|
||||
];
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -174,205 +159,4 @@ class expired_context extends \core\persistent {
|
||||
|
||||
return $DB->count_records_sql($sql, $params);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of role IDs for either expiredroles, or unexpiredroles.
|
||||
*
|
||||
* @param string $field
|
||||
* @param int[] $roleids
|
||||
* @return expired_context
|
||||
*/
|
||||
protected function set_roleids_for(string $field, array $roleids) : expired_context {
|
||||
$roledata = json_encode($roleids);
|
||||
|
||||
$this->raw_set($field, $roledata);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of role IDs for either expiredroles, or unexpiredroles.
|
||||
*
|
||||
* @param string $field
|
||||
* @return int[]
|
||||
*/
|
||||
protected function get_roleids_for(string $field) {
|
||||
$value = $this->raw_get($field);
|
||||
if (empty($value)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return json_decode($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of unexpired role IDs.
|
||||
*
|
||||
* @param int[] $roleids
|
||||
* @return expired_context
|
||||
*/
|
||||
protected function set_unexpiredroles(array $roleids) : expired_context {
|
||||
$this->set_roleids_for('unexpiredroles', $roleids);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a set of role IDs to the list of expired role IDs.
|
||||
*
|
||||
* @param int[] $roleids
|
||||
* @return expired_context
|
||||
*/
|
||||
public function add_expiredroles(array $roleids) : expired_context {
|
||||
$existing = $this->get('expiredroles');
|
||||
$newvalue = array_merge($existing, $roleids);
|
||||
|
||||
$this->set('expiredroles', $newvalue);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a set of role IDs to the list of unexpired role IDs.
|
||||
*
|
||||
* @param int[] $roleids
|
||||
* @return unexpired_context
|
||||
*/
|
||||
public function add_unexpiredroles(array $roleids) : expired_context {
|
||||
$existing = $this->get('unexpiredroles');
|
||||
$newvalue = array_merge($existing, $roleids);
|
||||
|
||||
$this->set('unexpiredroles', $newvalue);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the list of expired role IDs.
|
||||
*
|
||||
* @param int[] $roleids
|
||||
* @return expired_context
|
||||
*/
|
||||
protected function set_expiredroles(array $roleids) : expired_context {
|
||||
$this->set_roleids_for('expiredroles', $roleids);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of expired role IDs.
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
protected function get_expiredroles() {
|
||||
return $this->get_roleids_for('expiredroles');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of unexpired role IDs.
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
protected function get_unexpiredroles() {
|
||||
return $this->get_roleids_for('unexpiredroles');
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new expired_context based on the context, and expiry_info object.
|
||||
*
|
||||
* @param \context $context
|
||||
* @param expiry_info $info
|
||||
* @param boolean $save
|
||||
* @return expired_context
|
||||
*/
|
||||
public static function create_from_expiry_info(\context $context, expiry_info $info, bool $save = true) : expired_context {
|
||||
$record = (object) [
|
||||
'contextid' => $context->id,
|
||||
'status' => self::STATUS_EXPIRED,
|
||||
'defaultexpired' => (int) $info->is_default_expired(),
|
||||
];
|
||||
|
||||
$expiredcontext = new static(0, $record);
|
||||
$expiredcontext->set('expiredroles', $info->get_expired_roles());
|
||||
$expiredcontext->set('unexpiredroles', $info->get_unexpired_roles());
|
||||
|
||||
if ($save) {
|
||||
$expiredcontext->save();
|
||||
}
|
||||
|
||||
return $expiredcontext;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the expired_context from an expiry_info object which relates to this context.
|
||||
*
|
||||
* @param expiry_info $info
|
||||
* @return $this
|
||||
*/
|
||||
public function update_from_expiry_info(expiry_info $info) : expired_context {
|
||||
$save = false;
|
||||
|
||||
// Compare the expiredroles.
|
||||
$thisexpired = $this->get('expiredroles');
|
||||
$infoexpired = $info->get_expired_roles();
|
||||
|
||||
sort($thisexpired);
|
||||
sort($infoexpired);
|
||||
if ($infoexpired != $thisexpired) {
|
||||
$this->set('expiredroles', $infoexpired);
|
||||
$save = true;
|
||||
}
|
||||
|
||||
// Compare the unexpiredroles.
|
||||
$thisunexpired = $this->get('unexpiredroles');
|
||||
$infounexpired = $info->get_unexpired_roles();
|
||||
|
||||
sort($thisunexpired);
|
||||
sort($infounexpired);
|
||||
if ($infounexpired != $thisunexpired) {
|
||||
$this->set('unexpiredroles', $infounexpired);
|
||||
$save = true;
|
||||
}
|
||||
|
||||
if (empty($this->get('defaultexpired')) == $info->is_default_expired()) {
|
||||
$this->set('defaultexpired', (int) $info->is_default_expired());
|
||||
$save = true;
|
||||
}
|
||||
|
||||
if ($save) {
|
||||
$this->set('status', self::STATUS_EXPIRED);
|
||||
$this->save();
|
||||
}
|
||||
|
||||
return $this;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this expired_context record is in a state ready for deletion to actually take place.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function can_process_deletion() : bool {
|
||||
return ($this->get('status') == self::STATUS_APPROVED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether this expired_context record has already been cleaned.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_complete() : bool {
|
||||
return ($this->get('status') == self::STATUS_CLEANED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this context has 'fully' expired.
|
||||
* That is to say that the default retention period has been reached, and that there are no unexpired roles.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_fully_expired() : bool {
|
||||
return $this->get('defaultexpired') && empty($this->get('unexpiredroles'));
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Expired contexts manager for CONTEXT_COURSE, CONTEXT_MODULE and CONTEXT_BLOCK.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 David Monllao
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
use tool_dataprivacy\purpose;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Expired contexts manager for CONTEXT_COURSE, CONTEXT_MODULE and CONTEXT_BLOCK.
|
||||
*
|
||||
* @copyright 2018 David Monllao
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class expired_course_related_contexts extends \tool_dataprivacy\expired_contexts_manager {
|
||||
|
||||
/**
|
||||
* Course-related context levels.
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
protected function get_context_levels() {
|
||||
return [CONTEXT_MODULE, CONTEXT_BLOCK, CONTEXT_COURSE];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a recordset with user context instances that are possibly expired (to be confirmed by get_recordset_callback).
|
||||
*
|
||||
* @return \stdClass[]
|
||||
*/
|
||||
protected function get_expired_contexts() {
|
||||
global $DB;
|
||||
|
||||
// Including context info + course end date + purposeid (this last one only if defined).
|
||||
$fields = 'ctx.id AS id, ctxcourse.enddate AS courseenddate, dpctx.purposeid AS purposeid, ' .
|
||||
\context_helper::get_preload_record_columns_sql('ctx');
|
||||
|
||||
// We want all contexts at course-dependant levels.
|
||||
$parentpath = $DB->sql_concat('ctxcourse.path', "'/%'");
|
||||
|
||||
// This SQL query returns all course-dependant contexts (including the course context)
|
||||
// which course end date already passed.
|
||||
$sql = "SELECT $fields
|
||||
FROM {context} ctx
|
||||
JOIN (
|
||||
SELECT c.enddate, subctx.path
|
||||
FROM {context} subctx
|
||||
JOIN {course} c
|
||||
ON subctx.contextlevel = ? AND subctx.instanceid = c.id
|
||||
WHERE c.enddate < ? AND c.enddate > 0
|
||||
) ctxcourse
|
||||
ON ctx.path LIKE {$parentpath} OR ctx.path = ctxcourse.path
|
||||
LEFT JOIN {tool_dataprivacy_ctxinstance} dpctx
|
||||
ON dpctx.contextid = ctx.id
|
||||
LEFT JOIN {tool_dataprivacy_ctxexpired} expiredctx
|
||||
ON ctx.id = expiredctx.contextid
|
||||
WHERE expiredctx.id IS NULL
|
||||
ORDER BY ctx.contextlevel DESC, ctx.path";
|
||||
$possiblyexpired = $DB->get_recordset_sql($sql, [CONTEXT_COURSE, time()]);
|
||||
|
||||
$expiredcontexts = [];
|
||||
$excludedcontextids = [];
|
||||
foreach ($possiblyexpired as $record) {
|
||||
|
||||
\context_helper::preload_from_record($record);
|
||||
|
||||
// No strict checking as the context may already be deleted (e.g. we just deleted a course,
|
||||
// module contexts below it will not exist).
|
||||
$context = \context::instance_by_id($record->id, false);
|
||||
if (!$context) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// We pass the value we just got from SQL so get_effective_context_purpose don't need to query
|
||||
// the db again to retrieve it. If there is no tool_dataprovider_ctxinstance record
|
||||
// $record->purposeid will be null which is ok as it would force get_effective_context_purpose
|
||||
// to return the default purpose for the context context level (no db queries involved).
|
||||
$purposevalue = $record->purposeid !== null ? $record->purposeid : context_instance::NOTSET;
|
||||
|
||||
// It should be cheap as system purposes and context level purposes will be retrieved from a cache most of the time.
|
||||
$purpose = api::get_effective_context_purpose($context, $purposevalue);
|
||||
|
||||
$dt = new \DateTime();
|
||||
$dt->setTimestamp($record->courseenddate);
|
||||
$di = new \DateInterval($purpose->get('retentionperiod'));
|
||||
$dt->add($di);
|
||||
|
||||
if (time() < $dt->getTimestamp()) {
|
||||
// Exclude this context ID as it has not reached the retention period yet.
|
||||
$excludedcontextids[] = $context->id;
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if this context has children that have not yet expired.
|
||||
$hasunexpiredchildren = false;
|
||||
$children = $context->get_child_contexts();
|
||||
foreach ($children as $child) {
|
||||
if (in_array($child->id, $excludedcontextids)) {
|
||||
$hasunexpiredchildren = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($hasunexpiredchildren) {
|
||||
// Exclude this context ID as it has children that have not yet expired.
|
||||
$excludedcontextids[] = $context->id;
|
||||
continue;
|
||||
}
|
||||
|
||||
$expiredcontexts[$context->id] = $context;
|
||||
}
|
||||
|
||||
return $expiredcontexts;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,150 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Expired contexts manager for CONTEXT_USER.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 David Monllao
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
use core_privacy\manager;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Expired contexts manager for CONTEXT_USER.
|
||||
*
|
||||
* @copyright 2018 David Monllao
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class expired_user_contexts extends \tool_dataprivacy\expired_contexts_manager {
|
||||
|
||||
/**
|
||||
* Only user level.
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
protected function get_context_levels() {
|
||||
return [CONTEXT_USER];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the user context instances that are expired.
|
||||
*
|
||||
* @return \stdClass[]
|
||||
*/
|
||||
protected function get_expired_contexts() {
|
||||
global $DB;
|
||||
|
||||
// Including context info + last login timestamp.
|
||||
$fields = 'ctx.id AS id, ' . \context_helper::get_preload_record_columns_sql('ctx');
|
||||
|
||||
$purpose = api::get_effective_contextlevel_purpose(CONTEXT_USER);
|
||||
|
||||
// Calculate what is considered expired according to the context level effective purpose (= now + retention period).
|
||||
$expiredtime = new \DateTime();
|
||||
$retention = new \DateInterval($purpose->get('retentionperiod'));
|
||||
$expiredtime->sub($retention);
|
||||
|
||||
$sql = "SELECT $fields FROM {context} ctx
|
||||
JOIN {user} u ON ctx.contextlevel = ? AND ctx.instanceid = u.id
|
||||
LEFT JOIN {tool_dataprivacy_ctxexpired} expiredctx ON ctx.id = expiredctx.contextid
|
||||
WHERE u.lastaccess <= ? AND u.lastaccess > 0 AND expiredctx.id IS NULL
|
||||
ORDER BY ctx.path, ctx.contextlevel ASC";
|
||||
$possiblyexpired = $DB->get_recordset_sql($sql, [CONTEXT_USER, $expiredtime->getTimestamp()]);
|
||||
|
||||
$expiredcontexts = [];
|
||||
foreach ($possiblyexpired as $record) {
|
||||
|
||||
\context_helper::preload_from_record($record);
|
||||
|
||||
// No strict checking as the context may already be deleted (e.g. we just deleted a course,
|
||||
// module contexts below it will not exist).
|
||||
$context = \context::instance_by_id($record->id, false);
|
||||
if (!$context) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_siteadmin($context->instanceid)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$courses = enrol_get_users_courses($context->instanceid, false, ['enddate']);
|
||||
foreach ($courses as $course) {
|
||||
if (!$course->enddate) {
|
||||
// We can not know it what is going on here, so we prefer to be conservative.
|
||||
continue 2;
|
||||
}
|
||||
|
||||
if ($course->enddate >= time()) {
|
||||
// Future or ongoing course.
|
||||
continue 2;
|
||||
}
|
||||
}
|
||||
|
||||
$expiredcontexts[$context->id] = $context;
|
||||
}
|
||||
|
||||
return $expiredcontexts;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes user data from the provided context.
|
||||
*
|
||||
* Overwritten to delete the user.
|
||||
*
|
||||
* @param manager $privacymanager
|
||||
* @param expired_context $expiredctx
|
||||
* @return \context|false
|
||||
*/
|
||||
protected function delete_expired_context(manager $privacymanager, expired_context $expiredctx) {
|
||||
$context = \context::instance_by_id($expiredctx->get('contextid'), IGNORE_MISSING);
|
||||
if (!$context) {
|
||||
api::delete_expired_context($expiredctx->get('contextid'));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!PHPUNIT_TEST) {
|
||||
mtrace('Deleting context ' . $context->id . ' - ' .
|
||||
shorten_text($context->get_context_name(true, true)));
|
||||
}
|
||||
|
||||
// To ensure that all user data is deleted, instead of deleting by context, we run through and collect any stray
|
||||
// contexts for the user that may still exist and call delete_data_for_user().
|
||||
$user = \core_user::get_user($context->instanceid, '*', MUST_EXIST);
|
||||
$approvedlistcollection = new \core_privacy\local\request\contextlist_collection($user->id);
|
||||
$contextlistcollection = $privacymanager->get_contexts_for_userid($user->id);
|
||||
|
||||
foreach ($contextlistcollection as $contextlist) {
|
||||
$approvedlistcollection->add_contextlist(new \core_privacy\local\request\approved_contextlist(
|
||||
$user,
|
||||
$contextlist->get_component(),
|
||||
$contextlist->get_contextids()
|
||||
));
|
||||
}
|
||||
|
||||
$privacymanager->delete_data_for_user($approvedlistcollection);
|
||||
api::set_expired_context_status($expiredctx, expired_context::STATUS_CLEANED);
|
||||
|
||||
// Delete the user.
|
||||
delete_user($user);
|
||||
|
||||
return $context;
|
||||
}
|
||||
}
|
||||
@@ -1,207 +0,0 @@
|
||||
<?php
|
||||
// This file is part of Moodle - http://moodle.org/
|
||||
//
|
||||
// Moodle is free software: you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License as published by
|
||||
// the Free Software Foundation, either version 3 of the License, or
|
||||
// (at your option) any later version.
|
||||
//
|
||||
// Moodle is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
/**
|
||||
* Expiry Data.
|
||||
*
|
||||
* @package tool_dataprivacy
|
||||
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
namespace tool_dataprivacy;
|
||||
|
||||
use core_privacy\manager;
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/**
|
||||
* Expiry Data.
|
||||
*
|
||||
* @copyright 2018 Andrew Nicols <andrew@nicols.co.uk>
|
||||
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
||||
*/
|
||||
class expiry_info {
|
||||
|
||||
/** @var bool Whether this context is fully expired */
|
||||
protected $fullyexpired = false;
|
||||
|
||||
/** @var bool Whether the default expiry value of this purpose has been reached */
|
||||
protected $defaultexpiryreached = false;
|
||||
|
||||
/** @var bool Whether the default purpose is protected */
|
||||
protected $defaultprotected = false;
|
||||
|
||||
/** @var int[] List of expires roles */
|
||||
protected $expired = [];
|
||||
|
||||
/** @var int[] List of unexpires roles */
|
||||
protected $unexpired = [];
|
||||
|
||||
/** @var int[] List of unexpired roles which are also protected */
|
||||
protected $protectedroles = [];
|
||||
|
||||
/**
|
||||
* Constructor for the expiry_info class.
|
||||
*
|
||||
* @param bool $default Whether the default expiry period for this context has been reached.
|
||||
* @param bool $defaultprotected Whether the default expiry is protected.
|
||||
* @param int[] $expired A list of roles in this context which have explicitly expired.
|
||||
* @param int[] $unexpired A list of roles in this context which have not yet expired.
|
||||
* @param int[] $protectedroles A list of unexpired roles in this context which are protected.
|
||||
*/
|
||||
public function __construct(bool $default, bool $defaultprotected, array $expired, array $unexpired, array $protectedroles) {
|
||||
$this->defaultexpiryreached = $default;
|
||||
$this->defaultprotected = $defaultprotected;
|
||||
$this->expired = $expired;
|
||||
$this->unexpired = $unexpired;
|
||||
$this->protectedroles = $protectedroles;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether this context has 'fully' expired.
|
||||
* That is to say that the default retention period has been reached, and that there are no unexpired roles.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_fully_expired() : bool {
|
||||
return $this->defaultexpiryreached && empty($this->unexpired);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether any part of this context has expired.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_any_expired() : bool {
|
||||
if ($this->is_fully_expired()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!empty($this->get_expired_roles())) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->is_default_expired()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of explicitly expired role IDs.
|
||||
* Note: This does not list roles which have been expired via the default retention policy being reached.
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
public function get_expired_roles() : array {
|
||||
if ($this->is_default_expired()) {
|
||||
return [];
|
||||
}
|
||||
return $this->expired;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether the specified role is explicitly expired.
|
||||
* Note: This does not list roles which have been expired via the default retention policy being reached.
|
||||
*
|
||||
* @param int $roleid
|
||||
* @return bool
|
||||
*/
|
||||
public function is_role_expired(int $roleid) : bool {
|
||||
return false !== array_search($roleid, $this->expired);
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the default retention policy has been reached.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_default_expired() : bool {
|
||||
return $this->defaultexpiryreached;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether the default purpose is protected.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function is_default_protected() : bool {
|
||||
return $this->defaultprotected;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of unexpired role IDs.
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
public function get_unexpired_roles() : array {
|
||||
return $this->unexpired;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the list of unexpired protected roles.
|
||||
*
|
||||
* @return int[]
|
||||
*/
|
||||
public function get_unexpired_protected_roles() : array {
|
||||
return array_keys(array_filter($this->protectedroles));
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of all overridden roles which are unprotected.
|
||||
* @return int[]
|
||||
*/
|
||||
public function get_unprotected_overridden_roles() : array {
|
||||
$allroles = array_merge($this->expired, $this->unexpired);
|
||||
|
||||
return array_diff($allroles, $this->protectedroles);
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge this expiry_info object with another belonging to a child context in order to set the 'safest' heritage.
|
||||
*
|
||||
* It is not possible to delete any part of a context that is not deleted by a parent.
|
||||
* So if a course's retention policy has been reached, then only parts where the children have also expired can be
|
||||
* deleted.
|
||||
*
|
||||
* @param expiry_info $child The child record to merge with.
|
||||
* @return $this
|
||||
*/
|
||||
public function merge_with_child(expiry_info $child) : expiry_info {
|
||||
if ($child->is_fully_expired()) {
|
||||
return $this;
|
||||
}
|
||||
|
||||
// If the child is not fully expired, then none of the parents can be either.
|
||||
$this->fullyexpired = false;
|
||||
|
||||
// Remove any role in this node which is not expired in the child.
|
||||
foreach ($this->expired as $key => $roleid) {
|
||||
if (!$child->is_role_expired($roleid)) {
|
||||
unset($this->expired[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
array_merge($this->unexpired, $child->get_unexpired_roles());
|
||||
|
||||
if (!$child->is_default_expired()) {
|
||||
$this->defaultexpiryreached = false;
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
@@ -92,30 +92,17 @@ class external extends external_api {
|
||||
]);
|
||||
$requestid = $params['requestid'];
|
||||
|
||||
// Validate context and access to manage the registry.
|
||||
// Validate context.
|
||||
$context = context_user::instance($USER->id);
|
||||
self::validate_context($context);
|
||||
|
||||
// Ensure the request exists.
|
||||
$select = 'id = :id AND (userid = :userid OR requestedby = :requestedby)';
|
||||
$params = ['id' => $requestid, 'userid' => $USER->id, 'requestedby' => $USER->id];
|
||||
$requests = data_request::get_records_select($select, $params);
|
||||
$requestexists = count($requests) === 1;
|
||||
$requestexists = data_request::record_exists_select($select, $params);
|
||||
|
||||
$result = false;
|
||||
if ($requestexists) {
|
||||
$request = reset($requests);
|
||||
$datasubject = $request->get('userid');
|
||||
|
||||
if ($datasubject !== $USER->id) {
|
||||
// The user is not the subject. Check that they can cancel this request.
|
||||
if (!api::can_create_data_request_for_user($datasubject)) {
|
||||
$forusercontext = \context_user::instance($datasubject);
|
||||
throw new required_capability_exception($forusercontext,
|
||||
'tool/dataprivacy:makedatarequestsforchildren', 'nopermissions', '');
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Do we want a request to be non-cancellable past a certain point? E.g. When it's already approved/processing.
|
||||
$result = api::update_request_status($requestid, api::DATAREQUEST_STATUS_CANCELLED);
|
||||
} else {
|
||||
@@ -270,10 +257,9 @@ class external extends external_api {
|
||||
]);
|
||||
$requestid = $params['requestid'];
|
||||
|
||||
// Validate context and access to manage the registry.
|
||||
// Validate context.
|
||||
$context = context_system::instance();
|
||||
self::validate_context($context);
|
||||
api::check_can_manage_data_registry();
|
||||
|
||||
$message = get_string('markedcomplete', 'tool_dataprivacy');
|
||||
// Update the data request record.
|
||||
@@ -435,85 +421,6 @@ class external extends external_api {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameter description for bulk_approve_data_requests().
|
||||
*
|
||||
* @since Moodle 3.5
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function bulk_approve_data_requests_parameters() {
|
||||
return new external_function_parameters([
|
||||
'requestids' => new external_multiple_structure(
|
||||
new external_value(PARAM_INT, 'The request ID', VALUE_REQUIRED)
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk approve bulk data request.
|
||||
*
|
||||
* @since Moodle 3.5
|
||||
* @param array $requestids Array consisting the request ID's.
|
||||
* @return array
|
||||
* @throws coding_exception
|
||||
* @throws dml_exception
|
||||
* @throws invalid_parameter_exception
|
||||
* @throws restricted_context_exception
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
public static function bulk_approve_data_requests($requestids) {
|
||||
$warnings = [];
|
||||
$result = false;
|
||||
$params = external_api::validate_parameters(self::bulk_approve_data_requests_parameters(), [
|
||||
'requestids' => $requestids
|
||||
]);
|
||||
$requestids = $params['requestids'];
|
||||
|
||||
// Validate context.
|
||||
$context = context_system::instance();
|
||||
self::validate_context($context);
|
||||
require_capability('tool/dataprivacy:managedatarequests', $context);
|
||||
|
||||
foreach ($requestids as $requestid) {
|
||||
// Ensure the request exists.
|
||||
$requestexists = data_request::record_exists($requestid);
|
||||
|
||||
if ($requestexists) {
|
||||
api::approve_data_request($requestid);
|
||||
} else {
|
||||
$warnings[] = [
|
||||
'item' => $requestid,
|
||||
'warningcode' => 'errorrequestnotfound',
|
||||
'message' => get_string('errorrequestnotfound', 'tool_dataprivacy')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($warnings)) {
|
||||
$result = true;
|
||||
// Add notification in the session to be shown when the page is reloaded on the JS side.
|
||||
notification::success(get_string('requestsapproved', 'tool_dataprivacy'));
|
||||
}
|
||||
|
||||
return [
|
||||
'result' => $result,
|
||||
'warnings' => $warnings
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameter description for bulk_approve_data_requests().
|
||||
*
|
||||
* @since Moodle 3.5
|
||||
* @return external_description
|
||||
*/
|
||||
public static function bulk_approve_data_requests_returns() {
|
||||
return new external_single_structure([
|
||||
'result' => new external_value(PARAM_BOOL, 'The processing result'),
|
||||
'warnings' => new external_warnings()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameter description for deny_data_request().
|
||||
*
|
||||
@@ -586,85 +493,6 @@ class external extends external_api {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameter description for bulk_deny_data_requests().
|
||||
*
|
||||
* @since Moodle 3.5
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function bulk_deny_data_requests_parameters() {
|
||||
return new external_function_parameters([
|
||||
'requestids' => new external_multiple_structure(
|
||||
new external_value(PARAM_INT, 'The request ID', VALUE_REQUIRED)
|
||||
)
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Bulk deny data requests.
|
||||
*
|
||||
* @since Moodle 3.5
|
||||
* @param array $requestids Array consisting of request ID's.
|
||||
* @return array
|
||||
* @throws coding_exception
|
||||
* @throws dml_exception
|
||||
* @throws invalid_parameter_exception
|
||||
* @throws restricted_context_exception
|
||||
* @throws moodle_exception
|
||||
*/
|
||||
public static function bulk_deny_data_requests($requestids) {
|
||||
$warnings = [];
|
||||
$result = false;
|
||||
$params = external_api::validate_parameters(self::bulk_deny_data_requests_parameters(), [
|
||||
'requestids' => $requestids
|
||||
]);
|
||||
$requestids = $params['requestids'];
|
||||
|
||||
// Validate context.
|
||||
$context = context_system::instance();
|
||||
self::validate_context($context);
|
||||
require_capability('tool/dataprivacy:managedatarequests', $context);
|
||||
|
||||
foreach ($requestids as $requestid) {
|
||||
// Ensure the request exists.
|
||||
$requestexists = data_request::record_exists($requestid);
|
||||
|
||||
if ($requestexists) {
|
||||
api::deny_data_request($requestid);
|
||||
} else {
|
||||
$warnings[] = [
|
||||
'item' => $requestid,
|
||||
'warningcode' => 'errorrequestnotfound',
|
||||
'message' => get_string('errorrequestnotfound', 'tool_dataprivacy')
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($warnings)) {
|
||||
$result = true;
|
||||
// Add notification in the session to be shown when the page is reloaded on the JS side.
|
||||
notification::success(get_string('requestsdenied', 'tool_dataprivacy'));
|
||||
}
|
||||
|
||||
return [
|
||||
'result' => $result,
|
||||
'warnings' => $warnings
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameter description for bulk_deny_data_requests().
|
||||
*
|
||||
* @since Moodle 3.5
|
||||
* @return external_description
|
||||
*/
|
||||
public static function bulk_deny_data_requests_returns() {
|
||||
return new external_single_structure([
|
||||
'result' => new external_value(PARAM_BOOL, 'The processing result'),
|
||||
'warnings' => new external_warnings()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameter description for get_data_request().
|
||||
*
|
||||
@@ -762,9 +590,7 @@ class external extends external_api {
|
||||
'jsonformdata' => $jsonformdata
|
||||
]);
|
||||
|
||||
// Validate context and access to manage the registry.
|
||||
self::validate_context(\context_system::instance());
|
||||
api::check_can_manage_data_registry();
|
||||
|
||||
$serialiseddata = json_decode($params['jsonformdata']);
|
||||
$data = array();
|
||||
@@ -832,10 +658,6 @@ class external extends external_api {
|
||||
'id' => $id
|
||||
]);
|
||||
|
||||
// Validate context and access to manage the registry.
|
||||
self::validate_context(\context_system::instance());
|
||||
api::check_can_manage_data_registry();
|
||||
|
||||
$result = api::delete_purpose($params['id']);
|
||||
|
||||
return [
|
||||
@@ -885,9 +707,7 @@ class external extends external_api {
|
||||
'jsonformdata' => $jsonformdata
|
||||
]);
|
||||
|
||||
// Validate context and access to manage the registry.
|
||||
self::validate_context(\context_system::instance());
|
||||
api::check_can_manage_data_registry();
|
||||
|
||||
$serialiseddata = json_decode($params['jsonformdata']);
|
||||
$data = array();
|
||||
@@ -955,10 +775,6 @@ class external extends external_api {
|
||||
'id' => $id
|
||||
]);
|
||||
|
||||
// Validate context and access to manage the registry.
|
||||
self::validate_context(\context_system::instance());
|
||||
api::check_can_manage_data_registry();
|
||||
|
||||
$result = api::delete_category($params['id']);
|
||||
|
||||
return [
|
||||
@@ -1008,9 +824,8 @@ class external extends external_api {
|
||||
'jsonformdata' => $jsonformdata
|
||||
]);
|
||||
|
||||
// Validate context and access to manage the registry.
|
||||
// Extra permission checkings are delegated to api::set_contextlevel.
|
||||
self::validate_context(\context_system::instance());
|
||||
api::check_can_manage_data_registry();
|
||||
|
||||
$serialiseddata = json_decode($params['jsonformdata']);
|
||||
$data = array();
|
||||
@@ -1024,6 +839,7 @@ class external extends external_api {
|
||||
$contextlevel = api::set_contextlevel($validateddata);
|
||||
} else if ($errors = $mform->is_validated()) {
|
||||
$warnings[] = json_encode($errors);
|
||||
throw new moodle_exception('generalerror');
|
||||
}
|
||||
|
||||
if ($contextlevel) {
|
||||
@@ -1078,9 +894,8 @@ class external extends external_api {
|
||||
'jsonformdata' => $jsonformdata
|
||||
]);
|
||||
|
||||
// Validate context and access to manage the registry.
|
||||
// Extra permission checkings are delegated to api::set_context_instance.
|
||||
self::validate_context(\context_system::instance());
|
||||
api::check_can_manage_data_registry();
|
||||
|
||||
$serialiseddata = json_decode($params['jsonformdata']);
|
||||
$data = array();
|
||||
@@ -1090,7 +905,6 @@ class external extends external_api {
|
||||
$customdata = \tool_dataprivacy\form\context_instance::get_context_instance_customdata($context);
|
||||
$mform = new \tool_dataprivacy\form\context_instance(null, $customdata, 'post', '', null, true, $data);
|
||||
if ($validateddata = $mform->get_data()) {
|
||||
api::check_can_manage_data_registry($validateddata->contextid);
|
||||
$context = api::set_context_instance($validateddata);
|
||||
} else if ($errors = $mform->is_validated()) {
|
||||
$warnings[] = json_encode($errors);
|
||||
@@ -1220,9 +1034,9 @@ class external extends external_api {
|
||||
]);
|
||||
$ids = $params['ids'];
|
||||
|
||||
// Validate context and access to manage the registry.
|
||||
self::validate_context(\context_system::instance());
|
||||
api::check_can_manage_data_registry();
|
||||
// Validate context.
|
||||
$context = context_system::instance();
|
||||
self::validate_context($context);
|
||||
|
||||
$result = true;
|
||||
if (!empty($ids)) {
|
||||
@@ -1232,27 +1046,24 @@ class external extends external_api {
|
||||
$expiredcontext = new expired_context($id);
|
||||
$targetcontext = context_helper::instance_by_id($expiredcontext->get('contextid'));
|
||||
|
||||
if (!$targetcontext instanceof \context_user) {
|
||||
// Fetch this context's child contexts. Make sure that all of the child contexts are flagged for deletion.
|
||||
// User context children do not need to be considered.
|
||||
$childcontexts = $targetcontext->get_child_contexts();
|
||||
foreach ($childcontexts as $child) {
|
||||
if ($expiredchildcontext = expired_context::get_record(['contextid' => $child->id])) {
|
||||
// Add this child context to the list for approval.
|
||||
$expiredcontextstoapprove[] = $expiredchildcontext;
|
||||
} else {
|
||||
// This context has not yet been flagged for deletion.
|
||||
$result = false;
|
||||
$message = get_string('errorcontexthasunexpiredchildren', 'tool_dataprivacy',
|
||||
$targetcontext->get_context_name(false));
|
||||
$warnings[] = [
|
||||
'item' => 'tool_dataprivacy_ctxexpired',
|
||||
'warningcode' => 'errorcontexthasunexpiredchildren',
|
||||
'message' => $message
|
||||
];
|
||||
// Exit the process.
|
||||
break 2;
|
||||
}
|
||||
// Fetch this context's child contexts. Make sure that all of the child contexts are flagged for deletion.
|
||||
$childcontexts = $targetcontext->get_child_contexts();
|
||||
foreach ($childcontexts as $child) {
|
||||
if ($expiredchildcontext = expired_context::get_record(['contextid' => $child->id])) {
|
||||
// Add this child context to the list for approval.
|
||||
$expiredcontextstoapprove[] = $expiredchildcontext;
|
||||
} else {
|
||||
// This context has not yet been flagged for deletion.
|
||||
$result = false;
|
||||
$message = get_string('errorcontexthasunexpiredchildren', 'tool_dataprivacy',
|
||||
$targetcontext->get_context_name(false));
|
||||
$warnings[] = [
|
||||
'item' => 'tool_dataprivacy_ctxexpired',
|
||||
'warningcode' => 'errorcontexthasunexpiredchildren',
|
||||
'message' => $message
|
||||
];
|
||||
// Exit the process.
|
||||
break 2;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1299,289 +1110,6 @@ class external extends external_api {
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters for set_context_defaults().
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function set_context_defaults_parameters() {
|
||||
return new external_function_parameters([
|
||||
'contextlevel' => new external_value(PARAM_INT, 'The context level', VALUE_REQUIRED),
|
||||
'category' => new external_value(PARAM_INT, 'The default category for the given context level', VALUE_REQUIRED),
|
||||
'purpose' => new external_value(PARAM_INT, 'The default purpose for the given context level', VALUE_REQUIRED),
|
||||
'activity' => new external_value(PARAM_PLUGIN, 'The plugin name of the activity', VALUE_DEFAULT, null),
|
||||
'override' => new external_value(PARAM_BOOL, 'Whether to override existing instances with the defaults', VALUE_DEFAULT,
|
||||
false),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the default category and purpose for a given context level (and optionally, a plugin).
|
||||
*
|
||||
* @param int $contextlevel The context level.
|
||||
* @param int $category The ID matching the category.
|
||||
* @param int $purpose The ID matching the purpose record.
|
||||
* @param int $activity The name of the activity that we're making a defaults configuration for.
|
||||
* @param bool $override Whether to override the purpose/categories of existing instances to these defaults.
|
||||
* @return array
|
||||
*/
|
||||
public static function set_context_defaults($contextlevel, $category, $purpose, $activity, $override) {
|
||||
$warnings = [];
|
||||
|
||||
$params = external_api::validate_parameters(self::set_context_defaults_parameters(), [
|
||||
'contextlevel' => $contextlevel,
|
||||
'category' => $category,
|
||||
'purpose' => $purpose,
|
||||
'activity' => $activity,
|
||||
'override' => $override,
|
||||
]);
|
||||
$contextlevel = $params['contextlevel'];
|
||||
$category = $params['category'];
|
||||
$purpose = $params['purpose'];
|
||||
$activity = $params['activity'];
|
||||
$override = $params['override'];
|
||||
|
||||
// Validate context.
|
||||
$context = context_system::instance();
|
||||
self::validate_context($context);
|
||||
api::check_can_manage_data_registry();
|
||||
|
||||
// Set the context defaults.
|
||||
$result = api::set_context_defaults($contextlevel, $category, $purpose, $activity, $override);
|
||||
|
||||
return [
|
||||
'result' => $result,
|
||||
'warnings' => $warnings
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns for set_context_defaults().
|
||||
*
|
||||
* @return external_single_structure
|
||||
*/
|
||||
public static function set_context_defaults_returns() {
|
||||
return new external_single_structure([
|
||||
'result' => new external_value(PARAM_BOOL, 'Whether the context defaults were successfully set or not'),
|
||||
'warnings' => new external_warnings()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters for get_category_options().
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function get_category_options_parameters() {
|
||||
return new external_function_parameters([
|
||||
'includeinherit' => new external_value(PARAM_BOOL, 'Include option "Inherit"', VALUE_DEFAULT, true),
|
||||
'includenotset' => new external_value(PARAM_BOOL, 'Include option "Not set"', VALUE_DEFAULT, false),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a list of data category options containing category IDs as keys and the category name for the value.
|
||||
*
|
||||
* @param bool $includeinherit Whether to include the "Inherit" option.
|
||||
* @param bool $includenotset Whether to include the "Not set" option.
|
||||
* @return array
|
||||
*/
|
||||
public static function get_category_options($includeinherit, $includenotset) {
|
||||
$warnings = [];
|
||||
|
||||
$params = self::validate_parameters(self::get_category_options_parameters(), [
|
||||
'includeinherit' => $includeinherit,
|
||||
'includenotset' => $includenotset
|
||||
]);
|
||||
$includeinherit = $params['includeinherit'];
|
||||
$includenotset = $params['includenotset'];
|
||||
|
||||
$context = context_system::instance();
|
||||
self::validate_context($context);
|
||||
api::check_can_manage_data_registry();
|
||||
|
||||
$categories = api::get_categories();
|
||||
$options = data_registry_page::category_options($categories, $includenotset, $includeinherit);
|
||||
$categoryoptions = [];
|
||||
foreach ($options as $id => $name) {
|
||||
$categoryoptions[] = [
|
||||
'id' => $id,
|
||||
'name' => $name,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'options' => $categoryoptions,
|
||||
'warnings' => $warnings
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns for get_category_options().
|
||||
*
|
||||
* @return external_single_structure
|
||||
*/
|
||||
public static function get_category_options_returns() {
|
||||
$optiondefinition = new external_single_structure(
|
||||
[
|
||||
'id' => new external_value(PARAM_INT, 'The category ID'),
|
||||
'name' => new external_value(PARAM_TEXT, 'The category name'),
|
||||
]
|
||||
);
|
||||
|
||||
return new external_single_structure([
|
||||
'options' => new external_multiple_structure($optiondefinition),
|
||||
'warnings' => new external_warnings()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters for get_purpose_options().
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function get_purpose_options_parameters() {
|
||||
return new external_function_parameters([
|
||||
'includeinherit' => new external_value(PARAM_BOOL, 'Include option "Inherit"', VALUE_DEFAULT, true),
|
||||
'includenotset' => new external_value(PARAM_BOOL, 'Include option "Not set"', VALUE_DEFAULT, false),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a list of data storage purposes containing purpose IDs as keys and the purpose name for the value.
|
||||
*
|
||||
* @param bool $includeinherit Whether to include the "Inherit" option.
|
||||
* @param bool $includenotset Whether to include the "Not set" option.
|
||||
* @return array
|
||||
*/
|
||||
public static function get_purpose_options($includeinherit, $includenotset) {
|
||||
$warnings = [];
|
||||
|
||||
$params = self::validate_parameters(self::get_category_options_parameters(), [
|
||||
'includeinherit' => $includeinherit,
|
||||
'includenotset' => $includenotset
|
||||
]);
|
||||
$includeinherit = $params['includeinherit'];
|
||||
$includenotset = $params['includenotset'];
|
||||
|
||||
$context = context_system::instance();
|
||||
self::validate_context($context);
|
||||
|
||||
$purposes = api::get_purposes();
|
||||
$options = data_registry_page::purpose_options($purposes, $includenotset, $includeinherit);
|
||||
$purposeoptions = [];
|
||||
foreach ($options as $id => $name) {
|
||||
$purposeoptions[] = [
|
||||
'id' => $id,
|
||||
'name' => $name,
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'options' => $purposeoptions,
|
||||
'warnings' => $warnings
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns for get_purpose_options().
|
||||
*
|
||||
* @return external_single_structure
|
||||
*/
|
||||
public static function get_purpose_options_returns() {
|
||||
$optiondefinition = new external_single_structure(
|
||||
[
|
||||
'id' => new external_value(PARAM_INT, 'The purpose ID'),
|
||||
'name' => new external_value(PARAM_TEXT, 'The purpose name'),
|
||||
]
|
||||
);
|
||||
|
||||
return new external_single_structure([
|
||||
'options' => new external_multiple_structure($optiondefinition),
|
||||
'warnings' => new external_warnings()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Parameters for get_activity_options().
|
||||
*
|
||||
* @return external_function_parameters
|
||||
*/
|
||||
public static function get_activity_options_parameters() {
|
||||
return new external_function_parameters([
|
||||
'nodefaults' => new external_value(PARAM_BOOL, 'Whether to fetch all activities or only those without defaults',
|
||||
VALUE_DEFAULT, false),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetches a list of activity options for setting data registry defaults.
|
||||
*
|
||||
* @param boolean $nodefaults If false, it will fetch all of the activities. Otherwise, it will only fetch the activities
|
||||
* that don't have defaults yet (e.g. when adding a new activity module defaults).
|
||||
* @return array
|
||||
*/
|
||||
public static function get_activity_options($nodefaults) {
|
||||
$warnings = [];
|
||||
|
||||
$params = self::validate_parameters(self::get_activity_options_parameters(), [
|
||||
'nodefaults' => $nodefaults,
|
||||
]);
|
||||
$nodefaults = $params['nodefaults'];
|
||||
|
||||
$context = context_system::instance();
|
||||
self::validate_context($context);
|
||||
|
||||
// Get activity module plugin info.
|
||||
$pluginmanager = \core_plugin_manager::instance();
|
||||
$modplugins = $pluginmanager->get_enabled_plugins('mod');
|
||||
$modoptions = [];
|
||||
|
||||
// Get the module-level defaults. data_registry::get_defaults falls back to this when there are no activity defaults.
|
||||
list($levelpurpose, $levelcategory) = data_registry::get_defaults(CONTEXT_MODULE);
|
||||
foreach ($modplugins as $name) {
|
||||
// Check if we have default purpose and category for this module if we want don't want to fetch everything.
|
||||
if ($nodefaults) {
|
||||
list($purpose, $category) = data_registry::get_defaults(CONTEXT_MODULE, $name);
|
||||
// Compare this with the module-level defaults.
|
||||
if ($purpose !== $levelpurpose || $category !== $levelcategory) {
|
||||
// If the defaults for this activity has been already set, there's no need to add this in the list of options.
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$displayname = $pluginmanager->plugin_name('mod_' . $name);
|
||||
$modoptions[] = (object)[
|
||||
'name' => $name,
|
||||
'displayname' => $displayname
|
||||
];
|
||||
}
|
||||
|
||||
return [
|
||||
'options' => $modoptions,
|
||||
'warnings' => $warnings
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns for get_category_options().
|
||||
*
|
||||
* @return external_single_structure
|
||||
*/
|
||||
public static function get_activity_options_returns() {
|
||||
$optionsdefinition = new external_single_structure(
|
||||
[
|
||||
'name' => new external_value(PARAM_TEXT, 'The plugin name of the activity'),
|
||||
'displayname' => new external_value(PARAM_TEXT, 'The display name of the activity'),
|
||||
]
|
||||
);
|
||||
|
||||
return new external_single_structure([
|
||||
'options' => new external_multiple_structure($optionsdefinition),
|
||||
'warnings' => new external_warnings()
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the structure of a tree node (link + child branches).
|
||||
*
|
||||
|
||||
@@ -25,8 +25,6 @@ namespace tool_dataprivacy\external;
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
use core\external\persistent_exporter;
|
||||
use tool_dataprivacy\category;
|
||||
use tool_dataprivacy\context_instance;
|
||||
|
||||
/**
|
||||
* Class for exporting field data.
|
||||
@@ -55,25 +53,4 @@ class category_exporter extends persistent_exporter {
|
||||
'context' => 'context',
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Utility function that fetches a category name from the given ID.
|
||||
*
|
||||
* @param int $categoryid The category ID. Could be INHERIT (false, -1), NOT_SET (0), or the actual ID.
|
||||
* @return string The purpose name.
|
||||
*/
|
||||
public static function get_name($categoryid) {
|
||||
global $PAGE;
|
||||
if ($categoryid === false || $categoryid == context_instance::INHERIT) {
|
||||
return get_string('inherit', 'tool_dataprivacy');
|
||||
} else if ($categoryid == context_instance::NOTSET) {
|
||||
return get_string('notset', 'tool_dataprivacy');
|
||||
} else {
|
||||
$purpose = new category($categoryid);
|
||||
$output = $PAGE->get_renderer('tool_dataprivacy');
|
||||
$exporter = new self($purpose, ['context' => \context_system::instance()]);
|
||||
$data = $exporter->export($output);
|
||||
return $data->name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user