Skip to content

Commit f5771c3

Browse files
Merge pull request #1463 from clpetersonucf/react/fixes-and-polish-part-three
React/fixes and polish part three
2 parents 08c6cfb + 10e54a0 commit f5771c3

File tree

17 files changed

+130
-240
lines changed

17 files changed

+130
-240
lines changed

docker/config/nginx/nginx-dev.conf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,10 @@ http {
152152
listen *:8008 ssl;
153153
listen [::]:8008 ssl;
154154

155-
# some js assets will be requested at /js instead of /dist/js
156-
# redirect these requests appropriately
157-
location ~* ^\/js\/.+\.js$ {
155+
# In the dev environment, js and css assets are emitted to public/dist instead of public/
156+
# However, server pages will expect them to be in public/js or public/css instead
157+
# Redirect requests for these assets to public/dist
158+
location ~* ^\/(?:js|css)\/.+\.(?:js|css)$ {
158159
proxy_pass https://$server_addr/dist$uri;
159160
}
160161

docker/run_build_assets.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,4 @@ docker run \
2222
--mount type=bind,source="$(pwd)"/../,target=/build \
2323
--mount source=materia-asset-build-vol,target=/build/node_modules \
2424
node:18.13.0-alpine \
25-
/bin/ash -c "apk add --no-cache git && cd build && yarn install --frozen-lockfile --non-interactive --production --silent --pure-lockfile --force"
25+
/bin/ash -c "apk add --no-cache git && cd build && yarn install --frozen-lockfile --non-interactive --silent --pure-lockfile --force && npm run-script build"

docker/run_build_github_release_package.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ DOCKER_IMAGE=$1
2929

3030
# declare files that should have been created
3131
declare -a FILES_THAT_SHOULD_EXIST=(
32-
"public/dist/js/materia.enginecore.js"
33-
"public/dist/css/widget-player.css"
32+
"public/js/materia.enginecore.js"
33+
"public/css/widget-player.css"
3434
)
3535

3636
# declare files to omit from zip

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

Lines changed: 57 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,10 @@ static public function clear_all_perms_for_object($object_id, $object_type)
552552
}
553553

554554
/**
555-
* Gets an array of object id's that a user has permissions for matching any of the requested permissions.
555+
* Gets an array of object ids of a given type that a user has EXPLICIT permissions to that matches the perms provided.
556+
* (!!!) NOTE: Previously, this method would also return IMPLICITLY available objects based on the user's role (if elevated).
557+
* This is no longer the case. If IMPLICITLY available objects are required, use get_all_objects_for_elevated_user_role
558+
*
556559
* If an object has any of the requested permissions, it will be returned.
557560
* Perm_Manager->get_all_objects_for_users($user->user_id, \Materia\Perm::INSTANCE, [\Materia\Perm::SHARE]);
558561
*
@@ -570,43 +573,64 @@ static public function get_all_objects_for_user($user_id, $object_type, $perms)
570573
// WHERE id IN (5, 6) whould match ids that ***START*** with 5 or 6
571574
foreach ($perms as &$value) $value = (string) $value;
572575

573-
// ====================== GET THE USERS ROLE PERMISSIONS ============================
574-
// build a subquery that gets any roles the user has
575-
$subquery_role_ids = \DB::select('role_id')
576-
->from('perm_role_to_user')
577-
->where('user_id', $user_id);
578-
579-
// get any perms that users roles have
580-
$roles_perms = \DB::select('perm')
581-
->from('perm_role_to_perm')
582-
->where('role_id', 'IN', $subquery_role_ids)
576+
// ==================== GET USER's EXPLICIT PERMISSSION ==============================
577+
// get objects that the user has direct access to
578+
$objects = \DB::select('object_id')
579+
->from('perm_object_to_user')
580+
->where('object_type', $object_type)
581+
->where('user_id', $user_id)
583582
->where('perm', 'IN', $perms)
584-
->execute();
585-
586-
// Only super_user has role perm 30 -- get all assets/widgets
587-
if ($roles_perms->count() != 0)
588-
{
589-
$objects = \DB::select('id')
590-
->from($object_type == Perm::ASSET ? 'asset' : 'widget_instance')
591-
->execute()
592-
->as_array('id', 'id');
593-
}
594-
else
595-
{
596-
// ==================== GET USER's EXPLICIT PERMISSSION ==============================
597-
// get objects that the user has direct access to
598-
$objects = \DB::select('object_id')
599-
->from('perm_object_to_user')
600-
->where('object_type', $object_type)
601-
->where('user_id', $user_id)
602-
->where('perm', 'IN', $perms)
603-
->execute()
604-
->as_array('object_id', 'object_id');
605-
}
583+
->execute()
584+
->as_array('object_id', 'object_id');
606585
return $objects;
607586
}
608587
}
609588

589+
/**
590+
* Gets an array of object ids that a user has permissions to access EXCLUSIVELY based on an elevated role
591+
* This requires the user has a role with elevated perms, and that the group rights associated with those perms are present in the perm_role_to_perm table
592+
* Currently, the role must be Perm::ADMINISTRATOR or Perm::SUPERUSER
593+
*
594+
* Perm_Manager->get_all_objects_for_users($user->user_id, \Materia\Perm::INSTANCE);
595+
*
596+
* @param int User ID the get permissions for
597+
* @param int Object type as defined in Perm constants
598+
*/
599+
static public function get_all_objects_for_elevated_user_role($user_id, $object_type)
600+
{
601+
$objects = [];
602+
$user_is_admin_or_su = false;
603+
604+
// ====================== GET THE USERS ROLE PERMISSIONS ============================
605+
// build a subquery that gets any roles the user has
606+
$subquery_role_ids = \DB::select('role_id')
607+
->from('perm_role_to_user')
608+
->where('user_id', $user_id);
609+
610+
// get any perms that users roles have
611+
$roles_perms = \DB::select('perm')
612+
->from('perm_role_to_perm')
613+
->where('role_id', 'IN', $subquery_role_ids)
614+
->execute();
615+
616+
617+
// verify that perms returned from perm_role_to_perm table are elevated
618+
// this means either Perm::ADMINISTRATOR (85) or Perm::SUPERUSER (90)
619+
foreach ($roles_perms as $role)
620+
{
621+
if (in_array([Perm::ADMINISTRATOR, Perm::SUPERUSER], $role['perm'])) $user_is_admin_or_su = true;
622+
}
623+
624+
if ($user_is_admin_or_su == true)
625+
{
626+
$objects = \DB::select('id')
627+
->from($object_type == Perm::ASSET ? 'asset' : 'widget_instance')
628+
->execute()
629+
->as_array('id', 'id');
630+
}
631+
return $objects;
632+
}
633+
610634
/**
611635
* Counts the number of users with perms to a given object
612636
* to an object (used by Widget_Asset_Manager.can_asset_be_deleted)

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public static function get_by_inst_id($inst_id, $semester='all', $year='all')
262262

263263
public static function get_by_inst_id_paginated($inst_id, $semester='all', $year='all', $page_number=1)
264264
{
265-
$items_per_page = 10;
265+
$items_per_page = 100;
266266
$data = self::get_by_inst_id($inst_id, $semester, $year);
267267
$total_num_pages = ceil(sizeof($data) / $items_per_page);
268268
$offset = $items_per_page * ($page_number - 1);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public static function get_paginated_for_user($user_id, $page_number = 1)
8080
{
8181
$inst_ids = Perm_Manager::get_all_objects_for_user($user_id, Perm::INSTANCE, [Perm::FULL, Perm::VISIBLE]);
8282
$displayable_inst = self::get_all($inst_ids);
83-
$widgets_per_page = 10;
83+
$widgets_per_page = 80;
8484
$total_num_pages = ceil(sizeof($displayable_inst) / $widgets_per_page);
8585
$offset = $widgets_per_page * ($page_number - 1);
8686

fuel/app/config/css.php

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515

1616
'groups' => [
1717
'core' => [$webpack.'css/core.css'],
18-
'homepage' => [$webpack.'js/homepage.css'],
18+
'homepage' => [$webpack.'css/homepage.css'],
1919
'admin' => [$webpack.'css/admin.css'],
20-
'user-admin' => [$webpack.'js/user-admin.css'],
21-
'support' => [$webpack.'js/support.css'],
22-
'catalog' => [$webpack.'js/catalog.css'],
23-
'detail' => [$webpack.'js/detail.css'],
20+
'user-admin' => [$webpack.'css/user-admin.css'],
21+
'support' => [$webpack.'css/support.css'],
22+
'catalog' => [$webpack.'css/catalog.css'],
23+
'detail' => [$webpack.'css/detail.css'],
2424
'playpage' => [
2525
$webpack.'css/widget-player-page.css',
2626
$webpack.'css/loading-icon.css'
@@ -29,36 +29,36 @@
2929
$webpack.'css/widget-play.css',
3030
],
3131
'lti' => [$webpack.'css/util-lti-picker.css'],
32-
'my_widgets' => [$webpack.'js/my-widgets.css'],
32+
'my_widgets' => [$webpack.'css/my-widgets.css'],
3333
'widget_create' => [
3434
$webpack.'css/loading-icon.css',
35-
$webpack.'js/creator-page.css',
35+
$webpack.'css/creator-page.css',
3636
],
3737
'widget_detail' => [
3838
$webpack.'css/widget-detail.css',
3939
],
4040
'widget_catalog' => [$webpack.'css/widget-catalog.css'],
41-
'profile' => [$webpack.'js/profile.css'],
42-
'login' => [$webpack.'js/login.css'],
41+
'profile' => [$webpack.'css/profile.css'],
42+
'login' => [$webpack.'css/login.css'],
4343
'scores' => [
4444
$cdnjs.'jqPlot/1.0.9/jquery.jqplot.min.css',
45-
$webpack.'js/scores.css',
45+
$webpack.'css/scores.css',
4646
],
47-
'pre_embed_placeholder' => [$webpack.'js/pre-embed-common-styles.css'],
47+
'pre_embed_placeholder' => [$webpack.'css/pre-embed-common-styles.css'],
4848
'embed_scores' => [$webpack.'css/scores.css'],
4949
'question_import' => [
5050
$vendor.'jquery.dataTables.min.css',
5151
$webpack.'css/util-question-import.css',
5252
$webpack.'css/question-importer.css',
5353
],
54-
'questionimport' => [$webpack.'js/question-importer.css'],
54+
'questionimport' => [$webpack.'css/question-importer.css'],
5555
'qset_history' => [
5656
$webpack.'css/util-qset-history.css',
5757
],
5858
'rollback_dialog' => [
5959
$webpack.'css/util-rollback-confirm.css'
6060
],
61-
'media_import' => [$webpack.'js/media.css'],
61+
'media_import' => [$webpack.'css/media.css'],
6262
'help' => [$webpack.'css/help.css'],
6363
'errors' => [$webpack.'css/errors.css'],
6464
'fonts' => [
@@ -68,8 +68,8 @@
6868
'guide' => [$webpack.'css/widget-guide.css'],
6969
// the following are required for the support-info styles to be embedded
7070
// TODO probably consolidate the support_info styles in a common stylesheet
71-
'draft-not-playable' => [$webpack.'js/draft-not-playable.css'],
72-
'500' => [$webpack.'js/500.css'],
73-
'no_permission' => [$webpack.'js/no-permission.css']
71+
'draft-not-playable' => [$webpack.'css/draft-not-playable.css'],
72+
'500' => [$webpack.'css/500.css'],
73+
'no_permission' => [$webpack.'css/no-permission.css']
7474
],
7575
];

fuel/app/config/development/materia.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
// since this is the dev config - the assumption is that assets are located in public/dist. NGINX will reroute *.js and *.css requests for public/ to public/dist/
34
$assets_exist = file_exists(DOCROOT."dist/js/my-widgets.js");
45
// convert current url to https://whatever:8008/ for simulated pass through cdn
56
$simulated_cdn_url = preg_replace('/(https:\/\/.+?)(\:[0-9]*){0,1}(\/.*)/', '${1}:8008${3}', \Uri::create());
@@ -12,7 +13,7 @@
1213
// No port is specified so 8080 is picked by default
1314
'static' => $simulated_cdn_url,
1415
'engines' => $simulated_cdn_url.'widget/',
15-
'js_css' => $assets_exist ? $simulated_cdn_url.'dist/' : '//127.0.0.1:8080/dist/',
16+
'js_css' => $assets_exist ? $simulated_cdn_url : '//127.0.0.1:8080/',
1617
],
1718

1819
/**

fuel/app/config/materia.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@
3030
'static' => $_ENV['URLS_STATIC'] ?? \Uri::create(), // allows you to host another domain for static assets http://static.siteurl.com/
3131
'engines' => $_ENV['URLS_ENGINES'] ?? \Uri::create('widget/'), // widget file locations
3232
// where are js and css assets hosted?
33-
// DEFAULT: public/dist (hosted as as https://site.com/dist)
34-
'js_css' => \Uri::create('dist/'),
33+
// DEFAULT: public/dist (hosted as as https://site.com/)
34+
'js_css' => \Uri::create('/'),
3535
// CDN PASS-THROUGH: set up aws cloudfront cdn have it load data from the default url
3636
//'js_css' => '//xxxxxxxx.cloudfront.net/dist/',
3737
// CDN UNPKG.COM: load assets from npm module with the same release (version must match your version of materia)

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
"webpack-cli": "^5.0.1",
6464
"webpack-dev-server": "^4.11.1",
6565
"webpack-manifest-plugin": "^5.0.0",
66+
"webpack-remove-empty-scripts": "1.0.1",
6667
"webpack-strip-block": "^0.3.0"
6768
},
6869
"nodemonConfig": {

0 commit comments

Comments
 (0)