def make_blue(user): change = False logger.debug("Ensuring user %s has blue permissions and groups." % user) # ensure user is not a member if check_if_user_has_permission(user, 'member'): logger.info( "Removing user %s member permission to transition to blue" % user) remove_member_permission(user, 'blue_member') change = True member_group, c = Group.objects.get_or_create( name=settings.DEFAULT_AUTH_GROUP) if member_group in user.groups.all(): logger.info("Removing user %s member group" % user) user.groups.remove(member_group) change = True # make blue if check_if_user_has_permission(user, 'blue_member') is False: logger.info("Adding user %s blue permission" % user) add_member_permission(user, 'blue_member') change = True blue_group, c = Group.objects.get_or_create( name=settings.DEFAULT_BLUE_GROUP) if not blue_group in user.groups.all(): logger.info("Adding user %s to blue group" % user) user.groups.add(blue_group) change = True auth, c = AuthServicesInfo.objects.get_or_create(user=user) if auth.is_blue is False: logger.info("Marking user %s as blue" % user) auth.is_blue = True auth.save() change = True assign_corp_group(auth) assign_alliance_group(auth) return change
def make_blue(user): change = False logger.debug("Ensuring user %s has blue permissions and groups." % user) # ensure user is not a member if check_if_user_has_permission(user, 'member'): logger.info("Removing user %s member permission to transition to blue" % user) remove_member_permission(user, 'blue_member') change = True member_group, c = Group.objects.get_or_create(name=settings.DEFAULT_AUTH_GROUP) if member_group in user.groups.all(): logger.info("Removing user %s member group" % user) user.groups.remove(member_group) change = True # make blue if check_if_user_has_permission(user, 'blue_member') is False: logger.info("Adding user %s blue permission" % user) add_member_permission(user, 'blue_member') change = True blue_group, c = Group.objects.get_or_create(name=settings.DEFAULT_BLUE_GROUP) if not blue_group in user.groups.all(): logger.info("Adding user %s to blue group" % user) user.groups.add(blue_group) change = True auth, c = AuthServicesInfo.objects.get_or_create(user=user) if auth.is_blue is False: logger.info("Marking user %s as blue" % user) auth.is_blue = True auth.save() change = True assign_corp_group(auth) assign_alliance_group(auth) return change
def main_character_change(request, char_id): if EveManager.check_if_character_owned_by_user(char_id, request.user): previousmainid = AuthServicesInfoManager.get_auth_service_info(request.user).main_char_id AuthServicesInfoManager.update_main_char_Id(char_id, request.user) # Check if character is in the alliance character_info = EveManager.get_character_by_id(char_id) corporation_info = EveManager.get_corporation_info_by_id(character_info.corporation_id) if EveManager.get_charater_alliance_id_by_id(char_id) == settings.ALLIANCE_ID: add_member_permission(request.user, 'alliance_member') add_user_to_group(request.user, settings.DEFAULT_ALLIANCE_GROUP) add_user_to_group(request.user, generate_corp_group_name(EveManager.get_character_by_id(char_id).corporation_name)) elif corporation_info != None: if corporation_info.is_blue: add_member_permission(request.user, 'blue_member') add_user_to_group(request.user, settings.DEFAULT_BLUE_GROUP) AuthServicesInfoManager.update_is_blue(True, request.user) else: if check_if_user_has_permission(request.user, 'alliance_member'): disable_alliance_member(request.user, previousmainid) if check_if_user_has_permission(request.user, 'blue_member'): disable_blue_member(request.user) else: # TODO: disable serivces if check_if_user_has_permission(request.user, 'alliance_member'): disable_alliance_member(request.user, previousmainid) if check_if_user_has_permission(request.user, 'blue_member'): disable_blue_member(request.user) return HttpResponseRedirect("/characters") return HttpResponseRedirect("/characters")
def make_blue(user): logger.debug("Ensuring user %s has blue permissions and groups." % user) # ensure user is not a member if check_if_user_has_permission(user, "member"): logger.info("Removing user %s member permission to transition to blue" % user) remove_member_permission(user, "blue_member") member_group, c = Group.objects.get_or_create(name=settings.DEFAULT_AUTH_GROUP) if member_group in user.groups.all(): logger.info("Removing user %s member group" % user) user.groups.remove(member_group) # make blue if check_if_user_has_permission(user, "blue_member") is False: logger.info("Adding user %s blue permission" % user) add_member_permission(user, "blue_member") blue_group, c = Group.objects.get_or_create(name=settings.DEFAULT_BLUE_GROUP) if not blue_group in user.groups.all(): logger.info("Adding user %s to blue group" % user) user.groups.add(blue_group) auth, c = AuthServicesInfo.objects.get_or_create(user=user) if auth.is_blue is False: logger.info("Marking user %s as blue" % user) auth.is_blue = True auth.save() for g in user.groups.all(): if str.startswith(str(g.name), "Corp_"): logger.info("Removing blue user %s from corp group %s" % (user, g)) user.groups.remove(g)
def activate_teamspeak3(request): logger.debug("activate_teamspeak3 called by user %s" % request.user) authinfo = AuthServicesInfoManager.get_auth_service_info(request.user) character = EveManager.get_character_by_id(authinfo.main_char_id) if check_if_user_has_permission(request.user, "blue_member"): logger.debug( "Adding TS3 user for blue user %s with main character %s" % (request.user, character)) result = Teamspeak3Manager.add_blue_user(character.character_name, character.corporation_ticker) else: logger.debug("Adding TS3 user for user %s with main character %s" % (request.user, character)) result = Teamspeak3Manager.add_user(character.character_name, character.corporation_ticker) # if its empty we failed if result[0] is not "": AuthServicesInfoManager.update_user_teamspeak3_info( result[0], result[1], request.user) logger.debug( "Updated authserviceinfo for user %s with TS3 credentials. Updating groups." % request.user) update_teamspeak3_groups(request.user) logger.info("Succesfully activated TS3 for user %s" % request.user) return HttpResponseRedirect("/services/") logger.error("Unsuccessful attempt to activate TS3 for user %s" % request.user) return HttpResponseRedirect("/dashboard")
def fatlink_monthly_personal_statistics_view(request, year, month, char_id=None): year = int(year) month = int(month) start_of_month = datetime.datetime(year, month, 1) start_of_next_month = first_day_of_next_month(year, month) start_of_previous_month = first_day_of_previous_month(year, month) if check_if_user_has_permission(request.user, 'fleetactivitytracking_statistics') and char_id: user = EveCharacter.objects.get(character_id=char_id).user else: user = request.user logger.debug("Personal monthly statistics view for user %s called by %s" % (user, request.user)) personal_fats = Fat.objects.filter(user=user).filter(fatlink__fatdatetime__gte = start_of_month).filter(fatlink__fatdatetime__lt = start_of_next_month) ship_statistics = dict() n_fats = 0 for fat in personal_fats: ship_statistics[fat.shiptype] = ship_statistics.setdefault(fat.shiptype, 0) + 1 n_fats += 1 context = {'user': user, 'shipStats':sorted(ship_statistics.items()), 'month':start_of_month.strftime("%h"), 'year':year, 'n_fats': n_fats, 'char_id': char_id, 'previous_month': start_of_previous_month, 'next_month': start_of_next_month} created_fats = Fatlink.objects.filter(creator=user).filter(fatdatetime__gte = start_of_month).filter(fatdatetime__lt = start_of_next_month) context["created_fats"] = created_fats context["n_created_fats"] = len(created_fats) return render_to_response('registered/fatlinkpersonalmonthlystatisticsview.html', context, context_instance=RequestContext(request))
def reset_teamspeak3_perm(request): logger.debug("reset_teamspeak3_perm called by user %s" % request.user) authinfo = AuthServicesInfoManager.get_auth_service_info(request.user) character = EveManager.get_character_by_id(authinfo.main_char_id) logger.debug("Deleting TS3 user for user %s" % request.user) Teamspeak3Manager.delete_user(authinfo.teamspeak3_uid) remove_all_syncgroups_for_service(request.user, "teamspeak3") if check_if_user_has_permission(request.user, "blue_member"): logger.debug("Generating new permission key for blue user %s with main character %s" % (request.user, character)) result = Teamspeak3Manager.generate_new_blue_permissionkey(authinfo.teamspeak3_uid, character.character_name, character.corporation_ticker) else: logger.debug("Generating new permission key for user %s with main character %s" % (request.user, character)) result = Teamspeak3Manager.generate_new_permissionkey(authinfo.teamspeak3_uid, character.character_name, character.corporation_ticker) # if blank we failed if result != "": AuthServicesInfoManager.update_user_teamspeak3_info(result[0], result[1], request.user) logger.debug("Updated authserviceinfo for user %s with TS3 credentials. Updating groups." % request.user) update_teamspeak3_groups(request.user) logger.info("Successfully reset TS3 permission key for user %s" % request.user) return HttpResponseRedirect("/services/") logger.error("Unsuccessful attempt to reset TS3 permission key for user %s" % request.user) return HttpResponseRedirect("/")
def reset_teamspeak3_perm(request): logger.debug("reset_teamspeak3_perm called by user %s" % request.user) authinfo = AuthServicesInfoManager.get_auth_service_info(request.user) character = EveManager.get_character_by_id(authinfo.main_char_id) logger.debug("Deleting TS3 user for user %s" % request.user) Teamspeak3Manager.delete_user(authinfo.teamspeak3_uid) if check_if_user_has_permission(request.user, "blue_member"): logger.debug("Generating new permission key for blue user %s with main character %s" % (request.user, character)) result = Teamspeak3Manager.generate_new_blue_permissionkey(authinfo.teamspeak3_uid, character.character_name, character.corporation_ticker) else: logger.debug("Generating new permission key for user %s with main character %s" % (request.user, character)) result = Teamspeak3Manager.generate_new_permissionkey(authinfo.teamspeak3_uid, character.character_name, character.corporation_ticker) # if blank we failed if result != "": AuthServicesInfoManager.update_user_teamspeak3_info(result[0], result[1], request.user) logger.debug("Updated authserviceinfo for user %s with TS3 credentials. Updating groups." % request.user) update_teamspeak3_groups.delay(request.user) logger.info("Successfully reset TS3 permission key for user %s" % request.user) return HttpResponseRedirect("/services/") logger.error("Unsuccessful attempt to reset TS3 permission key for user %s" % request.user) return HttpResponseRedirect("/")
def main_character_change(request, char_id): if EveManager.check_if_character_owned_by_user(char_id, request.user): previousmainid = AuthServicesInfoManager.get_auth_service_info( request.user).main_char_id AuthServicesInfoManager.update_main_char_Id(char_id, request.user) # Check if character is in the alliance character_info = EveManager.get_character_by_id(char_id) corporation_info = EveManager.get_corporation_info_by_id( character_info.corporation_id) if EveManager.get_charater_alliance_id_by_id( char_id) == settings.ALLIANCE_ID: add_member_permission(request.user, 'alliance_member') add_user_to_group(request.user, settings.DEFAULT_ALLIANCE_GROUP) add_user_to_group( request.user, generate_corp_group_name( EveManager.get_character_by_id(char_id).corporation_name)) elif corporation_info != None: if corporation_info.is_blue: add_member_permission(request.user, 'blue_member') add_user_to_group(request.user, settings.DEFAULT_BLUE_GROUP) AuthServicesInfoManager.update_is_blue(True, request.user) else: if check_if_user_has_permission(request.user, 'alliance_member'): disable_alliance_member(request.user, previousmainid) if check_if_user_has_permission(request.user, 'blue_member'): disable_blue_member(request.user) else: # TODO: disable serivces if check_if_user_has_permission(request.user, 'alliance_member'): disable_alliance_member(request.user, previousmainid) if check_if_user_has_permission(request.user, 'blue_member'): disable_blue_member(request.user) return HttpResponseRedirect("/characters") return HttpResponseRedirect("/characters")
def main_character_change(request, char_id): logger.debug("main_character_change called by user %s for character id %s" % (request.user, char_id)) if EveManager.check_if_character_owned_by_user(char_id, request.user): previousmainid = AuthServicesInfoManager.get_auth_service_info(request.user).main_char_id AuthServicesInfoManager.update_main_char_Id(char_id, request.user) # Check if character is in the alliance character_info = EveManager.get_character_by_id(char_id) corporation_info = EveManager.get_corporation_info_by_id(character_info.corporation_id) logger.debug("User %s changing main character to %s in corp %s" % (request.user, character_info, corporation_info)) if (settings.IS_CORP and EveManager.get_charater_corporation_id_by_id(char_id) == settings.CORP_ID) or (not settings.IS_CORP and EveManager.get_charater_alliance_id_by_id(char_id) == settings.ALLIANCE_ID): add_member_permission(request.user, 'member') add_user_to_group(request.user, settings.DEFAULT_AUTH_GROUP) add_user_to_group(request.user, generate_corp_group_name(EveManager.get_character_by_id(char_id).corporation_name)) logger.info("User %s transitioned to full member by chaning main character to %s" % (request.user, character_info)) elif corporation_info != None: if corporation_info.is_blue: add_member_permission(request.user, 'blue_member') add_user_to_group(request.user, settings.DEFAULT_BLUE_GROUP) AuthServicesInfoManager.update_is_blue(True, request.user) logger.info("User %s transitioned to blue by changing main character to %s" % (request.user, character_info)) else: if check_if_user_has_permission(request.user, 'member'): disable_member(request.user, previousmainid) if check_if_user_has_permission(request.user, 'blue_member'): disable_blue_member(request.user) logger.info("User %s disabled as new main character %s not member nor blue." % (request.user, character_info)) else: # TODO: disable serivces if check_if_user_has_permission(request.user, 'member'): disable_member(request.user, previousmainid) if check_if_user_has_permission(request.user, 'blue_member'): disable_blue_member(request.user) logger.info("User %s disabled as new main character %s does not have corp model to check." % (request.user, character_info)) return HttpResponseRedirect("/characters") return HttpResponseRedirect("/characters")
def activate_mumble(request): authinfo = AuthServicesInfoManager.get_auth_service_info(request.user) character = EveManager.get_character_by_id(authinfo.main_char_id) if check_if_user_has_permission(request.user, "blue_member"): result = MumbleManager.create_blue_user(character.corporation_ticker, character.character_name) else: result = MumbleManager.create_user(character.corporation_ticker, character.character_name) # if its empty we failed if result[0] is not "": AuthServicesInfoManager.update_user_mumble_info(result[0], result[1], request.user) update_mumble_groups(request.user) return HttpResponseRedirect("/services/") return HttpResponseRedirect("/dashboard")
def fatlink_monthly_personal_statistics_view(request, year, month, char_id=None): year = int(year) month = int(month) start_of_month = datetime.datetime(year, month, 1) start_of_next_month = first_day_of_next_month(year, month) start_of_previous_month = first_day_of_previous_month(year, month) if check_if_user_has_permission( request.user, 'fleetactivitytracking_statistics') and char_id: user = EveCharacter.objects.get(character_id=char_id).user else: user = request.user logger.debug("Personal monthly statistics view for user %s called by %s" % (user, request.user)) personal_fats = Fat.objects.filter(user=user).filter( fatlink__fatdatetime__gte=start_of_month).filter( fatlink__fatdatetime__lt=start_of_next_month) ship_statistics = dict() n_fats = 0 for fat in personal_fats: ship_statistics[fat.shiptype] = ship_statistics.setdefault( fat.shiptype, 0) + 1 n_fats += 1 context = { 'user': user, 'shipStats': sorted(ship_statistics.items()), 'month': start_of_month.strftime("%h"), 'year': year, 'n_fats': n_fats, 'char_id': char_id, 'previous_month': start_of_previous_month, 'next_month': start_of_next_month } created_fats = Fatlink.objects.filter(creator=user).filter( fatdatetime__gte=start_of_month).filter( fatdatetime__lt=start_of_next_month) context["created_fats"] = created_fats context["n_created_fats"] = len(created_fats) return render_to_response( 'registered/fatlinkpersonalmonthlystatisticsview.html', context, context_instance=RequestContext(request))
def make_member(user): logger.debug("Ensuring user %s has member permissions and groups." % user) # ensure member is not blue right now if check_if_user_has_permission(user, "blue_member"): logger.info("Removing user %s blue permission to transition to member" % user) remove_member_permission(user, "blue_member") blue_group, c = Group.objects.get_or_create(name=settings.DEFAULT_BLUE_GROUP) if blue_group in user.groups.all(): logger.info("Removing user %s blue group" % user) user.groups.remove(blue_group) # make member if check_if_user_has_permission(user, "member") is False: logger.info("Adding user %s member permission" % user) add_member_permission(user, "member") member_group, c = Group.objects.get_or_create(name=settings.DEFAULT_AUTH_GROUP) if not member_group in user.groups.all(): logger.info("Adding user %s to member group" % user) user.groups.add(member_group) auth, c = AuthServicesInfo.objects.get_or_create(user=user) if auth.is_blue: logger.info("Marking user %s as non-blue" % user) auth.is_blue = False auth.save() if auth.main_char_id: if EveCharacter.objects.filter(character_id=auth.main_char_id).exists(): char = EveCharacter.objects.get(character_id=auth.main_char_id) corpname = generate_corp_group_name(char.corporation_name) corp_group, c = Group.objects.get_or_create(name=corpname) if not corp_group in user.groups.all(): logger.info("Adding user %s to corp group %s" % (user, corp_group)) user.groups.add(corp_group) for g in user.groups.all(): if str.startswith(str(g.name), "Corp_"): if g != corp_group: logger.info("Removing user %s from old corpgroup %s" % (user, g)) user.groups.remove(g)
def make_member(user): logger.debug("Ensuring user %s has member permissions and groups." % user) # ensure member is not blue right now if check_if_user_has_permission(user, 'blue_member'): logger.info("Removing user %s blue permission to transition to member" % user) remove_member_permission(user, 'blue_member') blue_group, c = Group.objects.get_or_create(name=settings.DEFAULT_BLUE_GROUP) if blue_group in user.groups.all(): logger.info("Removing user %s blue group" % user) user.groups.remove(blue_group) # make member if check_if_user_has_permission(user, 'member') is False: logger.info("Adding user %s member permission" % user) add_member_permission(user, 'member') member_group, c = Group.objects.get_or_create(name=settings.DEFAULT_AUTH_GROUP) if not member_group in user.groups.all(): logger.info("Adding user %s to member group" % user) user.groups.add(member_group) auth, c = AuthServicesInfo.objects.get_or_create(user=user) if auth.is_blue: logger.info("Marking user %s as non-blue" % user) auth.is_blue = False auth.save() assign_corp_group(auth)
def activate_mumble(request): authinfo = AuthServicesInfoManager.get_auth_service_info(request.user) character = EveManager.get_character_by_id(authinfo.main_char_id) if check_if_user_has_permission(request.user, "blue_member"): result = MumbleManager.create_blue_user(character.corporation_ticker, character.character_name) else: result = MumbleManager.create_user(character.corporation_ticker, character.character_name) # if its empty we failed if result[0] is not "": AuthServicesInfoManager.update_user_mumble_info( result[0], result[1], request.user) update_mumble_groups(request.user) return HttpResponseRedirect("/services/") return HttpResponseRedirect("/dashboard")
def fatlink_view(request): # Will show the last 5 or so fatlinks clicked by user. # If the user has the right privileges the site will also show the latest fatlinks with the options to add VIPs and # manually add players. user = request.user logger.debug("fatlink_view called by user %s" % request.user) latest_fats = Fat.objects.filter(user=user).order_by('-id')[:5] if check_if_user_has_permission(user, 'fleetactivitytracking'): latest_links = Fatlink.objects.all().order_by('-id')[:5] context = {'user':user, 'fats': latest_fats, 'fatlinks': latest_links} else: context = {'user':user, 'fats': latest_fats} return render_to_response('registered/fatlinkview.html', context, context_instance=RequestContext(request))
def fatlink_view(request): # Will show the last 5 or so fatlinks clicked by user. # If the user has the right privileges the site will also show the latest fatlinks with the options to add VIPs and # manually add players. user = request.user logger.debug("fatlink_view called by user %s" % request.user) latest_fats = Fat.objects.filter(user=user).order_by('-id')[:5] if check_if_user_has_permission(user, 'fleetactivitytracking'): latest_links = Fatlink.objects.all().order_by('-id')[:5] context = {'user': user, 'fats': latest_fats, 'fatlinks': latest_links} else: context = {'user': user, 'fats': latest_fats} return render_to_response('registered/fatlinkview.html', context, context_instance=RequestContext(request))
def activate_mumble(request): logger.debug("activate_mumble called by user %s" % request.user) authinfo = AuthServicesInfoManager.get_auth_service_info(request.user) character = EveManager.get_character_by_id(authinfo.main_char_id) if check_if_user_has_permission(request.user, "blue_member"): logger.debug("Adding mumble user for blue user %s with main character %s" % (request.user, character)) result = MumbleManager.create_blue_user(character.corporation_ticker, character.character_name) else: logger.debug("Adding mumble user for user %s with main character %s" % (request.user, character)) result = MumbleManager.create_user(character.corporation_ticker, character.character_name) # if its empty we failed if result[0] is not "": AuthServicesInfoManager.update_user_mumble_info(result[0], result[1], request.user) logger.debug("Updated authserviceinfo for user %s with mumble credentials. Updating groups." % request.user) update_mumble_groups(request.user) logger.info("Succesfully activated mumble for user %s" % request.user) return HttpResponseRedirect("/services/") logger.error("Unsuccessful attempt to activate mumble for user %s" % request.user) return HttpResponseRedirect("/dashboard")
def reset_teamspeak3_perm(request): authinfo = AuthServicesInfoManager.get_auth_service_info(request.user) character = EveManager.get_character_by_id(authinfo.main_char_id) Teamspeak3Manager.delete_user(authinfo.teamspeak3_uid) remove_all_syncgroups_for_service(request.user, "teamspeak3") if check_if_user_has_permission(request.user, "blue_member"): result = Teamspeak3Manager.generate_new_blue_permissionkey(authinfo.teamspeak3_uid, character.character_name, character.corporation_ticker) else: result = Teamspeak3Manager.generate_new_permissionkey(authinfo.teamspeak3_uid, character.character_name, character.corporation_ticker) # if blank we failed if result != "": AuthServicesInfoManager.update_user_teamspeak3_info(result[0], result[1], request.user) update_teamspeak3_groups(request.user) return HttpResponseRedirect("/services/") return HttpResponseRedirect("/")
def jabber_broadcast_view(request): logger.debug("jabber_broadcast_view called by user %s" % request.user) success = False allchoices = [] if check_if_user_has_permission(request.user, 'jabber_broadcast_all'): allchoices.append(('all', 'all')) for g in Group.objects.all(): allchoices.append((str(g.name), str(g.name))) else: for g in request.user.groups.all(): allchoices.append((str(g.name), str(g.name))) if request.method == 'POST': form = JabberBroadcastForm(request.POST) form.fields['group'].choices = allchoices logger.debug("Received POST request containing form, valid: %s" % form.is_valid()) if form.is_valid(): user_info = AuthServicesInfo.objects.get(user=request.user) main_char = EveCharacter.objects.get(character_id=user_info.main_char_id) logger.debug("Processing jabber broadcast for user %s with main character %s" % (user_info, main_char)) if user_info.main_char_id != "": message_to_send = form.cleaned_data['message'] + "\n##### SENT BY: " + "[" + main_char.corporation_ticker + "]" + main_char.character_name + " TO: " + form.cleaned_data['group'] + " WHEN: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " #####\n##### Replies are NOT monitored #####\n" group_to_send = form.cleaned_data['group'] OpenfireManager.send_broadcast_threaded(group_to_send, message_to_send,) else: message_to_send = form.cleaned_data['message'] + "\n##### SENT BY: " + "No character but can send pings?" + " TO: " + form.cleaned_data['group'] + " WHEN: " + datetime.datetime.utcnow().strftime("%Y-%m-%d %H:%M:%S") + " #####\n##### Replies are NOT monitored #####\n" group_to_send = form.cleaned_data['group'] OpenfireManager.send_broadcast_threaded(group_to_send, message_to_send,) success = True logger.info("Sent jabber broadcast on behalf of user %s" % request.user) else: form = JabberBroadcastForm() form.fields['group'].choices = allchoices logger.debug("Generated broadcast form for user %s containing %s groups" % (request.user, len(form.fields['group'].choices))) context = {'form': form, 'success': success} return render_to_response('registered/jabberbroadcast.html', context, context_instance=RequestContext(request))
def reset_teamspeak3_perm(request): authinfo = AuthServicesInfoManager.get_auth_service_info(request.user) character = EveManager.get_character_by_id(authinfo.main_char_id) Teamspeak3Manager.delete_user(authinfo.teamspeak3_uid) remove_all_syncgroups_for_service(request.user, "teamspeak3") if check_if_user_has_permission(request.user, "blue_member"): result = Teamspeak3Manager.generate_new_blue_permissionkey( authinfo.teamspeak3_uid, character.character_name, character.corporation_ticker) else: result = Teamspeak3Manager.generate_new_permissionkey( authinfo.teamspeak3_uid, character.character_name, character.corporation_ticker) # if blank we failed if result != "": AuthServicesInfoManager.update_user_teamspeak3_info( result[0], result[1], request.user) update_teamspeak3_groups(request.user) return HttpResponseRedirect("/services/") return HttpResponseRedirect("/")
def corp_member_view(request, corpid=None): logger.debug("corp_member_view called by user %s" % request.user) try: user_main = EveCharacter.objects.get( character_id=AuthServicesInfoManager.get_auth_service_info( user=request.user).main_char_id) user_corp_id = int(user_main.corporation_id) except (ValueError, EveCharacter.DoesNotExist): user_corp_id = settings.CORP_ID if not settings.IS_CORP: alliance = EveAllianceInfo.objects.get( alliance_id=settings.ALLIANCE_ID) alliancecorps = EveCorporationInfo.objects.filter(alliance=alliance) membercorplist = [(int(membercorp.corporation_id), str(membercorp.corporation_name)) for membercorp in alliancecorps] membercorplist.sort(key=lambda tup: tup[1]) membercorp_id_list = [ int(membercorp.corporation_id) for membercorp in alliancecorps ] bluecorps = EveCorporationInfo.objects.filter(is_blue=True) bluecorplist = [(int(bluecorp.corporation_id), str(bluecorp.corporation_name)) for bluecorp in bluecorps] bluecorplist.sort(key=lambda tup: tup[1]) bluecorp_id_list = [ int(bluecorp.corporation_id) for bluecorp in bluecorps ] if not (user_corp_id in membercorp_id_list or user_corp_id not in bluecorp_id_list): user_corp_id = None if not corpid: if (settings.IS_CORP): corpid = settings.CORP_ID elif user_corp_id: corpid = user_corp_id else: corpid = membercorplist[0][0] corp = EveCorporationInfo.objects.get(corporation_id=corpid) Player = namedtuple( "Player", ["main", "maincorp", "maincorpid", "altlist", "apilist"]) if check_if_user_has_permission(request.user, 'alliance_apis') or ( check_if_user_has_permission(request.user, 'corp_apis') and (user_corp_id == corpid)): logger.debug("Retreiving and sending API-information") if settings.IS_CORP: try: member_list = EveApiManager.get_corp_membertracking( settings.CORP_API_ID, settings.CORP_API_VCODE) except APIError: logger.debug( "Corp API does not have membertracking scope, using EveWho data instead." ) member_list = EveWhoManager.get_corporation_members(corpid) else: member_list = EveWhoManager.get_corporation_members(corpid) characters_with_api = {} characters_without_api = {} num_registered_characters = 0 for char_id, member_data in member_list.items(): try: char = EveCharacter.objects.get(character_id=char_id) char_owner = char.user try: mainid = int( AuthServicesInfoManager.get_auth_service_info( user=char_owner).main_char_id) mainchar = EveCharacter.objects.get(character_id=mainid) mainname = mainchar.character_name maincorp = mainchar.corporation_name maincorpid = mainchar.corporation_id api_pair = EveApiKeyPair.objects.get(api_id=char.api_id) except (ValueError, EveCharacter.DoesNotExist, EveApiKeyPair.DoesNotExist): logger.info( "No main character seem to be set for character %s" % char.character_name) mainname = "User: "******"Not set." maincorpid = None api_pair = None num_registered_characters = num_registered_characters + 1 characters_with_api.setdefault( mainname, Player(main=mainchar, maincorp=maincorp, maincorpid=maincorpid, altlist=[], apilist=[])).altlist.append(char) if api_pair: characters_with_api[mainname].apilist.append(api_pair) except (EveCharacter.DoesNotExist): characters_without_api.update( {member_data["name"]: member_data["id"]}) for char in EveCharacter.objects.filter(corporation_id=corpid): if not int(char.character_id) in member_list: logger.info("Character '%s' does not exist in EveWho dump." % char.character_name) char_owner = char.user try: mainid = int( AuthServicesInfoManager.get_auth_service_info( user=char_owner).main_char_id) mainchar = EveCharacter.objects.get(character_id=mainid) mainname = mainchar.character_name maincorp = mainchar.corporation_name maincorpid = mainchar.corporation_id api_pair = EveApiKeyPair.objects.get(api_id=char.api_id) except (ValueError, EveCharacter.DoesNotExist, EveApiKeyPair.DoesNotExist): logger.info( "No main character seem to be set for character %s" % char.character_name) mainname = "User: "******"Not set." maincorpid = None api_pair = None num_registered_characters = num_registered_characters + 1 characters_with_api.setdefault( mainname, Player(main=mainchar, maincorp=maincorp, maincorpid=maincorpid, altlist=[], apilist=[])).altlist.append(char) if api_pair: characters_with_api[mainname].apilist.append(api_pair) n_unacounted = corp.member_count - (num_registered_characters + len(characters_without_api)) if not settings.IS_CORP: context = { "membercorplist": membercorplist, "corp": corp, "characters_with_api": sorted(characters_with_api.items()), 'n_registered': num_registered_characters, 'n_unacounted': n_unacounted, "characters_without_api": sorted(characters_without_api.items()), "search_form": CorputilsSearchForm() } else: logger.debug("corp_member_view running in corportation mode") context = { "corp": corp, "characters_with_api": sorted(characters_with_api.items()), 'n_registered': num_registered_characters, 'n_unacounted': n_unacounted, "characters_without_api": sorted(characters_without_api.items()), "search_form": CorputilsSearchForm() } return render_to_response('registered/corputils.html', context, context_instance=RequestContext(request)) return HttpResponseRedirect("/dashboard/")
def corputils_search(request, corpid=settings.CORP_ID): logger.debug("corputils_search called by user %s" % request.user) corp = EveCorporationInfo.objects.get(corporation_id=corpid) authorized = False try: user_main = EveCharacter.objects.get( character_id=AuthServicesInfoManager.get_auth_service_info( user=request.user).main_char_id) if check_if_user_has_permission(request.user, 'alliance_apis') or ( check_if_user_has_permission(request.user, 'corp_apis') and (user_main.corporation_id == corpid)): logger.debug("Retreiving and sending API-information") authorized = True except (ValueError, EveCharacter.DoesNotExist): if check_if_user_has_permission(request.user, 'alliance_apis'): logger.debug("Retreiving and sending API-information") authorized = True if authorized: if request.method == 'POST': form = CorputilsSearchForm(request.POST) logger.debug("Request type POST contains form valid: %s" % form.is_valid()) if form.is_valid(): # Really dumb search and only checks character name # This can be improved but it does the job for now searchstring = form.cleaned_data['search_string'] logger.debug( "Searching for player with character name %s for user %s" % (searchstring, request.user)) if settings.IS_CORP: try: member_list = EveApiManager.get_corp_membertracking( settings.CORP_API_ID, settings.CORP_API_VCODE) except APIError: logger.debug( "Corp API does not have membertracking scope, using EveWho data instead." ) member_list = EveWhoManager.get_corporation_members( corpid) else: member_list = EveWhoManager.get_corporation_members(corpid) SearchResult = namedtuple('SearchResult', [ 'name', 'id', 'main', 'api_registered', 'character', 'apiinfo' ]) searchresults = [] for memberid, member_data in member_list.items(): if searchstring.lower() in member_data["name"].lower(): try: char = EveCharacter.objects.get( character_name=member_data["name"]) user = char.user mainid = int( AuthServicesInfoManager.get_auth_service_info( user=user).main_char_id) mainname = EveCharacter.objects.get( character_id=mainid).character_name api_registered = True apiinfo = EveApiKeyPair.objects.get( api_id=char.api_id) except EveCharacter.DoesNotExist: api_registered = False char = None mainname = "" apiinfo = None searchresults.append( SearchResult(name=member_data["name"], id=memberid, main=mainname, api_registered=api_registered, character=char, apiinfo=apiinfo)) logger.info( "Found %s members for user %s matching search string %s" % (len(searchresults), request.user, searchstring)) context = { 'corp': corp, 'results': searchresults, 'search_form': CorputilsSearchForm() } return render_to_response( 'registered/corputilssearchview.html', context, context_instance=RequestContext(request)) else: logger.debug("Form invalid - returning for user %s to retry." % request.user) context = { 'corp': corp, 'members': None, 'search_form': CorputilsSearchForm() } return render_to_response( 'registered/corputilssearchview.html', context, context_instance=RequestContext(request)) else: logger.debug("Returning empty search form for user %s" % request.user) return HttpResponseRedirect("/corputils/") return HttpResponseRedirect("/dashboard/")
def service_blue_alliance_test(user): return check_if_user_has_permission(user, 'member') or check_if_user_has_permission(user, 'blue_member')
def run_api_refresh(): users = User.objects.all() logger.debug("Running api refresh on %s users." % len(users)) for user in users: # Check if the api server is online logger.debug("Running api refresh for user %s" % user) if EveApiManager.check_if_api_server_online(): api_key_pairs = EveManager.get_api_key_pairs(user.id) logger.debug("User %s has api key pairs %s" % (user, api_key_pairs)) if api_key_pairs: valid_key = False authserviceinfo = AuthServicesInfo.objects.get(user=user) logger.debug("User %s has api keys. Proceeding to refresh." % user) if authserviceinfo.main_char_id: if authserviceinfo.main_char_id != "": #preserve old corp ID for corp change test on members oldcorp_id = 0 if EveManager.get_character_by_id(authserviceinfo.main_char_id): oldcorp_id = EveCharacter.objects.get(character_id=authserviceinfo.main_char_id).corporation_id logger.debug("Determined user %s current main corp id %s" % (user, oldcorp_id)) for api_key_pair in api_key_pairs: logger.debug("Running update on api key %s" % api_key_pair.api_id) if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key): #check to ensure API key meets min spec logger.info("Determined api key %s is still active." % api_key_pair.api_id) still_valid = True if authserviceinfo.is_blue: if settings.BLUE_API_ACCOUNT: if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key): logger.info("Determined api key %s for blue user %s is no longer type account as requred." % (api_key_pair.api_id, user)) still_valid = False if not EveApiManager.check_blue_api_is_full(api_key_pair.api_id, api_key_pair.api_key): logger.info("Determined api key %s for blue user %s no longer meets minimum access mask as required." % (api_key_pair.api_id, user)) still_valid = False else: if settings.MEMBER_API_ACCOUNT: if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key): logger.info("Determined api key %s for user %s is no longer type account as required." % (api_key_pair.api_id, user)) still_valid = False if not EveApiManager.check_api_is_full(api_key_pair.api_id, api_key_pair.api_key): logger.info("Determined api key %s for user %s no longer meets minimum access mask as required." % (api_key_pair.api_id, user)) still_valid = False if still_valid is not True: logger.debug("API key %s has failed validation; it and its characters will be deleted." % api_key_pair.api_id) EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id) EveManager.delete_api_key_pair(api_key_pair.api_id, user.id) else: logger.info("Determined api key %s still meets requirements." % api_key_pair.api_id) # Update characters characters = EveApiManager.get_characters_from_api(api_key_pair.api_id, api_key_pair.api_key) EveManager.update_characters_from_list(characters) new_character = False for char in characters.result: # Ensure we have a model for all characters on key if not EveManager.check_if_character_exist(characters.result[char]['name']): new_character = True logger.debug("API key %s has a new character on the account: %s" % (api_key_pair.api_id, characters.result[char]['name'])) if new_character: logger.debug("Creating new character %s from api key %s" % (characters.result[char]['name'], api_key_pair.api_id)) EveManager.create_characters_from_list(characters, user, api_key_pair.api_key) valid_key = True else: logger.debug("API key %s is no longer active; it and its characters will be deleted." % api_key_pair.api_id) EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id) EveManager.delete_api_key_pair(api_key_pair.api_id, user.id) if valid_key: # Check our main character character = EveManager.get_character_by_id(authserviceinfo.main_char_id) logger.debug("User %s has valid api key, checking main character %s" % (user, character)) if character is not None and EveManager.check_if_corporation_exists_by_id(character.corporation_id): corp = EveManager.get_corporation_info_by_id(character.corporation_id) main_corp_id = EveManager.get_charater_corporation_id_by_id(authserviceinfo.main_char_id) main_alliance_id = EveManager.get_charater_alliance_id_by_id(authserviceinfo.main_char_id) logger.debug("User %s main character %s has corp %s with alliance id %s" % (user, character, corp, main_alliance_id)) if (settings.IS_CORP and main_corp_id == settings.CORP_ID) or (not settings.IS_CORP and main_alliance_id == settings.ALLIANCE_ID): logger.debug("User %s corp or alliance meets membership requirements. Ensuring has required permissions and groups." % user) if not check_if_user_has_permission(user, "member"): #transition from none or blue to member if check_if_user_has_permission(user, "blue_member"): #strip blue status logger.debug("Removing user %s blue permission and group to prepare for member transition." % user) remove_member_permission(user, "blue_member") remove_user_from_group(user, settings.DEFAULT_BLUE_GROUP) AuthServicesInfoManager.update_is_blue(False, user) #add to auth group add_member_permission(user, "member") add_user_to_group(user, settings.DEFAULT_AUTH_GROUP) #add to required corp group add_user_to_group(user, generate_corp_group_name(character.corporation_name)) logger.info("User %s transitioned to full member during api refresh." % user) elif corp.corporation_id != oldcorp_id: #changed corps, both corps auth'd, need to change group assignment logger.debug("User %s main character changed corp from id %s to %s, both meet membership requirements. Updating corp group." % (user, oldcorp_id, corp.corporation_id)) oldcorp = EveCorporationInfo.objects.get(corporation_id=oldcorp_id) remove_user_from_group(user, generate_corp_group_name(oldcorp.corporation_name)) add_user_to_group(user, generate_corp_group_name(character.corporation_name)) #reset services to force new mumble names and group assignments deactivate_services(user) logger.info("User %s transferred corps from member to member. Reassigned groups." % user) elif corp is not None: logger.debug("User %s main corp %s does not meet membership requirements." % (user, corp)) if corp.is_blue is not True: if check_if_user_has_permission(user, "member"): #transition from member to nobody disable_alliance_member(user, authserviceinfo.main_char_id) logger.info("User %s no longer member: main has left member corp/alliance." % user) elif check_if_user_has_permission(user, "blue_member"): #transition from blue to nobody disable_blue_member(user) logger.info("User %s no longer blue: main has left blue entities." % user) else: #stay nobody, make sure no services deactivate_services(user) logger.debug("Ensured non-member %s has no services." % user) else: if check_if_user_has_permission(user, "member"): #remove auth member to prepare for member to blue transition disable_alliance_member(user, authserviceinfo.main_char_id) logger.debug("Removed user %s member group/permissions to transition to blue." % user) if not check_if_user_has_permission(user, "blue_member"): #perform nobody to blue transition add_member_permission(user, "blue_member") add_user_to_group(user, settings.DEFAULT_BLUE_GROUP) AuthServicesInfoManager.update_is_blue(True, user) logger.info("User %s transitioned to blue member during api refresh." % user) else: # disable accounts with missing corp model (not blue or member) if check_if_user_has_permission(user, "member"): disable_alliance_member(user, authserviceinfo.main_char_id) logger.info("User %s disabled (previously member) as unable to check missing corp model." % user) elif check_if_user_has_permission(user, "blue_member"): disable_blue_member(user) logger.info("User %s disabled (previously blue) as unable to check missing corp model." % user) else: deactivate_services(user) logger.debug("Ensured non-member %s has no services." % user) else: # nuke it, the hard way disable_expired_member(user) logger.info("User %s disabled due to missing main character or corp model." % user) else: # disable accounts with invalid keys disable_expired_member(user) logger.info("User %s has no valid api keys and has been disabled." % user) else: logger.warn("User %s has no main character id, unable to validate membership.")
def run_api_refresh(): users = User.objects.all() for user in users: # Check if the api server is online if EveApiManager.check_if_api_server_online(): api_key_pairs = EveManager.get_api_key_pairs(user.id) if api_key_pairs: valid_key = False authserviceinfo = AuthServicesInfo.objects.get(user=user) print 'Running update on user: '******'Running on ' + api_key_pair.api_id + ':' + api_key_pair.api_key if EveApiManager.api_key_is_valid(api_key_pair.api_id, api_key_pair.api_key): #check to ensure API key meets min spec still_valid = True if authserviceinfo.is_blue: if settings.BLUE_API_ACCOUNT: if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key): still_valid = False if not EveApiManager.check_blue_api_is_full(api_key_pair.api_id, api_key_pair.api_key): still_valid = False else: if settings.MEMBER_API_ACCOUNT: if not EveApiManager.check_api_is_type_account(api_key_pair.api_id, api_key_pair.api_key): still_valid = False if not EveApiManager.check_api_is_full(api_key_pair.api_id, api_key_pair.api_key): still_valid = False if still_valid is not True: EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id) EveManager.delete_api_key_pair(api_key_pair.api_id, user.id) else: # Update characters characters = EveApiManager.get_characters_from_api(api_key_pair.api_id, api_key_pair.api_key) EveManager.update_characters_from_list(characters) new_character = False for char in characters.result: # Ensure we have a model for all characters on key if not EveManager.check_if_character_exist(characters.result[char]['name']): new_character = True if new_character: EveManager.create_characters_from_list(characters, user, api_key_pair.api_key) valid_key = True else: EveManager.delete_characters_by_api_id(api_key_pair.api_id, user.id) EveManager.delete_api_key_pair(api_key_pair.api_id, user.id) if valid_key: # Check our main character character = EveManager.get_character_by_id(authserviceinfo.main_char_id) if character is not None and EveManager.check_if_corporation_exists_by_id(character.corporation_id): corp = EveManager.get_corporation_info_by_id(character.corporation_id) main_corp_id = EveManager.get_charater_corporation_id_by_id(authserviceinfo.main_char_id) main_alliance_id = EveManager.get_charater_alliance_id_by_id(authserviceinfo.main_char_id) if (settings.IS_CORP and main_corp_id == settings.CORP_ID) or (not settings.IS_CORP and main_alliance_id == settings.ALLIANCE_ID): if not check_if_user_has_permission(user, "member"): #transition from none or blue to member if check_if_user_has_permission(user, "blue_member"): #strip blue status remove_member_permission(user, "blue_member") remove_user_from_group(user, settings.DEFAULT_BLUE_GROUP) AuthServicesInfoManager.update_is_blue(False, user) #add to auth group add_member_permission(user, "member") add_user_to_group(user, settings.DEFAULT_AUTH_GROUP) #add to required corp group add_user_to_group(user, generate_corp_group_name(character.corporation_name)) elif corp.corporation_id != oldcorp_id: #changed corps, both corps auth'd, need to change group assignment oldcorp = EveCorporationInfo.objects.get(corporation_id=oldcorp_id) remove_user_from_group(user, generate_corp_group_name(oldcorp.corporation_name)) add_user_to_group(user, generate_corp_group_name(character.corporation_name)) #reset services to force new mumble names and group assignments deactivate_services(user) elif corp is not None: if corp.is_blue is not True: if check_if_user_has_permission(user, "member"): #transition from member to nobody disable_alliance_member(user, authserviceinfo.main_char_id) elif check_if_user_has_permission(user, "blue_member"): #transition from blue to nobody disable_blue_member(user) else: #stay nobody, make sure no services deactivate_services(user) else: if check_if_user_has_permission(user, "member"): #remove auth member to prepare for member to blue transition disable_alliance_member(user, authserviceinfo.main_char_id) if not check_if_user_has_permission(user, "blue_member"): #perform nobody to blue transition add_member_permission(user, "blue_member") add_user_to_group(user, settings.DEFAULT_BLUE_GROUP) AuthServicesInfoManager.update_is_blue(True, user) else: # disable accounts with missing corp model (not blue or member) if check_if_user_has_permission(user, "member"): disable_alliance_member(user, authserviceinfo.main_char_id) elif check_if_user_has_permission(user, "blue_member"): disable_blue_member(user) else: deactivate_services(user) else: # nuke it, the hard way disable_expired_member(user) else: # disable accounts with invalid keys disable_expired_member(user) else: print 'No main_char_id set'
def timer_util_test(user): return check_if_user_has_permission( user, 'alliance_member') or check_if_user_has_permission( user, 'blue_member')
def sigtracker_util_test(user): return check_if_user_has_permission(user, 'member') or check_if_user_has_permission(user, 'blue_member')
def srp_util_test(user): return check_if_user_has_permission(user, 'member') or check_if_user_has_permission(user, 'blue_member')
def srp_util_test(user): return check_if_user_has_permission(user, 'alliance_member') or check_if_user_has_permission(user, 'blue_member')
def corp_member_view(request, corpid = None, year=datetime.date.today().year, month=datetime.date.today().month): year = int(year) month = int(month) start_of_month = datetime.datetime(year, month, 1) start_of_next_month = first_day_of_next_month(year, month) start_of_previous_month = first_day_of_previous_month(year, month) logger.debug("corp_member_view called by user %s" % request.user) try: user_main = EveCharacter.objects.get(character_id=AuthServicesInfoManager.get_auth_service_info(user=request.user).main_char_id) user_corp_id = int(user_main.corporation_id) except (ValueError, EveCharacter.DoesNotExist): user_corp_id = settings.CORP_ID if not settings.IS_CORP: alliance = EveAllianceInfo.objects.get(alliance_id=settings.ALLIANCE_ID) alliancecorps = EveCorporationInfo.objects.filter(alliance=alliance) membercorplist = [(int(membercorp.corporation_id), str(membercorp.corporation_name)) for membercorp in alliancecorps] membercorplist.sort(key=lambda tup: tup[1]) membercorp_id_list = [int(membercorp.corporation_id) for membercorp in alliancecorps] bluecorps = EveCorporationInfo.objects.filter(is_blue=True) bluecorplist = [(int(bluecorp.corporation_id), str(bluecorp.corporation_name)) for bluecorp in bluecorps] bluecorplist.sort(key=lambda tup: tup[1]) bluecorp_id_list = [int(bluecorp.corporation_id) for bluecorp in bluecorps] if not (user_corp_id in membercorp_id_list or user_corp_id not in bluecorp_id_list): user_corp_id = None if not corpid: if(settings.IS_CORP): corpid = settings.CORP_ID elif user_corp_id: corpid = user_corp_id else: corpid = membercorplist[0][0] corp = EveCorporationInfo.objects.get(corporation_id=corpid) if check_if_user_has_permission(request.user, 'alliance_apis') or (check_if_user_has_permission(request.user, 'corp_apis') and (user_corp_id == corpid)): logger.debug("Retreiving and sending API-information") if settings.IS_CORP: try: member_list = EveApiManager.get_corp_membertracking(settings.CORP_API_ID, settings.CORP_API_VCODE) except APIError: logger.debug("Corp API does not have membertracking scope, using EveWho data instead.") member_list = EveWhoManager.get_corporation_members(corpid) else: member_list = EveWhoManager.get_corporation_members(corpid) characters_with_api = {} characters_without_api = {} num_registered_characters = 0 for char_id, member_data in member_list.items(): try: char = EveCharacter.objects.get(character_id=char_id) char_owner = char.user try: mainid = int(AuthServicesInfoManager.get_auth_service_info(user=char_owner).main_char_id) mainchar = EveCharacter.objects.get(character_id=mainid) mainname = mainchar.character_name maincorp = mainchar.corporation_name maincorpid = mainchar.corporation_id api_pair = EveApiKeyPair.objects.get(api_id=char.api_id) except (ValueError, EveCharacter.DoesNotExist, EveApiKeyPair.DoesNotExist): logger.info("No main character seem to be set for character %s" % char.character_name) mainname = "User: "******"Not set." maincorpid = None api_pair = None num_registered_characters = num_registered_characters + 1 characters_with_api.setdefault(mainname, Player(main=mainchar, user=char_owner, maincorp=maincorp, maincorpid=maincorpid, altlist=[], apilist=[], n_fats=0) ).altlist.append(char) if api_pair: characters_with_api[mainname].apilist.append(api_pair) except (EveCharacter.DoesNotExist): characters_without_api.update({member_data["name"]: member_data["id"]}) for char in EveCharacter.objects.filter(corporation_id=corpid): if not int(char.character_id) in member_list: logger.info("Character '%s' does not exist in EveWho dump." % char.character_name) char_owner = char.user try: mainid = int(AuthServicesInfoManager.get_auth_service_info(user=char_owner).main_char_id) mainchar = EveCharacter.objects.get(character_id=mainid) mainname = mainchar.character_name maincorp = mainchar.corporation_name maincorpid = mainchar.corporation_id api_pair = EveApiKeyPair.objects.get(api_id=char.api_id) except (ValueError, EveCharacter.DoesNotExist, EveApiKeyPair.DoesNotExist): logger.info("No main character seem to be set for character %s" % char.character_name) mainname = "User: "******"Not set." maincorpid = None api_pair = None num_registered_characters = num_registered_characters + 1 characters_with_api.setdefault(mainname, Player(main=mainchar, user=char_owner, maincorp=maincorp, maincorpid=maincorpid, altlist=[], apilist=[], n_fats=0) ).altlist.append(char) if api_pair: characters_with_api[mainname].apilist.append(api_pair) n_unacounted = corp.member_count - (num_registered_characters + len(characters_without_api)) for mainname, player in characters_with_api.items(): fats_this_month = Fat.objects.filter(user=player.user).filter(fatlink__fatdatetime__gte = start_of_month).filter(fatlink__fatdatetime__lt = start_of_next_month) characters_with_api[mainname].n_fats = len(fats_this_month) if start_of_next_month > datetime.datetime.now(): start_of_next_month = None if not settings.IS_CORP: context = {"membercorplist": membercorplist, "corp": corp, "characters_with_api": sorted(characters_with_api.items()), 'n_registered': num_registered_characters, 'n_unacounted': n_unacounted, "characters_without_api": sorted(characters_without_api.items()), "search_form": CorputilsSearchForm()} else: logger.debug("corp_member_view running in corportation mode") context = {"corp": corp, "characters_with_api": sorted(characters_with_api.items()), 'n_registered': num_registered_characters, 'n_unacounted': n_unacounted, "characters_without_api": sorted(characters_without_api.items()), "search_form": CorputilsSearchForm()} context["next_month"] = start_of_next_month context["previous_month"] = start_of_previous_month context["this_month"] = start_of_month return render_to_response('registered/corputils.html',context, context_instance=RequestContext(request) ) return HttpResponseRedirect("/dashboard/")
def corputils_search(request, corpid=settings.CORP_ID): logger.debug("corputils_search called by user %s" % request.user) corp = EveCorporationInfo.objects.get(corporation_id=corpid) authorized = False try: user_main = EveCharacter.objects.get(character_id=AuthServicesInfoManager.get_auth_service_info(user=request.user).main_char_id) if check_if_user_has_permission(request.user, 'alliance_apis') or (check_if_user_has_permission(request.user, 'corp_apis') and (user_main.corporation_id == corpid)): logger.debug("Retreiving and sending API-information") authorized = True except (ValueError, EveCharacter.DoesNotExist): if check_if_user_has_permission(request.user, 'alliance_apis'): logger.debug("Retreiving and sending API-information") authorized = True if authorized: if request.method == 'POST': form = CorputilsSearchForm(request.POST) logger.debug("Request type POST contains form valid: %s" % form.is_valid()) if form.is_valid(): # Really dumb search and only checks character name # This can be improved but it does the job for now searchstring = form.cleaned_data['search_string'] logger.debug("Searching for player with character name %s for user %s" % (searchstring, request.user)) if settings.IS_CORP: try: member_list = EveApiManager.get_corp_membertracking(settings.CORP_API_ID, settings.CORP_API_VCODE) except APIError: logger.debug("Corp API does not have membertracking scope, using EveWho data instead.") member_list = EveWhoManager.get_corporation_members(corpid) else: member_list = EveWhoManager.get_corporation_members(corpid) SearchResult = namedtuple('SearchResult', ['name', 'id', 'main', 'api_registered', 'character', 'apiinfo']) searchresults = [] for memberid, member_data in member_list.items(): if searchstring.lower() in member_data["name"].lower(): try: char = EveCharacter.objects.get(character_name=member_data["name"]) user = char.user mainid = int(AuthServicesInfoManager.get_auth_service_info(user=user).main_char_id) mainname = EveCharacter.objects.get(character_id=mainid).character_name api_registered = True apiinfo = EveApiKeyPair.objects.get(api_id=char.api_id) except EveCharacter.DoesNotExist: api_registered = False char = None mainname = "" apiinfo = None searchresults.append(SearchResult(name=member_data["name"], id=memberid, main=mainname, api_registered=api_registered, character=char, apiinfo=apiinfo)) logger.info("Found %s members for user %s matching search string %s" % (len(searchresults), request.user, searchstring)) context = {'corp': corp, 'results': searchresults, 'search_form': CorputilsSearchForm()} return render_to_response('registered/corputilssearchview.html', context, context_instance=RequestContext(request)) else: logger.debug("Form invalid - returning for user %s to retry." % request.user) context = {'corp': corp, 'members': None, 'search_form': CorputilsSearchForm()} return render_to_response('registered/corputilssearchview.html', context, context_instance=RequestContext(request)) else: logger.debug("Returning empty search form for user %s" % request.user) return HttpResponseRedirect("/corputils/") return HttpResponseRedirect("/dashboard/")
def fleetup_util_test(user): return check_if_user_has_permission(user, "member") or check_if_user_has_permission(user, "blue_member")