user to swap permissions easily

If you're a new user of AppGini, feel free to ask general usage questions, or look for answers here.
Post Reply
graham
Veteran Member
Posts: 84
Joined: 2020-09-29 12:30

user to swap permissions easily

Post by graham » 2020-10-13 14:51

Hi, in my application I have four permission Groups. Jack is a member of Group 1 - but he also needs to be able to access the app as a member of Group2. I can achieve this by making Jack a member of both Groups by giving Jack a different username for each Group. Part of Jack's job means he needs to see all the data and another part of his job means he only wants to see data relative to one Group. So I could give him global permission but he would continually have to filter. Or he could log out then back in with a different username but that would be tedious. So does anyone have any thoughts on how I can best allow Jack to quickly/easily 'switch Groups' ? Thanks for any thoughts.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: user to swap permissions easily

Post by pbottcher » 2020-10-13 16:21

Hi,

mybe this helps (read till the end)

viewtopic.php?t=2811
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

graham
Veteran Member
Posts: 84
Joined: 2020-09-29 12:30

Re: user to swap permissions easily

Post by graham » 2020-10-14 13:04

Ah! I am so close, thank ... 99% but not quite working.

I followed viewtopic.php?t=2811 and everything looked good.
I added two permission groups GroupA (view only) and GroupB (edit etc) to the App via the standard admin panel.
I allocated Eric to Group A and Bernard to Group B
Then logged into app as admin and in the freshly created groups table can see all users and all Groups.
So I want Bernard to be able to easily switch between GroupA and GroupB
So I added two records in the groups table - Bernard to GroupA and Bernard to GroupB
Then log in as Bernard and I can see the new icon in the menu bar (red circle, head icon and name 'GroupB') and Bernard has his GroupB permissions.
Now I want to swap his permission level to Group A (that's the whole point).
I click the icon and see GroupA dropdown but when I choose it I get:
404 messsage http://xoa143t///change_group.php?User= ... oup=GroupA NOT FOUND
So I've tried various permutations of adding him to A and B across AppGini and in the new groups table but cannot get working.

If you could kindly advise what I need to do to finally nail it, I would be really grateful - aside from this problem the solution seems great.

Thanks, Graham

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: user to swap permissions easily

Post by pbottcher » 2020-10-14 19:24

Hi,

can you try to change the statement in the hooks/header_extras.php file to

Code: Select all

$output .= "<li><a href=\"http://{$host}/{$appURI}/change_group.php?User=".$user."&Group=".$row['groupname']."\">	<small><em>".$row['groupname']."</em></small></a></li>";
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

graham
Veteran Member
Posts: 84
Joined: 2020-09-29 12:30

Re: user to swap permissions easily

Post by graham » 2020-10-15 08:14

I exchanged the code and it has had no effect.
Sorry to be repetitive but I'll just recount in case there is a flaw in my thinking ..
Bernard is a member of Permission GroupB, as set in AppGini admin area
I want him to also be a member of permission GroupA but he can't be member of both unless I give him different username. That's no good because he can't switch easily whilst in the app.
So your solution where he can switch via the dropdown in the top bar is perfect answer.
In the new groups table I have added him as a member of A, or B, or both and all error when you try to switch via the dropdown/icon (http://xoa143t//change_group.php?User=b ... oup=GroupA NOT FOUND)
Sorry to be trouble but it would be really brilliant to get this working if we can.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: user to swap permissions easily

Post by pbottcher » 2020-10-15 18:02

Hi,

actually it does exactly what you want. You need to add your member to both groups in the group table.

Why the href is not working is hard to say without knowing your environment. On my testsystem it works just fine.

In the link you show http://xoa143t/ your host sounds strange. Is your host xoa143t? (no domain ?)
Also, did you put the change_group.php in the root directory of your app?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

graham
Veteran Member
Posts: 84
Joined: 2020-09-29 12:30

Re: user to swap permissions easily

Post by graham » 2020-10-15 19:41

So ... it works!! I had change_group.php in hooks rather than the root directory.
FYI .. XOA143T is just a local name in WAMP.
It's so nice to get some help like this. And I think this feature is a really powerful tool for AppGini.
So thank you for your time, input and patience.

graham
Veteran Member
Posts: 84
Joined: 2020-09-29 12:30

Re: user to swap permissions easily

Post by graham » 2020-10-30 14:25

One small problem - it works perfectly in the normal TV/DV pages. But I've added some custom pages (as per https://bigprof.com/appgini/help/advanc ... cess-pages) and linked them to the main nav menu. If a user tries to switch whilst in one of those pages they get a page not found because when you switch whilst in a custom page, say .../hooks/help.php it tries to find ../hooks/change_group.php?User=eric&Group=Thailand and of course there is no such address. Actually, the user doesn't need to change whilst on a custom page but people will try just because they can and I don't want the error - I just want them to remain on the page and be in their new choosen group ready for when they link to a normal TV. Any thoughts? Thanks.

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: user to swap permissions easily

Post by pbottcher » 2020-10-30 21:37

What code do you have for calling the chagee_group.php?
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

graham
Veteran Member
Posts: 84
Joined: 2020-09-29 12:30

Re: user to swap permissions easily

Post by graham » 2020-10-31 09:31

Well, the only reference in my app to change_group.php is in the code added to header-extras. My custom page(s) has include_once("$hooks_dir/../header.php"); and header-extras is included via header.php. So in my I'm-new-to-this-thinking I thought I was calling the change_group.php through the inclusion of header.php. (But it doesn't work so it looks like my thinking is not right!)

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: user to swap permissions easily

Post by pbottcher » 2020-10-31 15:27

can you post the

hooks/header_extras.php

you use
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

graham
Veteran Member
Posts: 84
Joined: 2020-09-29 12:30

Re: user to swap permissions easily

Post by graham » 2020-10-31 16:15

Sure:

<script src="hooks/AppGiniHelper.min.js"></script>

<script>
new AppGiniCommon().setTitle("<b>PROJECT_</b>DataTool");
</script>

<script>
new AppGiniCommon().setIcon("plus");
</script>

<script>
var common = new AppGiniCommon();
common.autoRedirect();
</script>



<?php
/*This is integral to the ability to swap permission groups from within the app */
if(!defined('PREPEND_PATH')) define('PREPEND_PATH', '');
$user=getLoggedMemberID();
$memberinfo=getMemberInfo();
$maingroup=$memberinfo["group"];

if ($user == "guest") return;

$query = "SELECT groupname from groups where user='".$user."' and groupname != '".$maingroup."'";

$result = sql($query,$eo);
$output="'";

$count = $result->num_rows;
if ($count > 0 ) {
while($row = db_fetch_assoc($result)) {
$output .= "<li><a href=\"change_group.php?User=".$user."&Group=".$row['groupname']."\"> <small><em>".$row['groupname']."</em></small></a></li>";
}
}
else {
$output .= "<li> <small>No additional groups available</small> </a> </li>";
}
$output .="'";
?>

<script type="text/javascript">
var list=<?php echo $output; ?>;
$j('nav .navbar-collapse').append( '<ul class="nav navbar-nav">' +
'<li class="dropdown">' +
'<a href="#" class="dropdown-toggle" data-toggle="dropdown" id="User_Group"><span id="User_Group-count" class="label label-pill label-danger count" style="border-radius:10px;"><?php echo " ".$count; ?></span> <span> <i class="glyphicon glyphicon-user" style="font-size:18px;"></i></span><?php echo " ".$maingroup; ?></a>' +
'<ul class="dropdown-menu" role=menu id="User_Group-text"></ul>' +
'</li>' +
'</ul>' );
$j('#User_Group-text').html(list);

</script>

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: user to swap permissions easily

Post by pbottcher » 2020-10-31 16:56

ok,

can you change

Code: Select all

$output .= "<li><a href=\"change_group.php?User=".$user."&Group=".$row['groupname']."\"> <small><em>".$row['groupname']."</em></small></a>
to

Code: Select all

$output .= "<li><a href=\"http://{$host}/{$appURI}/change_group.php?User=".$user."&Group=".$row['groupname']."\">	<small><em>".$row['groupname']."</em></small></a>
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

graham
Veteran Member
Posts: 84
Joined: 2020-09-29 12:30

Re: user to swap permissions easily

Post by graham » 2020-10-31 17:34

I did that, thank you. The effect is that it doesn't work for the custom pages and it also breaks the ability to swap user on the non-custom pages. So with the code above added, whilst in a non-custom page, the user is taken to, for example, http://change_group.php/?User=wolly&Group=Thailand when attempting to switch user, which is of course 'page not found'. And with the new code added, whilst in a non-custom page, the User gets the same http://change_group.php/?User=wolly&Group=Thailand

pbottcher
AppGini Super Hero
AppGini Super Hero
Posts: 1635
Joined: 2018-04-01 10:12

Re: user to swap permissions easily

Post by pbottcher » 2020-10-31 19:33

ok,

so replace

http://{$host}/{$appURI}

with the path your app.
Any help offered comes with the best of intentions. Use it at your own risk. In any case, please make a backup of your existing environment before applying any changes.

graham
Veteran Member
Posts: 84
Joined: 2020-09-29 12:30

Re: user to swap permissions easily

Post by graham » 2020-11-01 10:54

Ah! ... sorry, I should have worked out that last bit. Of course, it works now - thank you very much.

Post Reply