Authorization to exclude Home Page - Oracle Apex - oracle

I have a authorization scheme applied to the properties of the application that returns
RETURN MYFUNCTION(:APP_USER, :APP_PAGE_ID);
The issue is, it does not let the user login when the home page ID doesn't return. How can I apply the scheme to the application excluding home page?
I'm using Apex 19.1

I imagine your function would look something like this, with an added if statement for your problem at hand.
begin
-- exclusions for this page check
if p_page_id in (
101 -- login page
,1 -- home page
) then
return true;
end if;
-- does user have access to the page provided?
select count(*)
into l_exists
from dual
where exists
(select null
from sec_table
where page_id = p_page_id
and username = p_app_user
);
return l_exists = 1;
end;

I'm not sure whether I understood you correctly, but - myfunction should be created so that it accepts exactly two parameters, and their names must be p_username and p_password. It is supposed to return Boolean:
true if credentials are OK and you're allowed to connect
false, if the opposite
It seems that your function returns home page ID; is that correct? If so, well, I just told you what to do. If not, could you, please, explain what you mean by
when the home page ID doesn't return
and
how can I apply the scheme (...) excluding home page

Related

Make a text field accept only numeric values in APEX

I have an APEX app that I am working on and need to make a field to only accept numeric values.
I want to have a validation that displays "Only numeric values allowed" whenever the user inputs letters or other characters that are not numeric.
How can I achieve this?
Thanks in advance
If you use the translate function, you can "detect" whether string contains something but digits (this example allows decimal dot as well):
SQL> with test (col) as
2 (select '1234' from dual union all -- valid
3 select '12a4' from dual union all -- invalid
4 select '12.4' from dual union all -- valid
5 select 'abcd' from dual union all -- invalid
6 select '1#34' from dual -- invalid
7 )
8 select col, translate(col, 'x0123456789.', 'x') result
9 from test;
COL RESU
---- ----
1234
12a4 a
12.4
abcd abcd
1#34 #
SQL>
So, if the result is NULL, then it is a valid value.
In Apex, you'd create validation (function that returns error text) which looks like this:
if translate(:P1_ITEM, 'x0123456789.', 'x') is not null then
return 'Only numeric values allowed';
else
return null;
end;
These field definitions are more about the inherent server-side validations that will run on your behalf to ensure the data submitted is numeric.
I think the best you're going to get is having some client side validation as well that gives the user immediate feedback - either has message, or auto-strip. I'm not sure if you can force a HTML element to only allow numerics.
If you really need to validate after each new character, you can try to add Dynamic Action based on Key Release event and Execute JavaScript code when true. Something like this
if ( $v("P2_NEW") !== ""
&& isNaN($v("P2_NEW"))) {
alert("Not a number");
}
Ok after some hours of trying this and that, the following is what has worked for me.
Click in the page. In the "Function and Global Variable Declaration" section add this code:
function isInputNumber(evt){
var ch = String.fromCharCode(evt.which);
if(!(/[0-9]/.test(ch))){
evt.preventDefault();
}
}
In the "Page HTML Body Attribute" section add this code:
onkeypress="isInputNumber(event)"
and thats it. This will prevent the user from entering letters into the input field.

Redirect to page stored in table

I have an application in which a user creates a form, for which several responsible persons are selected in this form and can edit this form.
As soon as the form is submitted, the corresponding page of the process is changed.
The page of the form and the respective responsible persons are saved in a separate table.
The function has to check whether the logged-in user with the user ID is entered in the table as one of the responsibles. The table for example Responsible1 contains a foreign key to the table USERS, in which the ID is located. As soon as it finds the responsible in the table, the function then should redirect the user to the corresponding page.
create or replace function forward_user(p_username in varchar2)
return varchar2
is
l_user varchar2(255);
l_branch_page number;
begin
l_user :=p_username;
/*
Get the target page depending on entry in table
*/
select
page
into l_branch_page
from
FORM_PAGES
where EXISTS (SELECT f.RESP1 from FORM f
left outer join RESPONSIBLE1 s on s.RESP1=f.RESP1
LEFT OUTER JOIN USERS u on u.ID=s.ID where lower(u.USERNAME) =lower(l_user) )
OR (fp.RESP2 in
(SELECT f.RESP2 from FORM f
left outer join RESPONSIBLE2 p on p.RESP2=f.RESP2
left outer join USERS u on u.ID=p.ID where lower(u.USERNAME) =lower(l_user) ))
OR (fp.RESP3 in (select f.RESP from FORM f
left outer join RESPONSIBLE3 e on e.RESP3=f.RESP3
left outer join USERS u on u.ID=e.ID where lower(u.USERNAME) =lower(l_user) ));
return APEX_PAGE.GET_URL(p_page =>l_branch_page);
exception
when no_data_found then
/*Use current page as default page*/
return APEX_PAGE.GET_URL(p_page =>1);
end ;
I then call this function in a pl/sql process when the button NEXT is clicked.
DECLARE
x varchar2(4000);
BEGIN
x:=forward_user(:session_user_name);
END;
I have already checked the sql statements and they work fine, I get the corresponding page.
As well the function compiles successfully.
But when I click the button nothing happens, the user is not forwarded to the stored page in the table.
As well I tried to call this function in a branching process with the behaviour Function Returning a URL(Redirect) but as well nothing happens.
Can someone help me here?
My suggestion would be:
create a hidden page item (as you're on Page 1, let's call it P1_URL)
you already have a process which runs when the Submit button is pressed. Its execution point should be "Processing". Rewrite the process so that it populates P1_URL, e.g.
declare
l_branch_page number;
begin
-- your query goes here; I'll redirect to page 4
l_branch_page := 4;
:P1_URL := APEX_PAGE.GET_URL(p_page => l_branch_page);
end;
create an After Processing branch (why? So that process (see above) first populates P1_URL item). Its behavior's type should be "Page or URL (Redirect)", and its target should be &P1_URL. (literally that - ampersand followed by P1_URL followed by dot).
That's all; when you push the Submit button, process will populate P1_URL item which will be used by the branch and redirect to desired page. Will it work? It worked for me, I've just tested it.
Function:
function forward_user (p_username in varchar2)
return varchar2
is
...
return apex_page.get_url(p_page => l_branch_page);
end;
Process: just one line:
:P1_URL := forward_user(:session_user_name);

Navigation menu access control through DB - Apex oracle

I have a table with Page and its page numbers stored in it. I want to show only those bars on the navigation menu whose page numbers are assigned to the end user. How can I do it?
I'm using Apex 19.1
Create a function which returns a Boolean, saying whether certain user can (or can not) access certain page, e.g.
create table t_access as
select 1 page_no, 'LITTLE' app_user, 'Y' yn from dual union all --> can access page 1
select 2 page_no, 'LITTLE' app_user, 'N' yn from dual; --> can NOT access page 2
create or replace function f_access(par_page_no in number, par_app_user in varchar2)
return boolean
as
l_yn t_access.yn%type;
begin
select a.yn
into l_yn
from t_access a
where a.page_no = par_page_no
and a.app_user = par_app_user;
return l_yn = 'Y';
exception
when no_data_found then
return false;
end;
Use that function in navigation list entry's conditions property; make it a "PL/SQL function body returning a Boolean" as
return f_access(1, :APP_USER);

Creating a Column Link in an Interactive Report -Oracle Apex

I am using Apex 20.1.0.00.13, trying to create link on a column of a Classic Report.
I have followed the step to create the link for a column and redirect it to a page in the same application as the steps below :
To create a link to another page, in the Link Builder - Target dialog:
Type - Select Page in this Application.
Page - Specify the target page number.
Set Items - Select a Name and Value to specify session state for an item.
Clear Session State, Clear Cache - Specify the page numbers on which to clear cache. To specify multiple page, enter a comma-delimited list of page numbers.
Rest Pagination - Select Yes to reset pagination for this page.v
Advanced, Request - Specify the request to be used.
Click OK.
But when I am setting the item and values to specify session state for an item, the Set Items : Name doesn't populate the columns, it appears blank, Could someone let me know where I am going wrong.
I am trying to achieve a link from page 1 say a row with dept no - 2, to be directed to page 2 with details of dept 2 . Is there any other way to do it. Since its a column and not an item I am unable to pass it as a parameter to the next page.
Thanks in advance !
Right; there are no "items" here, you have to create hyperlinks within the report.
Suppose that this is classic report's query:
with test (id, name) as
(select 1, 'Google' from dual union all
select 2, 'Yahoo' from dual union all
select 3, 'Bing' from dual
)
select
id,
'<a href="' || case
when name = 'Google' then 'https://www.google.com'
when name = 'Yahoo' then 'https://www.yahoo.com'
when name = 'Bing' then 'https://www.bing.com'
end
|| '" target="_blank">' || name || '</a>' as link
from test
order by name;
Go to LINK column's properties and set "Escape special characters" to "No". Run the report; everything should work OK.
If - as you say - use it to navigate to another page in your application and set some items to some values (from the IR), then you'd do something like this:
SELECT
'f?p=&APP_ID.:217' ||
':&APP_SESSION.::NO::P217_ID' ||
':' || r.id
as link, ...
FROM my_table r ...
In other words: it navigates to page 217 and passes r.id column value into P217_ID item which is located on page 217.
link column from such a query can be referenced when creating a link column. It would be a
link to custom target
target type = URL
URL = #link# (literally, type #link#)
Probably you could change and merge these two pages into one Master-Detail page. This way you could use the built in lookup function.

How to know, in validation(PL/SQL), if a page item is updated? Similar to apex.item().isChanged in JS

In validation's PL/SQL,is there any way to get the status of a given page item to know if it is changed. Similar to the one in JS API, apex.item.isChanged()?
In the session information (accessed from the developer tools) we can see the status as "Updated" for page Items changed after rendering. How can we get that in the PLSQL in validations?
Any help would be appreciated.
Thanks
if it is a database item, could you select it from the db and compare it to the value on the page? something like :
declare
value varchar2(250);
begin
select your_column into value from your_table where id = :PAGE_ITEM_ID;
if value != :PAGE_ITEM_VALUE then
/*do _something_here*/
end if;
end;

Resources