<s> import re <EOL> from synapse . resources . resources import ResourcesController <EOL> from synapse . logger import logger <EOL> @ logger <EOL> class UsersController ( ResourcesController ) : <EOL> __resource__ = "<STR_LIT>" <EOL> def read ( self , res_id = None , attributes = None ) : <EOL> return self . module . get_user_infos ( res_id ) <EOL> def create ( self , res_id = None , attributes = None ) : <EOL> password = attributes . get ( '<STR_LIT:password>' ) <EOL> login_group = attributes . get ( '<STR_LIT>' ) <EOL> groups = self . _sanitize_groups ( attributes . get ( '<STR_LIT>' , [ ] ) ) <EOL> homedir = attributes . get ( '<STR_LIT>' ) or '<STR_LIT>' % res_id <EOL> comment = attributes . get ( '<STR_LIT>' ) <EOL> uid = "<STR_LIT:%s>" % attributes . get ( '<STR_LIT>' , '<STR_LIT>' ) or '<STR_LIT>' <EOL> gid = "<STR_LIT:%s>" % attributes . get ( '<STR_LIT>' , '<STR_LIT>' ) or '<STR_LIT>' <EOL> shell = attributes . get ( '<STR_LIT>' ) <EOL> self . module . user_add ( res_id , password , login_group , groups , <EOL> homedir , comment , uid , gid , shell ) <EOL> if not uid : <EOL> uid = self . module . get_user_infos ( res_id ) [ '<STR_LIT>' ] <EOL> if not gid : <EOL> gid = self . module . get_user_infos ( res_id ) [ '<STR_LIT>' ] <EOL> if not shell : <EOL> shell = self . module . get_user_infos ( res_id ) [ '<STR_LIT>' ] <EOL> state = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT:password>' : self . module . get_pw ( res_id ) , <EOL> '<STR_LIT>' : groups . append ( login_group ) , <EOL> '<STR_LIT>' : homedir , <EOL> '<STR_LIT>' : comment , <EOL> '<STR_LIT>' : uid , <EOL> '<STR_LIT>' : gid , <EOL> '<STR_LIT>' : shell <EOL> } <EOL> self . save_state ( res_id , state , monitor = monitor ) <EOL> return self . read ( res_id ) <EOL> def update ( self , res_id = None , attributes = None ) : <EOL> monitor = attributes . get ( '<STR_LIT>' ) <EOL> if monitor is False : <EOL> self . comply ( monitor = False ) <EOL> return "<STR_LIT>" % res_id <EOL> password = attributes . get ( "<STR_LIT:password>" ) <EOL> login_group = attributes . get ( "<STR_LIT>" ) <EOL> groups = self . _sanitize_groups ( attributes . get ( '<STR_LIT>' , [ ] ) ) <EOL> homedir = attributes . get ( '<STR_LIT>' ) <EOL> move_home = attributes . get ( '<STR_LIT>' ) <EOL> comment = attributes . get ( '<STR_LIT>' ) <EOL> uid = "<STR_LIT:%s>" % attributes . get ( '<STR_LIT>' ) <EOL> gid = "<STR_LIT:%s>" % attributes . get ( '<STR_LIT>' ) <EOL> shell = attributes . get ( '<STR_LIT>' ) <EOL> if self . module . user_exists ( res_id ) : <EOL> self . module . user_mod ( res_id , password , login_group , groups , <EOL> homedir , move_home , comment , uid , gid , shell ) <EOL> state = { <EOL> '<STR_LIT>' : True , <EOL> '<STR_LIT:password>' : self . module . get_pw ( res_id ) , <EOL> '<STR_LIT>' : groups . append ( login_group ) , <EOL> '<STR_LIT>' : homedir , <EOL> '<STR_LIT>' : comment , <EOL> '<STR_LIT>' : uid , <EOL> '<STR_LIT>' : gid , <EOL> '<STR_LIT>' : shell <EOL> } <EOL> self . save_state ( res_id , state , monitor = monitor ) <EOL> self . response = self . module . get_user_infos ( res_id ) <EOL> else : <EOL> self . response = self . create ( res_id = res_id , attributes = attributes ) <EOL> return self . read ( res_id ) <EOL> def delete ( self , res_id = None , attributes = None ) : <EOL> monitor = attributes . get ( '<STR_LIT>' ) <EOL> state = { '<STR_LIT>' : False } <EOL> self . save_state ( res_id , state , monitor = monitor ) <EOL> self . module . user_del ( res_id ) <EOL> return self . read ( res_id ) <EOL> def _sanitize_groups ( self , groups ) : <EOL> group_list = [ ] <EOL> if groups : <EOL> group_list = re . sub ( '<STR_LIT>' , '<STR_LIT>' , groups ) . split ( '<STR_LIT:U+002C>' ) <EOL> return group_list <EOL> def is_compliant ( self , persisted_state , current_state ) : <EOL> compliant = True <EOL> name = persisted_state . get ( '<STR_LIT:name>' ) <EOL> for key in persisted_state . keys ( ) : <EOL> if key == '<STR_LIT:password>' : <EOL> if persisted_state [ '<STR_LIT:password>' ] != self . module . get_pw ( name ) : <EOL> compliant = False <EOL> else : <EOL> if current_state . get ( key ) != persisted_state [ key ] : <EOL> compliant = False <EOL> return compliant </s>
