Exemplo n.º 1
0
def update_all_users_accesses():
    """
    This function will update django users' accesses (that is which groups they are in).

    It must be executed *AFTER* ecm.apps.hr.tasks.titles.update() which creates all Group
    objects synchronized with in-game Titles. This function also adds 2 more Groups:
    "Members" and "Directors" which are not in-game titles but can be usefull for handling
    accesses to some parts of the application.

    After the execution, all django users will have been put into the Groups that match
    their owned characters' in-game titles.

    @see: ecm.apps.common.models.UrlPermission (django model)
    @see: ecm.views.decorators.check_user_access (decorator)
    """
    try:
        t = ScheduledTask.objects.get(
            function__contains='update_all_character_associations')
        if not t.is_last_exec_success:
            raise RuntimeWarning("Last character associations update failed. "
                                 "Skipping user access update.")
    except ScheduledTask.DoesNotExist:
        pass

    corp_members_group = get_members_group()
    directors_group = get_directors_group()
    my_corp = Corporation.objects.mine()

    LOG.info("Updating user accesses from their in-game roles...")
    for user in User.objects.filter(is_active=True):
        update_user_accesses(user, my_corp, corp_members_group,
                             directors_group)
    LOG.info("User accesses updated")
Exemplo n.º 2
0
Arquivo: users.py Projeto: evecm/ecm
def update_all_users_accesses():
    """
    This function will update django users' accesses (that is which groups they are in).

    It must be executed *AFTER* ecm.apps.hr.tasks.titles.update() which creates all Group
    objects synchronized with in-game Titles. This function also adds 2 more Groups:
    "Members" and "Directors" which are not in-game titles but can be usefull for handling
    accesses to some parts of the application.

    After the execution, all django users will have been put into the Groups that match
    their owned characters' in-game titles.

    @see: ecm.apps.common.models.UrlPermission (django model)
    @see: ecm.views.decorators.check_user_access (decorator)
    """
    try:
        t = ScheduledTask.objects.get(function__contains='update_all_character_associations')
        if not t.is_last_exec_success:
            raise RuntimeWarning("Last character associations update failed. "
                                 "Skipping user access update.")
    except ScheduledTask.DoesNotExist:
        pass
        
    corp_members_group = get_members_group()
    directors_group = get_directors_group()
    my_corp = Corporation.objects.mine()
    
    LOG.info("Updating user accesses from their in-game roles...")
    for user in User.objects.filter(is_active=True):
        update_user_accesses(user, my_corp, corp_members_group, directors_group)
    LOG.info("User accesses updated")
Exemplo n.º 3
0
def update_user_accesses(user,
                         my_corp=None,
                         corp_members_group=None,
                         directors_group=None,
                         allies_plus_5_group=None,
                         allies_plus_10_group=None):
    """
    Synchronizes a user's groups with his/hers owned characters' in-game titles.
    """
    my_corp = my_corp or Corporation.objects.mine()
    corp_members_group = corp_members_group or get_members_group()
    directors_group = directors_group or get_directors_group()
    allies_plus_5_group = allies_plus_5_group or get_allies_plus_5_group()
    allies_plus_10_group = allies_plus_10_group or get_allies_plus_10_group()
    owned_characters = user.characters.all()

    titles = Title.objects.none()  # we start with an empty QuerySet
    director = False
    contact_ids = set()

    for char in owned_characters:

        # store all possible contacts to query standings later
        contact_ids.add(char.characterID)
        if char.corp:
            contact_ids.add(char.corp_id)
            if char.corp.alliance:
                contact_ids.add(char.corp.alliance.allianceID)

        director = char.is_director or director
        titles |= char.titles.all(
        )  # the "|" operator concatenates django QuerySets

    all_titles = titles.distinct(
    )  # to remove duplicates if the same title is assigned to multiple characters

    user.groups.clear()

    if owned_characters.filter(corp=my_corp):
        user.groups.add(corp_members_group)

    for titleID in all_titles.values_list("titleID", flat=True):
        user.groups.add(Group.objects.get(id=titleID))

    if director:
        user.groups.add(directors_group)

    standings = my_corp.standings.filter(contactID__in=contact_ids)

    # first we test if the contacts of the user do not have negative standings
    if not standings.filter(value__lte=0):

        if standings.filter(value__gt=5):
            # if there are contacts with standings in ]5, 10], we add the user to the +10 allies group
            user.groups.add(allies_plus_10_group)
        elif standings.filter(value__gt=0):
            # if there are contacts with standings in ]0, 5], we add the user to the +5 allies group
            user.groups.add(allies_plus_5_group)
Exemplo n.º 4
0
def send_feedback():
    """
    This function will collect basic non-critical data about the current server
    instance and send it to eve-corp-management.org official server for usage
    statistics feedback.
    """
    LOG.debug("Sending usage feedback to %r...", ECM_USAGE_FEEDBACK_URL)

    mycorp = Corporation.objects.mine()

    # fetch geolocalization info
    http_client = HttpClient()
    resp = http_client.get(url="http://freegeoip.net/json/")
    geoloc_info = json.loads(resp.read())
    resp.close()

    # we only consider users that are corp members
    users = get_members_group().user_set.order_by("-last_login")

    usage_data = {
        "key_fingerprint": mycorp.key_fingerprint,
        "active_user_count": users.count(),
        "avg_last_visit_top10": avg_last_login(users[:10]),
        "avg_last_visit": avg_last_login(users),
        "first_installed": find_oldest_entry(),
        "country_code": geoloc_info.get("country_code"),
        "country_name": geoloc_info.get("country_name"),
        "city": geoloc_info.get("city"),
        "ecm_version": ecm.VERSION,
    }

    # send the data to the server
    resp = http_client.post(ECM_USAGE_FEEDBACK_URL, json.dumps(usage_data))
    LOG.info("Usage feedback sent to %r. Thank you for your contribution.", ECM_USAGE_FEEDBACK_URL)

    new_version = resp.read().strip()
    old_version = ecm.VERSION

    if parse_version(new_version) > parse_version(old_version):
        LOG.info("New version of ecm is available: %r.", new_version)

        ctx_dict = {
            "host_name": settings.EXTERNAL_HOST_NAME,
            "use_https": settings.USE_HTTPS,
            "new_version": new_version,
            "old_version": old_version,
        }

        dummy_request = HttpRequest()
        dummy_request.user = AnonymousUser()

        subject = tr_lazy("ECM version %s is available" % new_version)
        msg = render_to_string("ecm/common/email/new_version.txt", ctx_dict, Ctx(dummy_request))
        html = render_to_string("ecm/common/email/new_version.html", ctx_dict, Ctx(dummy_request))

        mail_admins(subject=subject, message=msg, html_message=html)
Exemplo n.º 5
0
Arquivo: users.py Projeto: evecm/ecm
def update_user_accesses(user, my_corp=None, corp_members_group=None, directors_group=None,
                         allies_plus_5_group=None, allies_plus_10_group=None):
    """
    Synchronizes a user's groups with his/hers owned characters' in-game titles.
    """
    my_corp = my_corp or Corporation.objects.mine()
    corp_members_group = corp_members_group or get_members_group()
    directors_group = directors_group or get_directors_group()
    allies_plus_5_group = allies_plus_5_group or get_allies_plus_5_group()
    allies_plus_10_group = allies_plus_10_group or get_allies_plus_10_group()
    owned_characters = user.characters.all()
    
    titles = Title.objects.none() # we start with an empty QuerySet
    director = False
    contact_ids = set()
    
    for char in owned_characters:
        
        # store all possible contacts to query standings later
        contact_ids.add(char.characterID)
        if char.corp:
            contact_ids.add(char.corp_id)
            if char.corp.alliance:
                contact_ids.add(char.corp.alliance.allianceID)
        
        director = char.is_director or director
        titles |= char.titles.all() # the "|" operator concatenates django QuerySets
        
    all_titles = titles.distinct() # to remove duplicates if the same title is assigned to multiple characters
    
    user.groups.clear()
    
    if owned_characters.filter(corp=my_corp):
        user.groups.add(corp_members_group)
        
    try:
        for titleID in all_titles.values_list("titleID", flat=True):
            user.groups.add(Group.objects.get(id=titleID+100))
    except:
        pass # Ignore any missing Groups
        
    if director:
        user.groups.add(directors_group)
    
    standings = my_corp.standings.filter(contactID__in=contact_ids)
    
    # first we test if the contacts of the user do not have negative standings
    if not standings.filter(value__lte=0):
        
        if standings.filter(value__gt=5):
            # if there are contacts with standings in ]5, 10], we add the user to the +10 allies group
            user.groups.add(allies_plus_10_group)
        elif standings.filter(value__gt=0):
            # if there are contacts with standings in ]0, 5], we add the user to the +5 allies group
            user.groups.add(allies_plus_5_group)