Changeset 2762

Show
Ignore:
Timestamp:
02/27/06 23:28:01 (18 years ago)
Author:
jerome
Message:

Make pkusers --list behave like edpykota --list : allowed to normal users,
but restricted in what can be seen.

Location:
pykota/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • pykota/trunk/bin/edpykota

    r2761 r2762  
    2727import sys 
    2828import os 
    29 import pwd 
    30 import grp 
    31 import time 
     29 
    3230from pykota.tool import PyKotaTool, PyKotaToolError, PyKotaCommandLineError, crashed, N_ 
    3331from pykota.config import PyKotaConfigError 
     
    174172    def main(self, names, options) : 
    175173        """Edit user or group quotas.""" 
    176         if not self.config.isAdmin : 
    177             username = pwd.getpwuid(os.geteuid())[0] 
    178             if not options["list"] : 
    179                 raise PyKotaCommandLineError, "%s : %s" % (username, _("You're not allowed to use this command.")) 
    180             else : 
    181                 names = [ username ] 
    182                 if options["groups"] : 
    183                     user = self.storage.getUser(username) 
    184                     if user.Exists : 
    185                         names = [ g.Name for g in self.storage.getUserGroups(user) ] 
    186         elif not names :         
    187             names = ["*"] 
    188              
     174        names = self.sanitizeNames(options, names) 
    189175        suffix = (options["groups"] and "Group") or "User"         
    190176        printernames = options["printer"].split(",") 
  • pykota/trunk/bin/pkusers

    r2757 r2762  
    160160    def main(self, names, options) : 
    161161        """Manage users or groups.""" 
    162         if not self.config.isAdmin : 
    163             raise PyKotaCommandLineError, "%s : %s" % (pwd.getpwuid(os.geteuid())[0], _("You're not allowed to use this command.")) 
    164              
     162        names = self.sanitizeNames(options, names) 
    165163        suffix = (options["groups"] and "Group") or "User"         
    166164         
     
    230228                self.display("\r100.00%%\r        \r%s\n" % _("Done.")) 
    231229            else :         
    232                 if not names : 
    233                     names = ["*"] 
    234230                entries = getattr(self.storage, "getMatching%ss" % suffix)(",".join(names)) 
    235231                if not entries : 
     
    407403        elif options["remove"] and not options["ingroups"] :     
    408404            raise PyKotaCommandLineError, _("You have to pass user groups names on the command line") 
    409         elif (not args) and options["add"] : 
     405        elif (not args) and (options["add"] or options["delete"]) : 
    410406            raise PyKotaCommandLineError, _("You have to pass user or group names on the command line") 
    411407        else : 
  • pykota/trunk/NEWS

    r2760 r2762  
    2323        
    2424    - 1.24alpha15 : 
    25      
    26         - edpykota --list is now authorized to mere mortal users, but 
    27           restricts the list to the current user's information. 
     25         
     26        - 'edpykota --list' and 'pkusers --list' are now authorized  
     27          to mere mortal users, but the list is restricted to informations 
     28          about the current user. 
    2829         
    2930        - Extended the functionnality of the 'onbackenderror' directive to 
  • pykota/trunk/pykota/tool.py

    r2692 r2762  
    220220                    return True 
    221221            return False 
     222         
     223    def sanitizeNames(self, options, names) : 
     224        """Ensures that an user can only see the datas he is allowed to see, by modifying the list of names.""" 
     225        if not self.config.isAdmin : 
     226            username = pwd.getpwuid(os.geteuid())[0] 
     227            if not options["list"] : 
     228                raise PyKotaCommandLineError, "%s : %s" % (username, _("You're not allowed to use this command.")) 
     229            else : 
     230                if options["groups"] : 
     231                    user = self.storage.getUser(username) 
     232                    if user.Exists : 
     233                        return [ g.Name for g in self.storage.getUserGroups(user) ] 
     234                return [ username ] 
     235        elif not names :         
     236            return ["*"] 
     237        else :     
     238            return names 
    222239         
    223240    def display_version_and_quit(self) :