From c393d8185ad526d9273cae9319b408666fedcaa5 Mon Sep 17 00:00:00 2001 From: Bas Brands Date: Thu, 21 May 2020 16:53:12 +0200 Subject: [PATCH] MDL-68796 core_contentbank: Store view preferences includes privacy export, privacy unit test --- contentbank/amd/build/sort.min.js | Bin 2534 -> 2791 bytes contentbank/amd/build/sort.min.js.map | Bin 11661 -> 13059 bytes contentbank/amd/src/sort.js | 35 ++++++++++++- contentbank/classes/output/bankcontent.php | 1 + contentbank/classes/privacy/provider.php | 23 ++++++++- contentbank/lib.php | 39 +++++++++++++++ contentbank/templates/bankcontent.mustache | 3 +- .../templates/bankcontent/toolbar.mustache | 4 +- .../tests/behat/view_preferences.feature | 28 +++++++++++ contentbank/tests/privacy_test.php | 47 ++++++++++++++++++ lang/en/contentbank.php | 1 + lib/classes/user.php | 2 +- 12 files changed, 177 insertions(+), 6 deletions(-) create mode 100644 contentbank/lib.php create mode 100644 contentbank/tests/behat/view_preferences.feature diff --git a/contentbank/amd/build/sort.min.js b/contentbank/amd/build/sort.min.js index 5d0babfc933c2f9ba5640b98a875bdf56641b5e4..bd655b72595060621cacf194911eb49d3dcc43aa 100644 GIT binary patch delta 541 zcmY*WF>ezw6xPv%M(RdkVIf=*vV|MUn&T=lu~prpD0+AIeCNdHi+sLNh)(?rJ$df0 z2uo*HRu&`}frbBo9nuP>_xXMP{C)5F$KlUMS1cHHub)3*VOnW?33IpzcUV>#*#C#}Na4x1{pQl&l>a-J_sg9_%jWUz5H9yxa2GL- zV+SEtjg+m=pTz4DO;KeEN*r$&H*0Ftvu5ct{l!a-95t#G>yUxY>+#yRE_c20WbJKt z>aVB9WGj#jj-j2lZKTmOS`BfOA%{kqQ3_I$NiwCAlc_tHv>^PB v#ETS{{wrw97XOUI?63aEKyI$@p9T-4+p=5I?aM8b_V@nxpxk^OJP!T<&Z4^2 delta 277 zcmaDZ`b>C&jzDsLQEGg0eqKpxUP)47UiL&?HKACYw9>rflFa-(jYOR!on)PqiJbvr zsTxU|)+x5B8Y!CAFnNX4iGOt&(s?PyZ zlL=Ha`4fv0WA@~UEb8pVnN_Kp*4aR#w87HZAn7vJQU#FO98~j4DhpDTbdoe{HEVS; tCf{W{z?ivt9=jc*P$tk)peaSEC8b4q3aPa^nUmjf++)nze3ny+5dg?VTmk?9 diff --git a/contentbank/amd/build/sort.min.js.map b/contentbank/amd/build/sort.min.js.map index 4609a9ec243415854c3651e4ec2de92b7cd7f952..663a4387719cfebb1625ec6cf3e943875181a3d3 100644 GIT binary patch delta 2529 zcmaJ@&2Jk;6xX^HP2(gcO`&O%l%XxeNtdK;`bD5pXUC4~y7{V`q-|1#jXjQ+*t_oT zI%!%J3n4B@fW(LcTq?u`fe=OE#EriIi91LfxNrc$jRO+zy>V=(AM9bi-pBmj@4eZX z_ZQzOJoJqHGMsnh#uXDh1L!IZ zWt@eZ6_l;pr7HIPP5TaXIlEM%F3c67pYlSd;NZuA@Zl*Y& z6llyjwsY8|?y84-hKxD&Yg@l@Ma80VV_LDc{?0S#nkTTyZK^a#E9$N2(a5T$-fJ_B zSIJD0+5A(?&a0Wd+N`&yY;nF$E>DY9>d&YT+n!fn@9mBhh5B|++;G%i?E}Wmrn9bA z468!jZ0{owz3PMZC<6Jk-Hep9ahZ(sP2(K_tSLKM51^)ZuOJbkgh(!7km*Y%u4FUN z6T8TbndLk?g$viPDWi7koIoPeW@ekm%P8AGnW#Y4U^0tM3KNuvQ8GcyuTj*zMjF#v z159oTbFQ9?q*)d`f$}7*rg0PSgXtC%!d&2dp)p51BHgNV+Tw|MSWUtzK+BLSF+On} z#)&L8Fskv1Nt6{4&JAu(ay|{T|pt0hM2)2Rlqz{7?vE&eGA7M)-3Kq^~cX! z6oW00uQ4JPkbv@Bh6v^kSrVOMM_!JrpQG_eF`@Q!3`IPlPIat7W&PN3=m2;E=UB~W z$(S$;lpX8bvGP&pG2^Uysna~C!RXq~BIPRp0ZtHR%OfW`tdkbvL{cCmD64lnM6vf-}J4lbI zKVz>%HY_#p?B6E}kmIY95K&g=b0Jee)+9DMn-y|ETP}DBb+Nm5&c)30BDLqK7)nVx z03I#r&FUuvQj?-`rBj!M+JdSlm^po1^19g4>Z|T+GgOa=U}6<_O!*0NL;u4Rd7vFc z(!9a>1fq})lS^chzDsA3&Xvfj>3z42G4;c~=OUXz4fKquXwUW6$%Gt>75MvVI6yFD zmlJt#yl0`LinMP_IKoM8J?QyomocKgI8eOolq;SeGQ0*@!S~8+Fz5Ml)Q0)sYfElj z+0RPlmc3gp)3{f2S)=}MtrmFkznhqt~T_-S`-$sHXY zUUJzm%gT_2MagoW8%j4^vE4OR4W!SSmm70jR)V{ct-~dWMr3%gV*7TPv3r*1mF|-a zFHjmVp}kq?%?`+VL|geXtokYw@2Fjs6)$i?&)KVzBH2D^%Sa zUYT)(gIf-I&Vp=#I0+rZUPHt3m1> zUDFbL$ZP{>DT`%{Y#9rob!Tm&TViUw!NB9*frW5MC zYBXnKV&V@lE=*V%H@b4?!kvGiHYU33!o+*d7(2DneeO;GXcLH{75k>+qYv9%IYk@hGeUQ=Y+)hL$uGQN=Ke z_`jO$B;m7n#GMecrhB;T4Z&NF-B~u1_awRN35Bkj$b(8z?`c+*&ZB=ijwaIRq{$@_ z*W@XiS28@qCGgDu5;NrfnTso|ri?xqC@x_X+NyF9?)qZWIuhpQ(j|db!Mh^DI(A>3 z6tu&28ii?zGY#1F#aS7`$G)Fal^mbX%U7UXQE+ml+#1=_wi@$m6G1Ubn*yf%!SEJQ z4I1@%MA1?y*x4kk_@hCAouE|oEGATy0ptVB!ApP9Kab3kgy}kprq@y$_y(dwzxf&B zGg~Q?q_-m$V0K_tZpyoXfTb=V5=ekOuy}!73aBTSVD48)*&ewMe3No4C<1;2qwB)sf>pHTtO!f^mN@5c_KX E36?)Pod5s; diff --git a/contentbank/amd/src/sort.js b/contentbank/amd/src/sort.js index bfa61c8a0a3..24f4f79fbbd 100644 --- a/contentbank/amd/src/sort.js +++ b/contentbank/amd/src/sort.js @@ -22,9 +22,11 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -import selectors from 'core_contentbank/selectors'; +import selectors from './selectors'; import {get_string as getString} from 'core/str'; import Prefetch from 'core/prefetch'; +import Ajax from 'core/ajax'; +import Notification from 'core/notification'; /** * Set up the contentbank views. @@ -59,6 +61,7 @@ const registerListenerEvents = (contentBank) => { contentBank.classList.add('view-grid'); viewGrid.classList.add('active'); viewList.classList.remove('active'); + setViewListPreference(false); }); viewList.addEventListener('click', () => { @@ -66,6 +69,7 @@ const registerListenerEvents = (contentBank) => { contentBank.classList.add('view-list'); viewList.classList.add('active'); viewGrid.classList.remove('active'); + setViewListPreference(true); }); // Sort by file name alphabetical @@ -97,6 +101,35 @@ const registerListenerEvents = (contentBank) => { }); }; + +/** + * Set the contentbank user preference in list view + * + * @param {Bool} viewList view ContentBank as list. + * @return {Promise} Repository promise. + */ +const setViewListPreference = function(viewList) { + + // If the given status is not hidden, the preference has to be deleted with a null value. + if (viewList === false) { + viewList = null; + } + + const request = { + methodname: 'core_user_update_user_preferences', + args: { + preferences: [ + { + type: 'core_contentbank_view_list', + value: viewList + } + ] + } + }; + + return Ajax.call([request])[0].catch(Notification.exception); +}; + /** * Update the sort button view. * diff --git a/contentbank/classes/output/bankcontent.php b/contentbank/classes/output/bankcontent.php index 6574b0409c7..5ac92e93a7a 100644 --- a/contentbank/classes/output/bankcontent.php +++ b/contentbank/classes/output/bankcontent.php @@ -97,6 +97,7 @@ class bankcontent implements renderable, templatable { 'type' => $mimetype ); } + $data->viewlist = get_user_preferences('core_contentbank_view_list'); $data->contents = $contentdata; $data->tools = $this->toolbar; return $data; diff --git a/contentbank/classes/privacy/provider.php b/contentbank/classes/privacy/provider.php index d654ab37bc5..c0c49c5c9ac 100644 --- a/contentbank/classes/privacy/provider.php +++ b/contentbank/classes/privacy/provider.php @@ -44,7 +44,8 @@ use context_course; class provider implements \core_privacy\local\metadata\provider, \core_privacy\local\request\core_userlist_provider, - \core_privacy\local\request\plugin\provider { + \core_privacy\local\request\plugin\provider, + \core_privacy\local\request\user_preference_provider { /** * Returns meta data about this system. @@ -65,6 +66,26 @@ class provider implements return $collection; } + /** + * Export all user preferences for the contentbank + * + * @param int $userid The userid of the user whose data is to be exported. + */ + public static function export_user_preferences(int $userid) { + $preference = get_user_preferences('core_contentbank_view_list', null, $userid); + if (isset($preference)) { + writer::export_user_preference( + 'core_contentbank', + 'core_contentbank_view_list', + $preference, + get_string('privacy:request:preference:set', 'core_contentbank', (object) [ + 'name' => 'core_contentbank_view_list', + 'value' => $preference, + ]) + ); + } + } + /** * Get the list of contexts that contain user information for the specified user. * diff --git a/contentbank/lib.php b/contentbank/lib.php new file mode 100644 index 00000000000..e709df77df0 --- /dev/null +++ b/contentbank/lib.php @@ -0,0 +1,39 @@ +. + +/** + * Library functions for contentbank + * + * @package core_contentbank + * @copyright 2020 Bas Brands + * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later + */ + +/** + * Get the current user preferences that are available + * + * @return Array preferences configuration + */ +function core_contentbank_user_preferences() { + return [ + 'core_contentbank_view_list' => [ + 'choices' => array(0, 1), + 'type' => PARAM_INT, + 'null' => NULL_NOT_ALLOWED, + 'default' => 'none' + ], + ]; +} diff --git a/contentbank/templates/bankcontent.mustache b/contentbank/templates/bankcontent.mustache index 0826a65e482..aaa3857789b 100644 --- a/contentbank/templates/bankcontent.mustache +++ b/contentbank/templates/bankcontent.mustache @@ -48,7 +48,8 @@ } }} -
+
{{>core_contentbank/bankcontent/search}} diff --git a/contentbank/templates/bankcontent/toolbar.mustache b/contentbank/templates/bankcontent/toolbar.mustache index 04c762a1320..76fe0877174 100644 --- a/contentbank/templates/bankcontent/toolbar.mustache +++ b/contentbank/templates/bankcontent/toolbar.mustache @@ -38,12 +38,12 @@ {{#pix}} {{{ icon }}} {{/pix}} {{{ name }}} {{/tools}} - -