Automatic assignment of Author role when a Contributor is already an User

Hi!

I wonder if it is possible to do this:

When someone makes a new submission, the user data is cloned to the authors table and a new row is added to the stage_assigments table. However, that does not happen with the other contributors (I understand the need for separate user/authors tables).

But if a contributor is already registered as an user in OJS, it would be possible to check that information (by e-mail or ORICD, perhaps…) and automatically create a new entry in the stage_assigment table, making that contributor “officially” an author.

One of the benefits of this feature would be a better screening for reviewers that have conflict in the current submission (as I understood, the $warnonassignment uses the information on the stage_assigment table to identify which reviewers put the double-blind review at risk; this happened to us last week, we enroled a submission contributor as a reviewer without realizing it…)

I’m new to php (thank you @NateWr for the help in my other posts), and I’m willing to try to accomplish what I suggest, if someone please leeds me in the right path… :slight_smile:

Thank you!

Kind regards,

Rui Pedro Silva

1 Like

Hi @Rui_Pedro_Silva,

Can you clarify which specific version of OJS you’re using in this case?

-Roger
PKP Team

Hi @rcgillis ,

Yes, 3.3.0.4

Thank you!

Hi @Rui_Pedro_Silva,

I recommend writing a plugin to do this for you. You can learn about plugins in our Plugin Guide. You’ll want to use a Generic Plugin and register a hook to fire when the author form is submitted.

The hook you will want for this form is authorform::execute.

Hi @NateWr !

Ok, it’s a good starting tip, I’ll try it! :slight_smile:

Do you advise me to keep you posted here or on GitHub?

Thank you!

Kind regards,

Rui Pedro Silva

The forum is a good place for plugin development. GitHub is ok if you run into bugs or limitations in the core code.

Ok, @NateWr , great!

So, I’ve already set up the plugin folder and main files, using the Tutorial example. Is “working” (No problem when I set to active in the plugin management).

Then I tried to figure out what I needed to do to set up the hook (sorry if I’m not using the right terms…).

As I understand, I need to set an action of filling the authorform if a given contributor variable (e-mail, for example) matches an existing e-mail in the users table. Is this correct?

If this is correct, how can I get it to work (I apologize for my ignorance, I’m really giving my first steps in this…)

Thank you!

The first thing I’d recommend is create your hook and inspect what variables are passed into the callback function:

HookRegistry::register('authorform::execute', function($hookName, $args) {
  // use a debugger to inspect $args or print to the error log
});

Then look at the PKPAuthorForm to see how an author is created.

If you haven’t yet, read about Entities in the docs.

Hi! Just to say that I’m working on this (still studying php and OJS code).

I believe I’ll get some progress during this week.

Rui Pedro Silva

Hi1, @NateWr !

I’ve managed to get it to work, but still not as a plugin.

After line 202 of /lib/pkp/controllers/grid/users/author/form/PKPAuthorForm.inc.php I added this::

 		$userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
		$user = $userDao->getUserByEmail($this->getData('email'));
        $role = "14";
      
      	if (is_null($user)) {
          
        } else  {
      		$stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
			$stageAssignmentDao->build($author->getData('publicationId'), $role, $user->getId());
   		}

Now it’s working as I wanted: if a contributor is a user, it makes a new entry in stage_assignments table as a author (role 14).

The code is very unpolished (it makes a translator contributor also an author, and the author remains when the contributor is deleted), but I’ll try to get it better in the next few days.

So, two questions:
1 - what’s yout opinion on the code?
2 - how can I get it to work as a plugin? (i’m still struggling to understand how hooks work…)

Thank you!

Kind regards,

Rui Pedro Silva

Hi @Rui_Pedro_Silva, that looks great!

You’ve set the user group ID manually, so it will only work for this one journal. And if the role configurations are ever changed it will break for that too.

You can get the default author user group with the following:

$userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /** @var $userGroupDao UserGroupDAO */
$authorGroupId = $userGroupDao->getDefaultByRoleId(Application::get()->getRequest()->getContextId(), ROLE_ID_AUTHOR);

You might want to test what happens when an editor makes a submission. This is common for editorials or issue introductions, and in this case they may not want to be assigned as an author.

how can I get it to work as a plugin?

You can use the code you’ve written almost as-is inside of a plugin. You’ll need to read the docs to learn how to create a generic plugin and use hooks (see my previous post), but the hook itself just wraps your code:

HookRegistry::register('authorform::execute', function($hookName, $args) {
  $form = $args[0];

  // Your code, using `$form` instead of `$this`, eg:
  // $user = $userDao->getUserByEmail($form->getData('email'));
});

Hi @NateWr !

Thank you very much for your reply!

Sorry for my ignorance, I thought 14 would always represent the author role… :sweat_smile: :sweat_smile: :sweat_smile:

I’ll use all your valuable advices and I’ll give another go at the plugin.

I’ll try to go a little deeper and get it to identify if the contributor is an editor or an translator (either case, it shouldn´t create the author role).

I’m really having a blast learning all this stuff!!!

I’ll keep you posted.

Kind regards,

Rui Pedro Silva