[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[EP-tech] Re: changing default user type



When I've had fiddly automatic values to apply in the past, I've done it in document_fields_automatic.  This can sometimes be necessary because we don't have an actual object when default fields are set.  Using the best practice of cfg.d file changes by feature in new files, create a file called z_user_type_default.pl:

#flag to make sure w
$c->add_dataset_field('document', { name => 'automatic_fields_applied', type => 'int', volatile => 1 });

#save reference to original automatic function
$c->{set_document_automatic_fields_user_type_default} = $c->{set_document_automatic_fields};

$c->{set_document_automatic_fields} = sub
{
	my( $doc ) = @_;

	#first call original automatic function
	$doc->repository->call('set_document_automatic_fields_user_type_default', $doc);

	if (
		!$eprint->is_set('automatic_fields_applied')
		|| $eprint->value('automatic_fields_applied') == 1
	)
	{
		#set default values here
		$user->set_value('usertype', 'wizard');

		$eprint->set_value('automatic_fields_applied', 1);
	}

};

You'll need to run epadmin update to add the new field to the database, and I've just typed the code into the email, so it will probably have bugs.  Also, you're unlikely to have a 'wizard' user type (though I can see lots of up-sides to having it), so you might want to change that to an actual user type.

Finally, note that this is almost certainly a *really* bad idea.  However, you opened with 'simple experiment', and I'm all for that kind of thing.

--
Adam Field
Business Relationship Manager and Community Lead
EPrints Services
+44 (0)23 8059 8814





On 2 Sep 2015, at 04:14, Matthew Brady wrote:

> Hi All,
>  
> I thought this would be a simple experiment? change the default value for a user record when it gets created from ?user? to ?editor?.
>  
> Altering the local file ?/archive/xxxxx/cfg/cfg.d/user_fields_default.pl file to include the line
>  
> $data->{type} =      "editor";
>  
> Doesn?t appear to work as expected?
>  
> Even altering a default (that I didn?t know existed, until I tried to figure out what was going wrong!)
> Within ?/perl_lib/EPrints/DataObj/User.pm, there is a sub ?get_system_field_info?, that contains a default setting as well?
>  
> { name=>"usertype", type=>"namedset", required=>1,
>               set_name=>"user", input_style=>"medium", default_value=>"user" },
>  
> Anyone got any ideas ?
>  
> Cheers
>  
> Matt
>  
> _____________________________________________________________
> This email (including any attached files) is confidential and is for the intended recipient(s) only. If you received this email by mistake, please, as a courtesy, tell the sender, then delete this email.
> 
> The views and opinions are the originator's and do not necessarily reflect those of the University of Southern Queensland. Although all reasonable precautions were taken to ensure that this email contained no viruses at the time it was sent we accept no liability for any losses arising from its receipt.
> 
> The University of Southern Queensland is a registered provider of education with the Australian Government.
> (CRICOS Institution Code QLD 00244B / NSW 02225M, TEQSA PRV12081 )
> 
> *** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech
> *** Archive: http://www.eprints.org/tech.php/
> *** EPrints community wiki: http://wiki.eprints.org/
> *** EPrints developers Forum: http://forum.eprints.org/