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

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .hunspell.en.dic
Original file line number Diff line number Diff line change
Expand Up @@ -1155,3 +1155,6 @@ isEnvVarDefined
envVarEquals
setEnvVarIfUndefined
LMSTICKYRULE
Chardon
Jérémy
Déchard
8 changes: 8 additions & 0 deletions NEWS.rst
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ Modules 5.4.0 (not yet released)
#503)
* Init: Improve Tcsh shell completion script to complete against existing
files when pattern starts with ``/``, ``.`` or ``~/``. (fix issue #523)
* Add ``--user`` option to :mfcmd:`module-forbid`, :mfcmd:`module-hide` and
:mfcmd:`module-tag` modulefile commands to forbid, hide or tag only if user
is listed in the value of this new option. (fix issue #520 with contribution
from Jérémy Déchard)
* Add ``--group`` option to :mfcmd:`module-forbid`, :mfcmd:`module-hide` and
:mfcmd:`module-tag` modulefile commands to forbid, hide or tag only if one
user's group is listed in the value of this new option. (fix issue #520 with
contribution from Jérémy Déchard)


.. _5.3 release notes:
Expand Down
18 changes: 13 additions & 5 deletions contrib/nagelfar/syntaxdb_modulefile.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -261,19 +261,27 @@ set {::option(module switch)} {--tag --not-req}
set {::option(module switch --tag)} 1
set {::option(module unuse)} {--remove-on-unload --noop-on-unload\
--append-on-unload --prepend-on-unload}
set ::option(module-forbid) {--not-user --not-group --after --before\
--message --nearly-message}
set ::option(module-forbid) {--user --group --not-user --not-group --after\
--before --message --nearly-message}
set {::option(module-forbid --user)} 1
set {::option(module-forbid --group)} 1
set {::option(module-forbid --not-user)} 1
set {::option(module-forbid --not-group)} 1
set {::option(module-forbid --after)} 1
set {::option(module-forbid --before)} 1
set ::option(module-hide) {--not-user --not-group --after --before --soft\
--hard --hidden-loaded}
set ::option(module-hide) {--user --group --not-user --not-group --after\
--before --soft --hard --hidden-loaded}
set {::option(module-hide --user)} 1
set {::option(module-hide --group)} 1
set {::option(module-hide --not-user)} 1
set {::option(module-hide --not-group)} 1
set {::option(module-hide --after)} 1
set {::option(module-hide --before)} 1
set ::option(module-tag) {--not-user --not-group}
set ::option(module-tag) {--user --group --not-user --not-group}
set {::option(module-tag --user)} 1
set {::option(module-tag --group)} 1
set {::option(module-tag --not-user)} 1
set {::option(module-tag --not-group)} 1
set ::option(prepend-path) {-d --delim --duplicates --ignore-refcount}
set {::option(prepend-path -d)} 1
set {::option(prepend-path --delim)} 1
Expand Down
18 changes: 13 additions & 5 deletions contrib/nagelfar/syntaxdb_modulerc.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,26 @@ set ::subCmd(module-info) {alias command loaded mode name shell shelltype\
set ::subCmd(uname) {sysname nodename domain release version machine}

# option
set ::option(module-forbid) {--not-user --not-group --after --before\
--message --nearly-message}
set ::option(module-forbid) {--user --group --not-user --not-group --after\
--before --message --nearly-message}
set {::option(module-forbid --user)} 1
set {::option(module-forbid --group)} 1
set {::option(module-forbid --not-user)} 1
set {::option(module-forbid --not-group)} 1
set {::option(module-forbid --after)} 1
set {::option(module-forbid --before)} 1
set ::option(module-hide) {--not-user --not-group --after --before --soft\
--hard --hidden-loaded}
set ::option(module-hide) {--user --group --not-user --not-group --after\
--before --soft --hard --hidden-loaded}
set {::option(module-hide --user)} 1
set {::option(module-hide --group)} 1
set {::option(module-hide --not-user)} 1
set {::option(module-hide --not-group)} 1
set {::option(module-hide --after)} 1
set {::option(module-hide --before)} 1
set ::option(module-tag) {--not-user --not-group}
set ::option(module-tag) {--user --group --not-user --not-group}
set {::option(module-tag --user)} 1
set {::option(module-tag --group)} 1
set {::option(module-tag --not-user)} 1
set {::option(module-tag --not-group)} 1

# vim:set tabstop=3 shiftwidth=3 expandtab autoindent:
1 change: 1 addition & 0 deletions doc/source/changes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,7 @@ The following modulefile Tcl commands appeared on Modules 5.
* module specification on which stickiness applies is recorded in loaded
environment to determine if it is still satisfied when updating
environment.
* options ``--user`` and ``--group`` are added.

:mfcmd:`break`

Expand Down
12 changes: 10 additions & 2 deletions doc/source/design/hide-or-forbid-modulefile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,17 @@ Specification
- ``--hard``: highest hiding level
- ``--not-user``: specify a list of users unaffected by hide mechanism
- ``--not-group``: specify a list of groups whose member are unaffected by hide mechanism
- ``--user``: specify a list of users specifically affected by hide mechanism
- ``--group``: specify a list of groups whose member are specifically affected by hide mechanism
- ``--before``: enables hide mechanism until a given date
- ``--after``: enables hide mechanism after a given date

- ``module-forbid`` accepts options that change its behavior:

- ``--not-user``: specify a list of users unaffected by forbid mechanism
- ``--not-group``: specify a list of groups whose member are unaffected by forbid mechanism
- ``--user``: specify a list of users specifically affected by forbid mechanism
- ``--group``: specify a list of groups whose member are specifically affected by forbid mechanism
- ``--before``: enables forbid mechanism until a given date
- ``--after``: enables forbid mechanism after a given date
- ``--message``: supplements error message obtained when trying to evaluate a forbidden module with given text message
Expand Down Expand Up @@ -259,12 +263,16 @@ Specification

- Unless on very specific cases, where a global rc file defines these hidden/forbidden commands for the full path modules

- ``--not-user`` and ``--not-group`` specification is only supported on Unix platform
- ``--user``, ``--group``, ``--not-user`` and ``--not-group`` specification is only supported on Unix platform

- These 2 options raise an error when used on Windows platform
- These options raise an error when used on Windows platform
- In which case relative ``module-hide`` or ``module-forbid`` command is made ineffective as well as remaining content of the modulerc script hosting them
- Error message is clearly seen when trying to load related modules and indicate where to find the erroneous command

- ``--user`` and ``--group`` options prevail over ``--not-user`` and ``--not-group`` options

- When ``--user`` or ``--group`` is set, exclusion list from ``--not-user`` and ``--not-group`` are ignored

- ``--before`` and ``--after`` are also supported by ``module-hide`` to phase-out modules prior to forbid their evaluation

- ``--before`` and ``--after`` accept a date time as value
Expand Down
10 changes: 8 additions & 2 deletions doc/source/design/module-tags.rst
Original file line number Diff line number Diff line change
Expand Up @@ -83,13 +83,19 @@ Defining

- ``--not-user``: specify a list of users unaffected by specified tagging
- ``--not-group``: specify a list of groups whose member are unaffected by specified tagging
- ``--user``: specify a list of users specifically affected by specified tagging
- ``--group``: specify a list of groups whose member are specifically affected by specified tagging

- ``--not-user`` and ``--not-group`` specification is only supported on Unix platform
- ``--user``, ``--group``, ``--not-user`` and ``--not-group`` specification is only supported on Unix platform

- These 2 options raise an error when used on Windows platform
- These options raise an error when used on Windows platform
- In which case relative ``module-tag`` command is made ineffective as well as remaining content of the modulerc script hosting them
- Error message is clearly seen when trying to load related modules and indicate where to find the erroneous command

- ``--user`` and ``--group`` options prevail over ``--not-user`` and ``--not-group`` options

- When ``--user`` or ``--group`` is set, exclusion list from ``--not-user`` and ``--not-group`` are ignored

- ``module-tag`` is intended to be used in modulerc files

- to be easily fetched during ``avail`` sub-command processing
Expand Down
39 changes: 39 additions & 0 deletions doc/source/modulefile.rst
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ the *modulefile* is being loaded.
* ``--before datetime``
* ``--not-user {user...}``
* ``--not-group {group...}``
* ``--user {user...}``
* ``--group {group...}``
* ``--message {text message}``
* ``--nearly-message {text message}``

Expand All @@ -487,6 +489,14 @@ the *modulefile* is being loaded.
specified. When both options are set, forbidding is not applied if a match is
found for ``--not-user`` or ``--not-group``.

If ``--user`` option is set, forbidding is applied only if the username of
the user currently running :file:`modulecmd.tcl` is part of the list of
username specified. Following the same approach, if ``--group`` option is
set, forbidding is applied only if current user is member of one the group
specified. When both options are set, forbidding is applied if a match is
found for ``--user`` or ``--group``. These two options prevail over
``--not-user`` and ``--not-group`` options.

Error message returned when trying to evaluate a forbidden module can be
supplemented with the *text message* set through ``--message`` option.

Expand Down Expand Up @@ -521,6 +531,9 @@ the *modulefile* is being loaded.
.. versionchanged:: 5.4
Full path file name may be used to designate *modulefile*

.. versionchanged:: 5.4
Options ``--user`` and ``--group`` added

.. mfcmd:: module-hide [options] modulefile...

Hide *modulefile* to exclude it from available module search or module
Expand All @@ -535,6 +548,8 @@ the *modulefile* is being loaded.
* ``--before datetime``
* ``--not-user {user...}``
* ``--not-group {group...}``
* ``--user {user...}``
* ``--group {group...}``

When ``--soft`` option is set, *modulefile* is also set hidden, but hiding is
disabled when search or selection query's root name matches module's root
Expand Down Expand Up @@ -569,6 +584,14 @@ the *modulefile* is being loaded.
When both options are set, hiding is not applied if a match is found for
``--not-user`` or ``--not-group``.

If ``--user`` option is set, hiding is applied only if the username of the
user currently running :file:`modulecmd.tcl` is part of the list of username
specified. Following the same approach, if ``--group`` option is set, hiding
is applied only if current user is member of one the group specified. When
both options are set, hiding is applied if a match is found for ``--user`` or
``--group``. These two options prevail over ``--not-user`` and
``--not-group`` options.

If the :option:`--all` option is set on :subcmd:`avail`, :subcmd:`aliases`,
:subcmd:`whatis` or :subcmd:`search` sub-commands, hiding is disabled thus
hidden modulefiles are included in module search. Hard-hidden modules (i.e.,
Expand Down Expand Up @@ -611,6 +634,9 @@ the *modulefile* is being loaded.
.. versionchanged:: 5.4
Full path file name may be used to designate *modulefile*

.. versionchanged:: 5.4
Options ``--user`` and ``--group`` added

.. mfcmd:: module-info option [info-args]

Provide information about the :file:`modulecmd.tcl` program's state. Some of
Expand Down Expand Up @@ -786,6 +812,8 @@ the *modulefile* is being loaded.

* ``--not-user {user...}``
* ``--not-group {group...}``
* ``--user {user...}``
* ``--group {group...}``

If ``--not-user`` option is set, the tag is not applied if the username of
the user currently running :file:`modulecmd.tcl` is part of the list of
Expand All @@ -794,6 +822,14 @@ the *modulefile* is being loaded.
specified. When both options are set, the tag is not applied if a match is
found for ``--not-user`` or ``--not-group``.

If ``--user`` option is set, the tag is applied only if the username of the
user currently running :file:`modulecmd.tcl` is part of the list of username
specified. Following the same approach, if ``--group`` option is set, the tag
is applied only if current user is member of one the group specified. When
both options are set, the tag is applied if a match is found for ``--user``
or ``--group``. These two options prevail over ``--not-user`` and
``--not-group`` options.

The parameter *modulefile* may also be a symbolic modulefile name or a
modulefile alias. It may also leverage a specific syntax to finely select
module version (see `Advanced module version specifiers`_ section below).
Expand Down Expand Up @@ -822,6 +858,9 @@ the *modulefile* is being loaded.
.. versionchanged:: 5.4
Full path file name may be used to designate *modulefile*

.. versionchanged:: 5.4
Options ``--user`` and ``--group`` added

.. mfcmd:: module-version modulefile version-name...

Assigns the symbolic *version-name* to the *modulefile*. This command
Expand Down
29 changes: 22 additions & 7 deletions tcl/mfcmd.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -277,11 +277,11 @@ proc parseApplicationCriteriaArgs {aftbef nearsec args} {
set nextargisdatetime [string trimleft $arg -]
}
}
--not-group - --not-user {
--not-group - --not-user - --group - --user {
if {[getState is_win]} {
knerror "Option '$arg' not supported on Windows platform"
} else {
set nextargisval not[string range $arg 6 end]list
set nextargisval [string map {- {}} $arg]list
}
}
default {
Expand All @@ -296,6 +296,11 @@ proc parseApplicationCriteriaArgs {aftbef nearsec args} {
knerror "Missing value for '$prevarg' option"
}

set user [expr {[info exists userlist] && [getState username] in\
$userlist}]
set group [expr {[info exists grouplist] && [isIntBetweenList\
$grouplist [getState usergroups]]}]

# does it apply to current user?
set notuser [expr {[info exists notuserlist] && [getState username] in\
$notuserlist}]
Expand All @@ -308,13 +313,23 @@ proc parseApplicationCriteriaArgs {aftbef nearsec args} {
set isafter [expr {[info exists after] && [getState clock_seconds] >=\
$after}]

# are criteria met
set apply [expr {!$notuser && !$notgroup && ($isbefore || $isafter ||\
(![info exists before] && ![info exists after]))}]

set user_or_group_target_defined [expr {[info exists userlist] || [info\
exists grouplist]}]
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 in_near_time_frame [expr {[info exists after] && !$isafter &&\
[getState clock_seconds] >= ($after - $nearsec)}]

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

# is end limit near ?
set isnearly [expr {!$apply && !$notuser && !$notgroup && [info exists\
after] && !$isafter && [getState clock_seconds] >= ($after - $nearsec)}]
set isnearly [expr {!$apply && ($user_or_group_targeted ||\
(!$user_or_group_target_defined && !$user_or_group_excluded)) &&\
$in_near_time_frame}]
if {![info exists afterraw]} {
set afterraw {}
}
Expand Down
Loading