blob: f5bff1345b9eb8cad3863b84bb6df2e72175a871 [file] [log] [blame]
# Copyright 2013 the Melange authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""Mapreduce converting profile model."""
from google.appengine.ext import ndb
# This MapReduce requires this model to have been imported.
# pylint: disable=unused-import
from melange.models.profile import Profile
# pylint: enable=unused-import
@ndb.transactional
def convertProfileRolesTxn(profile_key):
"""Converts lists of organizations for which the specified profile has
role in a transaction.
Args:
profile_key: Profile key.
"""
# only update profiles for Code In programs
if 'gci' not in profile_key.name():
return
profile = ndb.Key.from_old_key(profile_key).get()
# only update projects
new_mentor_for = []
for org_key in profile.mentor_for:
new_mentor_for.append(ndb.Key('Organization', org_key.id()))
profile.mentor_for = new_mentor_for
new_admin_for = []
for org_key in profile.admin_for:
new_admin_for.append(ndb.Key('Organization', org_key.id()))
profile.admin_for = new_admin_for
profile.put()