@@ -1507,7 +1507,8 @@ def add_contributors(self, contributors, auth=None, log=True, save=False):
15071507 return self .contributor_set .filter (user__in = users )
15081508
15091509 def add_unregistered_contributor (self , fullname , email , auth , send_email = None ,
1510- visible = True , permissions = None , save = True , existing_user = None ):
1510+ visible = True , permissions = None , save = True , existing_user = None ,
1511+ log = True ):
15111512 """Add a non-registered contributor to the project.
15121513
15131514 :param str fullname: The full name of the person.
@@ -1555,7 +1556,7 @@ def add_unregistered_contributor(self, fullname, email, auth, send_email=None,
15551556
15561557 self .add_contributor (
15571558 contributor , permissions = permissions , auth = auth ,
1558- visible = visible , send_email = send_email , log = True , save = False
1559+ visible = visible , send_email = send_email , log = log , save = False
15591560 )
15601561 self ._add_related_source_tags (contributor )
15611562 if save :
@@ -1564,12 +1565,13 @@ def add_unregistered_contributor(self, fullname, email, auth, send_email=None,
15641565
15651566 def add_contributor_registered_or_not (self , auth , user_id = None ,
15661567 full_name = None , email = None , send_email = None ,
1567- permissions = None , bibliographic = True , index = None , save = True ):
1568+ permissions = None , bibliographic = True , index = None , save = True ,
1569+ user = None , log = True ):
15681570 OSFUser = apps .get_model ('osf.OSFUser' )
15691571 send_email = send_email or self .contributor_email_template
15701572
15711573 if user_id :
1572- contributor = OSFUser .load (user_id )
1574+ contributor = user or OSFUser .load (user_id )
15731575 if not contributor :
15741576 raise ValueError (f'User with id { user_id } was not found.' )
15751577
@@ -1578,7 +1580,7 @@ def add_contributor_registered_or_not(self, auth, user_id=None,
15781580
15791581 if contributor .is_registered :
15801582 contributor = self .add_contributor (contributor = contributor , auth = auth , visible = bibliographic ,
1581- permissions = permissions , send_email = send_email , save = save )
1583+ permissions = permissions , send_email = send_email , save = save , log = log )
15821584 else :
15831585 if not full_name :
15841586 raise ValueError (
@@ -1588,7 +1590,7 @@ def add_contributor_registered_or_not(self, auth, user_id=None,
15881590 contributor = self .add_unregistered_contributor (
15891591 fullname = full_name , email = contributor .username , auth = auth ,
15901592 send_email = send_email , permissions = permissions ,
1591- visible = bibliographic , existing_user = contributor , save = save
1593+ visible = bibliographic , existing_user = contributor , save = save , log = log
15921594 )
15931595
15941596 else :
@@ -1604,12 +1606,13 @@ def add_contributor_registered_or_not(self, auth, user_id=None,
16041606 send_email = send_email ,
16051607 permissions = permissions ,
16061608 save = save ,
1609+ log = log ,
16071610 )
16081611 else :
16091612 contributor = self .add_unregistered_contributor (
16101613 fullname = full_name , email = email , auth = auth ,
16111614 send_email = send_email , permissions = permissions ,
1612- visible = bibliographic , save = save
1615+ visible = bibliographic , save = save , log = log
16131616 )
16141617
16151618 auth .user .email_last_sent = timezone .now ()
@@ -1621,6 +1624,55 @@ def add_contributor_registered_or_not(self, auth, user_id=None,
16211624 contributor_obj = self .contributor_set .get (user = contributor )
16221625 return contributor_obj
16231626
1627+ def add_contributors_registered_or_not (self , contributors , auth = None , log = True , save = False ):
1628+ """Add multiple contributors using the unified registered-or-not path.
1629+
1630+ Each item should be a dictionary with keys compatible with
1631+ `add_contributor_registered_or_not`, e.g.:
1632+ {
1633+ 'user_id': '<user guid>',
1634+ 'user': '<OSFUser>' or None,
1635+ 'email': '<email>' or None,
1636+ 'full_name': '<full name>' or None,
1637+ 'send_email': '<email preference>' or None,
1638+ 'permissions': <permission string>,
1639+ 'bibliographic': <bool>,
1640+ 'index': <int or None>,
1641+ }
1642+ """
1643+ results = []
1644+
1645+ for item in contributors :
1646+ contributor_obj = self .add_contributor_registered_or_not (
1647+ auth = auth ,
1648+ user_id = item .get ('user_id' ),
1649+ user = item .get ('user' ),
1650+ full_name = item .get ('full_name' ),
1651+ email = item .get ('email' ),
1652+ send_email = item .get ('send_email' ) or getattr (self , 'contributor_email_template' , None ),
1653+ permissions = item .get ('permissions' ),
1654+ bibliographic = item .get ('bibliographic' , True ),
1655+ index = item .get ('index' ),
1656+ save = False ,
1657+ log = False ,
1658+ )
1659+ results .append (contributor_obj )
1660+
1661+ if log and results :
1662+ params = self .log_params
1663+ params ['contributors' ] = [c .user ._id for c in results ]
1664+ self .add_log (
1665+ action = self .log_class .CONTRIB_ADDED ,
1666+ params = params ,
1667+ auth = auth ,
1668+ save = False ,
1669+ )
1670+
1671+ if save :
1672+ self .save ()
1673+
1674+ return results
1675+
16241676 def replace_contributor (self , old , new ):
16251677 """
16261678 Replacing unregistered contributor with a verified user
0 commit comments