Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#520 explicit user group for module hide forbid tag #521

Conversation

jdechard
Copy link
Contributor

Open PR to review code for explicit user/ group option in module-{hide,forbid,tag} command (see issue here..

Code review needed to not use the boolean flag.

@jdechard
Copy link
Contributor Author

Hi Xavier,

PR done, sorry for the delay.

Thank you for your suggestion for appIyand isnearly. In fact this was my first try 2 weeks ago and it works well only for the user/ group used in the module-{hide,forbid,tag} command.

I use the following test:

  • user alan belonging to groupA
  • user bill belonging to groupB
  • a .modulerc file hiding the foo application with the different option set
  • The table below sums up what we should get:
module-hide option bool user for alan bool not-user for alan wanted apply for alan bool user for bill bool not-user for bill wanted apply for bill
--user alan 1 0 1 0 0 0
--not-user alan 0 1 1 0 0 0

And of course the same apply to the groupoption.
With:

set apply [expr {($user || $group || (!$notuser && !$notgroup)) &&\
   ($isbefore || $isafter || (![info exists before] && ![info exists\
   after]))}]

apply=1 all the time for bill due to the ORoperator between user/groupand notuser/notgroupbooleans. I tried different unique expressions without success so far... There is maybe something that I don't see here...

@xdelaruelle
Copy link
Collaborator

xdelaruelle commented Jan 15, 2024 via email

@jdechard
Copy link
Contributor Author

The .modulerc is trivial and contains only the different options:

#%Module
# Comment/Uncomment to test the different options

module-hide --user alan foo
#module-hide --not-user alan foo
#module-hide --group groupA foo
#module-hide --not-group groupA foo

@xdelaruelle
Copy link
Collaborator

With module-hide --not-user alan, it should not apply to alan but it should apply for bill. The table example should be updated this way:

module-hide option bool user for alan bool not-user for alan wanted apply for alan bool user for bill bool not-user for bill wanted apply for bill
--user alan 1 0 1 0 0 0
--not-user alan 0 1 0 0 0 1

If we split Tcl code a bit, it may be simpler to build the accurate apply expression.

    set user_or_group_target_defined [expr {[info exists user] || [info exists\
       group]}]
    set user_or_group_targeted [expr {$user || $group}]
    set user_or_group_excluded [expr {$notuser || $notgroup}]
    set time_frame_defined [expr {[info exists before] || [info exists after]}]
    set in_time_frame [expr {!$time_frame_defined || $isbefore || $isafter}]
                                                                         
    set apply [expr {$in_time_frame && ($user_or_group_targeted ||\
       (!$user_or_group_target_defined && !$user_or_group_excluded))}]

User or group exclusion should be skipped if a user or group target is defined.

This code seems to work with the few examples I have tried.

@jdechard
Copy link
Contributor Author

jdechard commented Jan 22, 2024

Hello Xavier,

Thank you for the good catch and to break down the Tcl code!

From my test user_or_group_target_defined equals 1 even when it should not (see bold in the table).

module-hide option` variables for alan variables for bill
--user alan user=1
notuser=0
group=0
notgroup=0
user_or_group_target_defined=1
user_or_group_targeted=1
user_or_group_excluded=0
time_frame_defined=0
in_time_frame=1
apply=1
user=0
notuser=0
group=0
notgroup=0
user_or_group_target_defined=1
user_or_group_targeted=0
user_or_group_excluded=0
time_frame_defined=0
in_time_frame=1
apply=0
--not-user alan user=0
notuser=1
group=0
notgroup=0
user_or_group_target_defined=1
user_or_group_targeted=0
user_or_group_excluded=1
time_frame_defined=0
in_time_frame=1
apply=0
user=0
notuser=0
group=0
notgroup=0
user_or_group_target_defined=1
user_or_group_targeted=0
user_or_group_excluded=0
time_frame_defined=0
in_time_frame=1
apply=0 (wrong)

If I correct the user_or_group_target_defined value, the apply expression seems to work well!

I'll try to look into that (maybe a typo that I don't see yet) and find out a valid isnearly expression.

Regards,

@xdelaruelle
Copy link
Collaborator

Hello Jeremy,

I made an error on the definition of the user_or_group_target_defined variable. It should rely on userlist and grouplist instead of user and group variable.

    set user_or_group_target_defined [expr {[info exists userlist] || [info\
       exists grouplist]}]

To help clarify isnearly definition, a in_near_time_frame intermediate variable may be defined:

    set in_near_time_frame [expr {[info exists after] && !$isafter &&\              
       [getState clock_seconds] >= ($after - $nearsec)}]

I think isnearly could then be defined this way (but I have not tested it):

    set isnearly [expr {!$apply && ($user_or_group_targeted ||\                     
       (!$user_or_group_target_defined && !$user_or_group_excluded)) &&\            
       $in_near_time_frame}]

Regards,
Xavier

@xdelaruelle
Copy link
Collaborator

@jdechard I am taking over this pull request. I will finish tests and documentation soon, so this change will be part of 5.4

@jdechard
Copy link
Contributor Author

Hello Xavier,

Sorry to not have answer sooner (little bit busy) , your suggestions seem to work well on my test with alan and bill but I did not tested completely all the time option possibilities.

Many thanks for you help :)

Regards

@xdelaruelle xdelaruelle force-pushed the Issue#520_Explicit_user_group_for_module-hide_forbid_tag branch from 7a3ac8a to 91b4de7 Compare February 19, 2024 18:19
Copy link

codecov bot commented Feb 19, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (80c460d) 99.60% compared to head (91b4de7) 99.60%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #521   +/-   ##
=======================================
  Coverage   99.60%   99.60%           
=======================================
  Files          14       14           
  Lines        5123     5123           
=======================================
  Hits         5103     5103           
  Misses         20       20           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@xdelaruelle xdelaruelle merged commit 5b7245e into envmodules:main Feb 19, 2024
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants