本文整理汇总了Python中util.check_if_user_has_permission函数的典型用法代码示例。如果您正苦于以下问题:Python check_if_user_has_permission函数的具体用法?Python check_if_user_has_permission怎么用?Python check_if_user_has_permission使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了check_if_user_has_permission函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: make_blue
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)
开发者ID:kallama,项目名称:allianceauth,代码行数:27,代码来源:tasks.py
示例2: main_character_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")
开发者ID:Krienas,项目名称:allianceauth,代码行数:35,代码来源:views.py
示例3: make_blue
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
开发者ID:johanko,项目名称:allianceauth,代码行数:32,代码来源:tasks.py
示例4: reset_teamspeak3_perm
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("/")
开发者ID:Tuqiri,项目名称:allianceauth,代码行数:27,代码来源:views.py
示例5: fatlink_monthly_personal_statistics_view
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))
开发者ID:Ydmir,项目名称:allianceauth,代码行数:29,代码来源:views.py
示例6: main_character_change
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")
开发者ID:Tuqiri,项目名称:allianceauth,代码行数:40,代码来源:views.py
示例7: activate_mumble
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")
开发者ID:tankbusta,项目名称:allianceauth,代码行数:13,代码来源:views.py
示例8: make_member
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)
开发者ID:kallama,项目名称:allianceauth,代码行数:36,代码来源:tasks.py
示例9: make_member
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)
开发者ID:Cafune,项目名称:allianceauth,代码行数:24,代码来源:tasks.py
示例10: fatlink_view
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))
开发者ID:alflife,项目名称:allianceauth,代码行数:16,代码来源:views.py
示例11: activate_mumble
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")
开发者ID:Tuqiri,项目名称:allianceauth,代码行数:19,代码来源:views.py
示例12: reset_teamspeak3_perm
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("/")
开发者ID:tankbusta,项目名称:allianceauth,代码行数:21,代码来源:views.py
示例13: jabber_broadcast_view
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))
开发者ID:Tuqiri,项目名称:allianceauth,代码行数:40,代码来源:views.py
示例14: corputils_search
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/")
开发者ID:alflife,项目名称:allianceauth,代码行数:73,代码来源:views.py
示例15: run_api_refresh
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
#.........这里部分代码省略.........
开发者ID:Tuqiri,项目名称:allianceauth,代码行数:101,代码来源:tasks.py
示例16: run_api_refresh
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: ' + user.username
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
for api_key_pair in api_key_pairs:
print '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"):
#transit
|
请发表评论