def get_user_form(global_config, username):
    global_config['logger'].debug( 'GET User Form For: %s', username )
        
    session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])

    user = UsersDataModel.getUser(session, username)
    form = userform()
    if user:
        form[user_username_label].value = user.username
        form[user_emailaddress_label].value = user.email_address
        form[user_cellphone_label].value = user.cellphone
        form[user_carrier_label].value = user.carrier
        form[user_subgroup_label].value = user.subgroup
        form[user_password_label].value = user.password
        form[user_display_name_label].value = user.display_name
        form[user_role_label].value = user.role
        form[user_contact_mode_label].value = user.contact_mode
        form[user_nickname_label].value = user.altname
        form[user_access_level_label].value = user.access_level
        form[user_state_label].value = user.state
        form[user_taskgroups_label].value = UsersDataModel.getUserTaskgroups(session, user.username)
    else:
        form[user_access_level_label].value = 10
        form[user_role_label].value = 'Guest'

    session.remove()

    return form
def process_delete_user(global_config, username):
    global_config['logger'].debug( 'Process Delete User' )
    
    session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])
    UsersDataModel.deleteUser(session, username)
    session.commit()
    session.remove()

    return '/users'
Beispiel #3
0
def process_delete_user_form(global_config, form):
    global_config['logger'].debug( 'Process Delete User' )
    
    session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])
    username = form[user_username_label].value
    UsersDataModel.deleteUser(session, username)
    session.commit()
    session.close()

    return '/users'
def process_load_user_form(global_config, form):
    global_config['logger'].debug('Process Load Users Form')
                                    
    users_file = './config/' + form[user_file_label].value
    global_config['logger'].debug('Loading Users from file: %s' % users_file)
    
    session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])

    UsersDataModel.add_users_from_file(session, users_file)
    
    session.remove()
    
    return '/users'
def process_user_form(global_config, form, username, my_access_level, new_user=False):
    if new_user == True:
        username = form[user_username_label].value
        
    global_config['logger'].debug( 'Process User Profile For: %s', username )
    
    session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])
                                
    email_address = form[user_emailaddress_label].value
    cellphone = form[user_cellphone_label].value
    carrier = form[user_carrier_label].value
    subgroup = form[user_subgroup_label].value
    
    user = UsersDataModel.getUser(session, username)
    if user:
        if new_user == True:
            raise Exception('User Already Exists!')
            
        # validate the password confirmation only if the user actually changed his
        # password
        if form[user_password_label].value != user.password:
            if form[user_password_label].value != form[user_password_confirm_label].value:
                raise Exception('Passwords Do NOT Match')
        # also make sure to pull username from the database, in case the user
        # provided the nickname
        username = user.username
    password = form[user_password_label].value
    display_name = form[user_display_name_label].value
    role = form[user_role_label].value
    contact_mode = form[user_contact_mode_label].value
    nickname = form[user_nickname_label].value
    access_level = int(form[user_access_level_label].value)
    if access_level == 0:
        if my_access_level >0: 
            raise Exception('Only Supreme Admins (aka NOT you) can set access level to 0')
    taskgroups = form[user_taskgroups_label].value
    state = form[user_state_label].value
    
    UsersDataModel.addOrUpdateUser(session, username, email_address, 
                                          cellphone, carrier, subgroup, password, 
                                          display_name, role, contact_mode, nickname,
                                          access_level, state)

    UsersDataModel.updateUserTaskgroups(session, username, taskgroups)
        
    session.commit()
    session.remove()
    return '/users'
def auth_user(global_config, desired_path='/home'):
    auth = web.ctx.env.get('HTTP_AUTHORIZATION')
    authreq = False
    
    if auth is None:
        authreq = True
    else:
        auth = re.sub('^Basic ','',auth)
        username,password = base64.decodestring(auth).split(':')
        
        if logged_out_users.has_key(username):
            del logged_out_users[username]
        else:
            session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])
            user = UsersDataModel.getUser(session, username)
            session.remove()
            if user:
                if user.state == 'Disabled':
                    raise web.seeother('/accountdisabled')
                #if (username,password) in allowed:
                if user.check_password(password) == True:
                    raise web.seeother(desired_path)
        authreq = True
    if authreq:
        web.header('WWW-Authenticate','Basic realm="FRC1073 ScoutingAppCentral"')
        web.ctx.status = '401 Unauthorized'
        return
 def GET(self, name):
     email_lists = UsersDataModel.getTaskgroupEmailLists(global_config, name)
     taskgroups_filename = './static/data/ScoutingConfig/TaskGroupEmailLists.txt'
     fd = open(taskgroups_filename, 'w+')
     fd.write( email_lists )
     fd.close()
     return email_lists
Beispiel #8
0
def get_issue_form(global_config, issue_id):
    global_config['logger'].debug( 'GET Issue Form, Issue: %s', issue_id )
        
    session = DbSession.open_db_session(global_config['issues_db_name'] + global_config['this_season'])
    users_session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])

    issue_id = issue_id
    platform = issue_id.split('-')[0]
    issue = IssueTrackerDataModel.getIssue(session, issue_id)
    
    form = issueform()
    form[issue_id_label].value = issue_id
    form[issue_platform_label].value = platform
    form[issue_summary_label].value = issue.summary
    form[issue_status_label].value = issue.status
    form[issue_priority_label].value = issue.priority
    
    # TODO: can also extract the subgroup and taskgroup(component) lists from the 
    #       database and override the form with the contents
    #       IssueTrackerDataModel.getSubgroupList() and getTaskgroupList()
    form[issue_subgroup_label].value = issue.subgroup
    form[issue_component_label].value = issue.component
    
    # apply the valid list of user names to the dropdown 
    # for the owner field and the submitter field
    username_list = UsersDataModel.getDisplayNameList(users_session)
    form[issue_owner_label].args = username_list
    form[issue_submitter_label].args = username_list

    form[issue_owner_label].value = issue.owner
    form[issue_submitter_label].value = issue.submitter
    form[issue_description_label].value = issue.description

    return form
def get_user_list_json(global_config):
    
    global_config['logger'].debug( 'GET User List' )
    session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])

    user_list = UsersDataModel.getUserList(session)
    session.remove()
    
    web.header('Content-Type', 'application/json')
    result = []

    result.append('{  "users" : [\n')

    for user in user_list:
        result.append('   { "username": "******", "email_address": "%s", "display_name": "%s", "nickname": "%s", "access_level": "%s", \
"role": "%s", "subgroup": "%s", "contact_mode": "%s", "cellphone": "%s", "carrier": "%s", "state": "%s" }' % \
(user.username,user.email_address,user.display_name,user.altname, user.access_level, user.role, user.subgroup, user.contact_mode, user.cellphone, user.carrier, user.state))
        
        result.append(',\n')

    if len(user_list) > 0:         
        result = result[:-1]

    result.append(' ] }\n')
    return ''.join(result)
def get_user_list_page(global_config):
 
    session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])

    result = ''
    result += '<hr>'
    result += '<br>'
    result += '<a href="/newuser"> Create New User</a></td>'
    result += '<br>'
    result += '<a href="/deleteuser"> Delete User</a></td>'
    result += '<br>'
    result += '<a href="/loadusers"> Load Users From File</a></td>'
    result += '<br>'
    result += '<br>'
    result += '<hr>'
    
    users = UsersDataModel.getUsers(session)
    user_list = UsersDataModel.getUserList(session)
    result += insert_users_table(user_list)

    session.remove()
    return result
def process_userprofile_form(global_config, form, username):
    global_config['logger'].debug( 'Process User Profile For: %s', username )
    
    session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])
                                
    email_address = form[user_emailaddress_label].value
    cellphone = form[user_cellphone_label].value
    carrier = form[user_carrier_label].value
    subgroup = form[user_subgroup_label].value
    
    # set default access level and rols, and override if the user is already in the system
    access_level = 5
    role = 'Guest'
    user = UsersDataModel.getUser(session, username)
    if user:
        # validate the password confirmation only if the user actually changed his
        # password
        if form[user_password_label].value != user.password:
            if form[user_password_label].value != form[user_password_confirm_label].value:
                raise Exception('Passwords Do NOT Match')

        access_level = user.access_level
        role = user.role
        state = user.state
        
    password = form[user_password_label].value
    display_name = form[user_display_name_label].value
    contact_mode = form[user_contact_mode_label].value
    nickname = form[user_nickname_label].value
                    
    UsersDataModel.addOrUpdateUser(session, username, email_address, 
                                          cellphone, carrier, subgroup, password, 
                                          display_name, role, contact_mode, nickname,
                                          access_level, state)
    session.commit()
    session.remove()

    return '/home'
def get_delete_user_form(global_config):
    global_config['logger'].debug( 'GET Delete User Form' )
        
    session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])

    form = deleteuserform()

    # apply the valid list of user names to the dropdown 
    # for the username field
    username_list = UsersDataModel.getUsernameList(session)
    form[user_username_label].args = username_list
    form[user_username_label].args = username_list

    session.remove()

    return form
Beispiel #13
0
def check_access(global_config, access_level):
    auth = web.ctx.env.get('HTTP_AUTHORIZATION')
    
    if auth is None:
        raise web.seeother('/login?path=%s' % web.ctx.path)
    else:
        auth = re.sub('^Basic ','',auth)
        username,password = base64.decodestring(auth).split(':')
        
        # here is where we need to do a lookup in the user database and see if the
        # user is authorized to access this page.
        session = DbSession.open_db_session(global_config['users_db_name'])
        user = UsersDataModel.getUser(session, username)
        if user:
            if user.check_access_level(access_level) == True:
                return (username,user.access_level)
            
        raise web.seeother('/accessdenied')
def get_userprofile_form(global_config, username):
    global_config['logger'].debug( 'GET User Form For: %s', username )
        
    session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])

    user = UsersDataModel.getUser(session, username)
    
    form = userprofileform()
    form[user_username_label].value = user.username
    form[user_emailaddress_label].value = user.email_address
    form[user_cellphone_label].value = user.cellphone
    form[user_carrier_label].value = user.carrier
    form[user_subgroup_label].value = user.subgroup
    form[user_password_label].value = user.password
    form[user_display_name_label].value = user.display_name
    form[user_contact_mode_label].value = user.contact_mode
    form[user_nickname_label].value = user.altname

    session.remove()

    return form
Beispiel #15
0
def get_new_issue_form(global_config, platform_type=None):
    global_config['logger'].debug( 'GET New Issue Form' )
        
    users_session = DbSession.open_db_session(global_config['users_db_name'] + global_config['this_season'])

    form = new_issueform()

    # apply the valid list of user names to the dropdown 
    # for the owner field and the submitter field
    username_list = UsersDataModel.getDisplayNameList(users_session)
    form[issue_owner_label].args = username_list
    form[issue_submitter_label].args = username_list
    
    # if the platform type is specified, then constrain the platform to that value
    if platform_type != None:
        form[issue_platform_label].args = [ platform_type ]

    # TODO: can also extract the subgroup and taskgroup(component) lists from the 
    #       database and override the form with the contents
    #       IssueTrackerDataModel.getSubgroupList() and getTaskgroupList()
    
    return form
            if not os.path.isdir(base_dir):
                raise

    input_dir = './static/data/' + competition + '/ScoutingData/'
        
    db_name = global_config['db_name']
    issues_db_name = global_config['issues_db_name']
    debriefs_db_name = global_config['debriefs_db_name']
    users_db_name = global_config['users_db_name']
    session         = DbSession.open_db_session(db_name, DataModel)
    issues_session  = DbSession.open_db_session(issues_db_name, IssueTrackerDataModel)
    debrief_session = DbSession.open_db_session(debriefs_db_name, DebriefDataModel)
    users_session = DbSession.open_db_session(users_db_name, UsersDataModel)
        
    # make sure that there is a default admin user. If no admin user exists, then create one
    if UsersDataModel.getUser( users_session, 'admin' ) is None:
        UsersDataModel.create_admin_user(users_session, 'squirrel!')

    # Build the attribute definition dictionary from the definitions csv file
    attrdef_filename = './config/' + global_config['attr_definitions']    
    attr_definitions = AttributeDefinitions.AttrDefinitions()
    attr_definitions.parse(attrdef_filename)

    if options.processfiles:
        competition = global_config['this_competition'] + global_config['this_season']
        try:
            process_files(session, db_name, attr_definitions, input_dir, options.recursive, options.test)
            dump_database_as_csv_file(session, attr_definitions, competition)
        except Exception, e:
            global_config['logger'].debug('Exception Caught Processing Files: %s' % str(e) )
            traceback.print_exc(file=sys.stdout)
    # we need a temporary directory, so make sure that it exists
    tmp_dir = './tmp'
    try: 
        os.makedirs(tmp_dir)
    except OSError:
        if not os.path.isdir(tmp_dir):
            raise
    
    # load the users file if one is specified
    if options.users_file != '':
        users_file = './config/' + options.users_file
        
        if not users_file.endswith('.xlsx'):
            users_file += '.xlsx'
        logger.debug('Loading Users from file: %s' % users_file)
        UsersDataModel.add_users_from_file(users_session, users_file)

    # make sure that there is a default admin user. If no admin user exists, then create one
    if UsersDataModel.getUser( users_session, 'admin' ) is None:
        UsersDataModel.create_admin_user(users_session, 'squirrel!')

    session.close()
    issues_session.close()
    debrief_session.close()
    users_session.close()
    

    # Build the attribute definition dictionary from the definitions spreadsheet file
    if global_config['attr_definitions'] != None:
        attrdef_filename = './config/' + global_config['attr_definitions']
        if os.path.exists(attrdef_filename):
        
    myfile = './config/Users-2013.xlsx'
    user_definitions = UserDefinitions()
    # create the user definition dictionary from the csv file
    user_definitions.parse(myfile)
    print user_definitions
        
    db_name = 'Issues2013'
    db_connect='sqlite:///%s'%(db_name)
    my_db = create_engine(db_connect)
    Session = sessionmaker(bind=my_db)
    session = Session()

    # Create the database if it doesn't already exist
    if not os.path.exists('./' + db_name):    
        UsersDataModel.create_db_tables(my_db)

    users = user_definitions.get_definitions()
    for user, definition in users.iteritems():
        UsersDataModel.addUserFromAttributes(session, definition)
    
    session.commit()
    
    taskgroups = UsersDataModel.getTaskgroupList(session)
    print taskgroups
    for group in taskgroups:
        print group
        members = UsersDataModel.getTaskgroupMembers(session,group)
        print members
    
    subgroups = UsersDataModel.getSubgroupList(session)