@@ -260,27 +260,22 @@ function __construct($return = FALSE)
260260 // If this directory doesn't exist then we can't do anything
261261 if (! empty ($ upload_directory )) {
262262
263- $ this ->valid_upload_dir = 'y ' ;
264- $ this ->can_upload = 'y ' ;
265-
266-
267-
268-
269- if ($ this ->has_role (array (2 , 3 , 4 ), TRUE ))
270- {
271- $ this ->can_upload = 'n ' ;
272- }
273- elseif (! ee ('Permission ' )->isSuperAdmin ())
274- {
275- ee ()->db ->select ('upload_id ' );
276- ee ()->db ->where_in ('role_id ' , $ this ->get_role_ids ());
277- $ access = ee ()->db ->get_where ('upload_prefs_roles ' , array ('upload_id ' => $ this ->upload_dir ));
263+ $ this ->valid_upload_dir = 'y ' ;
264+ $ this ->can_upload = 'y ' ;
278265
279- if ($ access -> num_rows () == 0 ) {
266+ if ($ this -> has_role ( array ( 2 , 3 , 4 ), TRUE )) {
280267 $ this ->can_upload = 'n ' ;
281268 }
282- }
283- }
269+ elseif (! ee ('Permission ' )->isSuperAdmin ()) {
270+ ee ()->db ->select ('upload_id ' );
271+ ee ()->db ->where_in ('role_id ' , $ this ->get_role_ids ());
272+ $ access = ee ()->db ->get_where ('upload_prefs_roles ' , array ('upload_id ' => $ this ->upload_dir ));
273+
274+ if ($ access ->num_rows () == 0 ) {
275+ $ this ->can_upload = 'n ' ;
276+ }
277+ }
278+ }
284279 }
285280
286281 /** ----------------------------------------
@@ -614,12 +609,20 @@ function __construct($return = FALSE)
614609
615610 public function has_role ($ roles , $ strict = FALSE )
616611 {
617- if (ee ('Permission ' )->isSuperAdmin () && $ strict = FALSE ) {
612+ if (ee ()->session ->userdata ('member_id ' ) == 0 ) {
613+ return FALSE ;
614+ }
615+
616+ if (ee ('Permission ' )->isSuperAdmin () && $ strict == FALSE ) {
618617 return TRUE ;
619618 }
620619
621620 $ user_role_ids = $ this ->get_role_ids ();
622621
622+ if (empty ($ user_role_ids )) {
623+ return FALSE ;
624+ }
625+
623626 if (! empty (array_intersect ($ user_role_ids , $ roles ))) {
624627 return TRUE ;
625628 }
@@ -629,23 +632,11 @@ public function has_role($roles, $strict = FALSE)
629632
630633 public function get_role_ids ()
631634 {
632- $ role_ids = array (0 );
633- $ member_id = ee ()->session ->userdata ('member_id ' );
634-
635- if (empty ($ member_id )) {
636- return array (0 );
637- }
638-
639- $ member = ee ('Model ' )
640- ->get ('Member ' , $ member_id )
641- ->with ('PrimaryRole ' , 'Roles ' , 'RoleGroups ' )
642- ->first ();
643-
644- if (!$ member ) {
645- return array (0 );
646- }
647-
648- return $ member ->getAllRoles ()->pluck ('role_id ' );
635+ $ user = ee ()->session ->getMember ();
636+ $ user_role_ids = (empty ($ user )) ? array () : $ user ->getAllRoles ()->pluck ('role_id ' );
637+
638+ return $ user_role_ids ;
639+
649640 }
650641
651642
0 commit comments