Repository: rucio/rucio

Issue:
Email missing from list identities
Motivation
----------
Looking at the output from list_identities in the account client, it does not return the e-mail address for the identity. However, the set identity takes this parameter and the field exists in the database.  Is this an oversight or is it intentional?

The underlying motivation for this is that I'm trying to migrate the accounts and identities from one server to another.


Modification
------------





Discussion:
@hahahannes can you please have a look on this.
In https://github.com/rucio/rucio/blob/ca3166ff5e63b7f24b61236646c2aa747f8aa40b/lib/rucio/core/account.py#L180
we probably need to join models.IdentityAccountAssociation with models.Identitiy to add the email there.

Resolving patch:
diff --git a/lib/rucio/core/account.py b/lib/rucio/core/account.py
--- a/lib/rucio/core/account.py
+++ b/lib/rucio/core/account.py
@@ -13,7 +13,7 @@
 # - Martin Barisits, <martin.barisits@cern.ch>, 2014
 # - Cedric Serfon, <cedric.serfon@cern.ch>, 2014-2019
 # - Joaquin Bogado, <joaquin.bogado@cern.ch>, 2015
-# - Hannes Hansen, <hannes.jakob.hansen@cern.ch>, 2018
+# - Hannes Hansen, <hannes.jakob.hansen@cern.ch>, 2018-2019
 #
 # PY3K COMPATIBLE
 
@@ -22,6 +22,7 @@
 from re import match
 from traceback import format_exc
 
+from sqlalchemy import and_
 from sqlalchemy.exc import IntegrityError
 from sqlalchemy.orm import exc
 
@@ -176,9 +177,12 @@ def list_identities(account, session=None):
     except exc.NoResultFound:
         raise exception.AccountNotFound('Account with ID \'%s\' cannot be found' % account)
 
-    query = session.query(models.IdentityAccountAssociation).filter_by(account=account)
+    query = session.query(models.IdentityAccountAssociation, models.Identity)\
+                   .join(models.Identity, and_(models.Identity.identity == models.IdentityAccountAssociation.identity,
+                                               models.Identity.identity_type == models.IdentityAccountAssociation.identity_type))\
+                   .filter(models.IdentityAccountAssociation.account == account)
     for identity in query:
-        identity_list.append({'type': identity.identity_type, 'identity': identity.identity})
+        identity_list.append({'type': identity[0].identity_type, 'identity': identity[0].identity, 'email': identity[1].email})
 
     return identity_list
 


Test patch:
diff --git a/lib/rucio/tests/test_account.py b/lib/rucio/tests/test_account.py
--- a/lib/rucio/tests/test_account.py
+++ b/lib/rucio/tests/test_account.py
@@ -12,13 +12,13 @@
 # - Vincent Garonne, <vincent.garonne@cern.ch>, 2012-2015
 # - Joaquin Bogado, <joaquin.bogado@cern.ch>, 2015
 # - Cedric Serfon, <cedric.serfon@cern.ch>, 2015, 2017
-# - Hannes Hansen, <hannes.jakob.hansen@cern.ch>, 2018
+# - Hannes Hansen, <hannes.jakob.hansen@cern.ch>, 2018-2019
 #
 # PY3K COMPATIBLE
 
 from json import dumps, loads
 
-from nose.tools import assert_equal, assert_true, assert_raises, raises
+from nose.tools import assert_equal, assert_true, assert_raises, raises, assert_in
 from paste.fixture import TestApp
 
 from rucio.api.account import add_account, account_exists, del_account, update_account, get_account_info
@@ -26,6 +26,7 @@
 from rucio.common.config import config_get
 from rucio.common.exception import AccountNotFound, Duplicate, InvalidObject
 from rucio.common.utils import generate_uuid as uuid
+from rucio.core.account import list_identities
 from rucio.core.identity import add_account_identity, add_identity
 from rucio.db.sqla.constants import AccountStatus, IdentityType
 from rucio.tests.common import account_name_generator
@@ -58,6 +59,16 @@ def test_update_account(self):
         assert_equal(email, 'test')
         del_account(usr, 'root')
 
+    def test_list_account_identities(self):
+        """ ACCOUNT (CORE): Test listing of account identities """
+        email = 'email'
+        identity = uuid()
+        identity_type = IdentityType.USERPASS
+        account = 'root'
+        add_account_identity(identity, identity_type, account, email)
+        identities = list_identities(account)
+        assert_in({'type': identity_type, 'identity': identity, 'email': email}, identities)
+
 
 class TestAccountRestApi():