<s> from datetime import datetime <EOL> from itertools import chain <EOL> from olympia import amo <EOL> from access . models import Group <EOL> from devhub . models import ActivityLog <EOL> from editors . models import EventLog <EOL> from users . models import UserProfile <EOL> group_map = { <EOL> <NUM_LIT:1> : '<STR_LIT>' , <EOL> <NUM_LIT:2> : '<STR_LIT>' <EOL> } <EOL> def run ( ) : <EOL> new_groups = Group . objects . filter ( name__in = group_map . values ( ) ) <EOL> new_groups = dict ( ( g . name , g ) for g in new_groups ) <EOL> for id , name in group_map . items ( ) : <EOL> group_map [ id ] = new_groups [ name ] <EOL> items = ( EventLog . objects . values_list ( '<STR_LIT:action>' , '<STR_LIT:user>' , '<STR_LIT>' , '<STR_LIT>' , <EOL> '<STR_LIT>' , '<STR_LIT>' ) <EOL> . filter ( type = '<STR_LIT>' , <EOL> action__in = ( '<STR_LIT>' , <EOL> '<STR_LIT>' ) , <EOL> changed_id__in = group_map . keys ( ) ) <EOL> . order_by ( '<STR_LIT>' ) ) <EOL> user_ids = set ( chain ( * [ ( i [ <NUM_LIT:1> ] , int ( i [ <NUM_LIT:2> ] or i [ <NUM_LIT:3> ] ) ) <EOL> for i in items <EOL> if ( i [ <NUM_LIT:2> ] or i [ <NUM_LIT:3> ] or '<STR_LIT>' ) . isdigit ( ) ] ) ) <EOL> users = dict ( ( u . id , u ) <EOL> for u in UserProfile . objects . filter ( id__in = user_ids ) ) <EOL> for action , admin , added , removed , group_id , created in items : <EOL> if action == '<STR_LIT>' : <EOL> user_id , action = added , amo . LOG . GROUP_USER_ADDED <EOL> else : <EOL> user_id , action = removed , amo . LOG . GROUP_USER_REMOVED <EOL> if not user_id . isdigit ( ) : <EOL> continue <EOL> user_id = int ( user_id ) <EOL> kw = { '<STR_LIT>' : created } <EOL> if admin in users : <EOL> kw [ '<STR_LIT:user>' ] = users [ admin ] <EOL> if user_id in users : <EOL> amo . log ( action , group_map [ group_id ] , users [ user_id ] , ** kw ) <EOL> created = datetime ( <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:3> , <NUM_LIT> , <NUM_LIT:15> , <NUM_LIT> ) <EOL> user = group_map [ <NUM_LIT:1> ] . users . all ( ) [ <NUM_LIT:0> ] <EOL> group = group_map [ <NUM_LIT:2> ] <EOL> logs = ( ActivityLog . objects . for_group ( group ) <EOL> . filter ( action = amo . LOG . GROUP_USER_ADDED . id ) ) <EOL> editors = ( UserProfile . objects . filter ( groups = group ) <EOL> . exclude ( id__in = [ l . arguments [ <NUM_LIT:1> ] . id for l in logs ] ) ) <EOL> for editor in editors : <EOL> amo . log ( amo . LOG . GROUP_USER_ADDED , group , editor , user = user , <EOL> created = created ) </s>
