Home > front end >  How to automaticaly set new accounts as contributors in Oracle Apex
How to automaticaly set new accounts as contributors in Oracle Apex

Time:07-20

I made an app and created an authentication scheme that creates an account every time a new employee is inserted. Now I'm looking at how to set all new users as contributors. I found this PL/SQL code somewhere.

 IF v('APP_USER') = 'username' THEN
  apex_util.set_session_state('F_IS_ADMIN','Y');
END IF;

Now i don't know how to specifically say "all the accounts" but i came up with something:

IF v('APP_USER') IS NOT NULL THEN
  apex_util.set_session_state('F_IS_CONTRIBUTOR','Y');
END IF;

I know it's probably wide of the mark as I'm having trouble understanding what 'F_IS_ADMIN' is and where it comes from but this is the best I can do at the moment (newbie). Anyone has any idea how to do this and if I went in the right direction or not?

And where do I stick this code? in the authorization scheme or in the authentication scheme? All help and pointers very much apriciated!

CodePudding user response:

First of all... what is the code you posted supposed to do ? It is setting an application item to control authorization - it doesn't have anything to do with the "Contributor" role you are talking about. Controlling authorization with application items isn't a good practice. Don't blindly copy code. Instead try to understand what it does and then implement your own version of the code you use as basis.

Now to answer your question. There are a couple of possible solutions (only one needs to be selected - pick your favorite and test first on a copy of your application):

  • If you insist on the user having the actual role, then you can immediately grant the role to the user when the new account is created by invoking this API.

  • But... if all users need the "Contributor" role - that just means that any user needs to access components that are currently protected by the "Contribution Rights" authorization scheme. Just remove that authorization scheme altogether and all those components will be unprotected.

  • If the option above scares you, then it's also possible to modify the "Contribution Rights" authorization scheme so it always yields true. That has the same effect as every user having the role. To do so, edit the "Contribution Rights" authorization scheme:

Scheme Type: PL/SQL Function returning Boolean

PL/SQL Function Body:

  RETURN true;

A similar question was asked earlier this week: How to automatically assign USER ROLES in Oracle Apex

  • Related