Skip to content

Commit c68a8cd

Browse files
Merge pull request #1545 from ucfopen/dev/10.1.0
Dev/10.1.0
2 parents c307c91 + 730bea4 commit c68a8cd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+3269
-3601
lines changed

fuel/app/classes/controller/api/admin.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,20 @@ public function post_user($user_id)
6969
return \Service_User::update_user($user_id, $user);
7070
}
7171

72-
public function get_widget_search(string $input)
72+
public function get_instance_search(string $input, string $page_number)
7373
{
7474
$input = trim($input);
7575
$input = urldecode($input);
76+
$page_number = (int) $page_number;
7677
//no need to search if for some reason an empty string is passed
77-
if ($input == '') return [];
78-
return \Materia\Widget_Instance_Manager::get_search($input);
78+
if ($input == '')
79+
{
80+
return [
81+
'pagination' => [],
82+
'next_page' => $page_number
83+
];
84+
}
85+
return \Materia\Widget_Instance_Manager::get_paginated_instance_search($input, $page_number);
7986
}
8087

8188
public function get_extra_attempts(string $inst_id)

fuel/app/classes/materia/api/v1.php

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,10 @@ static public function widget_instances_get($inst_ids = null, bool $deleted = fa
6464
*
6565
* @return array of objects containing total_num_pages and widget instances that are visible to the user.
6666
*/
67-
static public function widget_paginate_instances_get($page_number = 0)
67+
static public function widget_paginate_user_instances_get($page_number = 0)
6868
{
6969
if (\Service_User::verify_session() !== true) return Msg::no_login();
70-
$data = Widget_Instance_Manager::get_paginated_for_user(\Model_User::find_current_id(), $page_number);
70+
$data = Widget_Instance_Manager::get_paginated_instances_for_user(\Model_User::find_current_id(), $page_number);
7171
return $data;
7272
}
7373

@@ -218,7 +218,7 @@ static public function widget_instance_new($widget_id=null, $name=null, $qset=nu
218218
* @param int $close_at
219219
* @param int $attempts
220220
* @param bool $guest_access
221-
* @param bool $is_student_made
221+
* @param bool $is_student_made // NOT USED
222222
*
223223
* @return array An associative array with details about the save
224224
*/
@@ -237,6 +237,10 @@ static public function widget_instance_update($inst_id=null, $name=null, $qset=n
237237
// student made widgets are locked forever
238238
if ($inst->is_student_made)
239239
{
240+
if ($guest_access === false)
241+
{
242+
return new Msg('Student-made widgets must stay in guest access mode.', 'Student Made', 'error', false);
243+
}
240244
$attempts = -1;
241245
$guest_access = true;
242246
}
@@ -328,36 +332,42 @@ static public function widget_instance_update($inst_id=null, $name=null, $qset=n
328332
}
329333
if ($guest_access !== null)
330334
{
331-
if ($inst->guest_access != $guest_access)
332-
{
333-
$activity = new Session_Activity([
334-
'user_id' => \Model_User::find_current_id(),
335-
'type' => Session_Activity::TYPE_EDIT_WIDGET_SETTINGS,
336-
'item_id' => $inst_id,
337-
'value_1' => 'Guest Access',
338-
'value_2' => $guest_access
339-
]);
340-
$activity->db_store();
341-
}
342-
$inst->guest_access = $guest_access;
343-
// when disabling guest mode on a widget, make sure no students have access to that widget
344-
if ( ! $guest_access)
335+
// if the user is a student and they're not the owner, they can't do anything
336+
// if the user is a student and they're the owner, they're allowed to set it to guest access
337+
if (($inst->user_id == \Model_User::find_current_id() && $guest_access) || ! Perm_Manager::is_student(\Model_User::find_current_id()))
345338
{
346-
$access = Perm_Manager::get_all_users_explicit_perms($inst_id, Perm::INSTANCE)['widget_user_perms'];
347-
foreach ($access as $user_id => $user_perms)
339+
if ($inst->guest_access != $guest_access)
348340
{
349-
if (Perm_Manager::is_student($user_id))
341+
$activity = new Session_Activity([
342+
'user_id' => \Model_User::find_current_id(),
343+
'type' => Session_Activity::TYPE_EDIT_WIDGET_SETTINGS,
344+
'item_id' => $inst_id,
345+
'value_1' => 'Guest Access',
346+
'value_2' => $guest_access
347+
]);
348+
$activity->db_store();
349+
}
350+
$inst->guest_access = $guest_access;
351+
// when disabling guest mode on a widget, make sure no students have access to that widget
352+
if ( ! $guest_access)
353+
{
354+
$access = Perm_Manager::get_all_users_explicit_perms($inst_id, Perm::INSTANCE)['widget_user_perms'];
355+
foreach ($access as $user_id => $user_perms)
350356
{
351-
\Model_Notification::send_item_notification(\Model_user::find_current_id(), $user_id, Perm::INSTANCE, $inst_id, 'disabled', null);
352-
Perm_Manager::clear_user_object_perms($inst_id, Perm::INSTANCE, $user_id);
357+
if (Perm_Manager::is_student($user_id) && $user_id != $inst->user_id)
358+
{
359+
\Model_Notification::send_item_notification(\Model_user::find_current_id(), $user_id, Perm::INSTANCE, $inst_id, 'disabled', null);
360+
Perm_Manager::clear_user_object_perms($inst_id, Perm::INSTANCE, $user_id);
361+
}
353362
}
354363
}
355364
}
356365
}
357366

358367
if ($embedded_only !== null)
359368
{
360-
if ($inst->embedded_only != $embedded_only)
369+
// if current user is student, they cannot change embedded_only
370+
if ($inst->embedded_only != $embedded_only && ! Perm_Manager::is_student(\Model_User::find_current_id()))
361371
{
362372
$activity = new Session_Activity([
363373
'user_id' => \Model_User::find_current_id(),
@@ -367,8 +377,9 @@ static public function widget_instance_update($inst_id=null, $name=null, $qset=n
367377
'value_2' => $embedded_only
368378
]);
369379
$activity->db_store();
380+
381+
$inst->embedded_only = $embedded_only;
370382
}
371-
$inst->embedded_only = $embedded_only;
372383
}
373384

374385
try
@@ -662,11 +673,12 @@ static public function guest_widget_instance_scores_get($inst_id, $play_id)
662673
*/
663674
static public function play_logs_get($inst_id, $semester = 'all', $year = 'all', $page_number=1)
664675
{
665-
if ( ! Util_Validator::is_valid_hash($inst_id)) return Msg::invalid_input($inst_id);
676+
if ( ! Util_Validator::is_valid_hash($inst_id)) return Msg::invalid_input($inst_id);
666677
if (\Service_User::verify_session() !== true) return Msg::no_login();
667678
if ( ! static::has_perms_to_inst($inst_id, [Perm::VISIBLE, Perm::FULL])) return Msg::no_perm();
679+
$is_student = ! \Service_User::verify_session(['basic_author', 'super_user']);
668680

669-
$data = Session_Play::get_by_inst_id_paginated($inst_id, $semester, $year, $page_number);
681+
$data = Session_Play::get_by_inst_id_paginated($inst_id, $semester, $year, $page_number, $is_student);
670682
return $data;
671683
}
672684

@@ -881,23 +893,39 @@ static public function semester_date_ranges_get()
881893
return Utils::get_date_ranges();
882894
}
883895

884-
static public function users_search($search)
896+
/**
897+
* Paginated search for users that match input
898+
*
899+
* @param string Search query
900+
* @param string Page number
901+
* @return array List of users
902+
*/
903+
static public function users_search($input, $page_number = 0)
885904
{
886905
if (\Service_User::verify_session() !== true) return Msg::no_login();
887906

888-
$user_objects = \Model_User::find_by_name_search($search);
889-
$user_arrays = [];
907+
$items_per_page = 50;
908+
$offset = $items_per_page * $page_number;
909+
910+
// query DB for only a single page + 1 item
911+
$displayable_items = \Model_User::find_by_name_search($input, $offset, $items_per_page + 1);
912+
913+
$has_next_page = sizeof($displayable_items) > $items_per_page ? true : false;
914+
915+
if ($has_next_page) array_pop($displayable_items);
890916

891-
// scrub the user models with to_array
892-
if (count($user_objects))
917+
foreach ($displayable_items as $key => $person)
893918
{
894-
foreach ($user_objects as $key => $person)
895-
{
896-
$user_arrays[$key] = $person->to_array();
897-
}
919+
$displayable_items[$key] = $person->to_array();
898920
}
899921

900-
return $user_arrays;
922+
$data = [
923+
'pagination' => $displayable_items,
924+
];
925+
926+
if ($has_next_page) $data['next_page'] = $page_number + 1;
927+
928+
return $data;
901929
}
902930
/**
903931
* Gets information about the current user

fuel/app/classes/materia/perm/manager.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ static public function is_super_user()
3838
// The session caching has been removed due to issues related to the cache when the role is added or revoked
3939
// Ideally we can still find a way to cache this and make it more performant!!
4040
return (\Fuel::$is_cli === true && ! \Fuel::$is_test) || self::does_user_have_role([\Materia\Perm_Role::SU]);
41-
41+
4242
}
4343

4444
/**
@@ -351,10 +351,10 @@ static public function remove_users_from_roles_system_only(Array $user_ids = [],
351351
->execute();
352352
}
353353
}
354+
354355
return $success;
355356
}
356357

357-
358358
/*
359359
********************** User to Object Rights ***************************************
360360
*/

fuel/app/classes/materia/session/play.php

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public function resume($play_id)
213213
* Must be fast because it can be asked to retrieve large data sets
214214
*
215215
*/
216-
public static function get_by_inst_id($inst_id, $semester='all', $year='all')
216+
public static function get_by_inst_id($inst_id, $semester='all', $year='all', $is_student=false)
217217
{
218218
if ($semester != 'all' && $year != 'all')
219219
{
@@ -230,7 +230,23 @@ public static function get_by_inst_id($inst_id, $semester='all', $year='all')
230230

231231
if (is_null($plays))
232232
{
233-
$query = \DB::select(
233+
// if user is student, do not query user information
234+
if ($is_student)
235+
{
236+
$query = \DB::select(
237+
's.id',
238+
['s.created_at', 'time'],
239+
['s.is_complete', 'done'],
240+
['s.percent', 'perc'],
241+
['s.elapsed', 'elapsed'],
242+
['s.qset_id', 'qset_id']
243+
)
244+
->from(['log_play', 's'])
245+
->where('s.inst_id', $inst_id);
246+
}
247+
else
248+
{
249+
$query = \DB::select(
234250
's.id',
235251
['s.created_at', 'time'],
236252
['s.is_complete', 'done'],
@@ -246,6 +262,7 @@ public static function get_by_inst_id($inst_id, $semester='all', $year='all')
246262
->join(['users', 'u'], 'LEFT OUTER')
247263
->on('u.id', '=', 's.user_id')
248264
->where('s.inst_id', $inst_id);
265+
}
249266

250267
if (isset($date))
251268
{
@@ -256,14 +273,28 @@ public static function get_by_inst_id($inst_id, $semester='all', $year='all')
256273

257274
\Cache::set('play-logs.'.$inst_id.'.'.$cache_id, $plays);
258275
}
276+
else
277+
{
278+
// if user is student, do not show user information
279+
if ($is_student)
280+
{
281+
foreach ($plays as &$play)
282+
{
283+
$play['user_id'] = 0;
284+
unset($play['first']);
285+
unset($play['last']);
286+
unset($play['username']);
287+
}
288+
}
289+
}
259290

260291
return $plays;
261292
}
262293

263-
public static function get_by_inst_id_paginated($inst_id, $semester='all', $year='all', $page_number=1)
294+
public static function get_by_inst_id_paginated($inst_id, $semester='all', $year='all', $page_number=1, $is_student=false)
264295
{
265296
$items_per_page = 100;
266-
$data = self::get_by_inst_id($inst_id, $semester, $year);
297+
$data = self::get_by_inst_id($inst_id, $semester, $year, $is_student);
267298
$total_num_pages = ceil(sizeof($data) / $items_per_page);
268299
$offset = $items_per_page * ($page_number - 1);
269300
$page = array_slice($data, $offset, $items_per_page);
@@ -327,6 +358,8 @@ public function get_by_id($play_id=0)
327358
$this->elapsed = $r['elapsed'];
328359
$this->context_id = $r['context_id'];
329360
$this->semester = $r['semester'];
361+
$this->auth = $r['auth'];
362+
$this->environment_data = $r['environment_data'];
330363
return true;
331364
}
332365
}

fuel/app/classes/materia/widget/instance.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,10 @@ public function duplicate(int $owner_id, string $new_name = null, bool $copy_exi
467467
// update name
468468
if ( ! empty($new_name)) $duplicate->name = $new_name;
469469

470+
// is_embedded and embedded_only should default to false for new instances (since the new instance won't have the play history requisite for is_embedded)
471+
$duplicate->is_embedded = false;
472+
$duplicate->embedded_only = false;
473+
470474
// these values aren't saved to the db - but the frontend will make use of them
471475
$duplicate->clean_name = \Inflector::friendly_title($duplicate->name, '-', true);
472476
$base_url = "{$duplicate->id}/{$duplicate->clean_name}";

0 commit comments

Comments
 (0)