New procedures created for the user management screens.

git-svn-id: http://locode01.ad.dom/svn/WEBMIP/trunk@2973 248e525c-4dfb-0310-94bc-949c084e9493
This commit is contained in:
mullenm
2007-12-11 18:46:49 +00:00
parent bba39db4d7
commit 9cb6d4539e
2 changed files with 442 additions and 162 deletions

View File

@@ -1,6 +1,5 @@
CREATE OR REPLACE PACKAGE mip_parties AS CREATE OR REPLACE PACKAGE mip_parties AS
/* /*
PROCEDURE add_party PROCEDURE add_party
- allows an admin user to create new parties for use in the system - allows an admin user to create new parties for use in the system
@@ -8,44 +7,97 @@ CREATE OR REPLACE PACKAGE mip_parties AS
%param p_password - the password of the party %param p_password - the password of the party
%p_role - the party's role in the system %p_role - the party's role in the system
*/ */
FUNCTION get_user_id(p_username IN VARCHAR2) FUNCTION get_user_id(p_username IN VARCHAR2) RETURN NUMBER;
RETURN NUMBER; FUNCTION get_user_role(p_username IN VARCHAR2) RETURN VARCHAR2;
FUNCTION get_user_role(p_username IN VARCHAR2)
return varchar2;
-- --
/** get the password created date for the given username and password /** get the password created date for the given username and password
%return DATE the date the password was created for authenticated username and password combination %return DATE the date the password was created for authenticated username and password combination
*/ */
FUNCTION get_user_password_created(p_username IN VARCHAR2 FUNCTION get_user_password_created(p_username IN VARCHAR2,
,p_password IN VARCHAR2) RETURN DATE; p_password IN VARCHAR2) RETURN DATE;
-- --
FUNCTION has_supplier(p_username IN VARCHAR2, p_supplierid IN VARCHAR) return boolean; FUNCTION has_supplier(p_username IN VARCHAR2, p_supplierid IN VARCHAR)
RETURN BOOLEAN;
PROCEDURE add_address(p_address addresses%ROWTYPE); PROCEDURE add_address(p_address addresses%ROWTYPE);
PROCEDURE add_partyaddress(p_addr_code IN VARCHAR2, p_prty_id IN INTEGER); PROCEDURE add_partyaddress(p_addr_code IN VARCHAR2, p_prty_id IN INTEGER);
PROCEDURE add_partyrole(p_role_code IN VARCHAR2, p_prty_id IN NUMBER); PROCEDURE add_partyrole(p_role_code IN VARCHAR2, p_prty_id IN NUMBER);
PROCEDURE add_partycontactmech(p_contact_mech IN VARCHAR2, p_prty_id IN NUMBER); PROCEDURE add_partycontactmech(p_contact_mech IN VARCHAR2,
PROCEDURE add_party(p_role IN VARCHAR2, p_prty_id IN NUMBER);
p_username IN VARCHAR2, PROCEDURE add_party(p_role IN VARCHAR2,
p_created_by IN VARCHAR2, p_username IN VARCHAR2,
p_name IN VARCHAR2, p_created_by IN VARCHAR2,
p_mkpt_ref IN VARCHAR2, p_name IN VARCHAR2,
p_shortcode IN VARCHAR2, p_mkpt_ref IN VARCHAR2,
p_lt_7b_contract_ref IN VARCHAR2, p_shortcode IN VARCHAR2,
p_gt_7b_contract_ref IN VARCHAR2, p_lt_7b_contract_ref IN VARCHAR2,
p_gt_7b_contract_ref IN VARCHAR2,
p_adversarial_contract_ref IN VARCHAR2, p_adversarial_contract_ref IN VARCHAR2,
p_manu_ref IN VARCHAR2, p_manu_ref IN VARCHAR2,
p_description IN VARCHAR2, p_description IN VARCHAR2,
p_status IN VARCHAR2, p_status IN VARCHAR2,
p_first_name IN VARCHAR2, p_first_name IN VARCHAR2,
p_last_name IN VARCHAR2, p_last_name IN VARCHAR2,
p_personal_title IN VARCHAR2, p_personal_title IN VARCHAR2,
p_comments IN VARCHAR2, p_comments IN VARCHAR2,
p_addresscode IN VARCHAR2, p_addresscode IN VARCHAR2,
p_partyrole IN VARCHAR2, p_partyrole IN VARCHAR2,
p_partycontactmech IN VARCHAR2); p_partycontactmech IN VARCHAR2);
--
/** allows new parties to be created in the system.
%param p_manu_ref the manufacturer's unique reference
%param p_created_by the user that created the party
%param p_shortcode the mktp short code
%param p_name the organization's name
%param p_description description of the manufacturer
%param p_created_on when the party was created
%param p_mktp_ref the mktp's unique reference
%param p_lt_7b_contract_ref
%param p_gt_7b_contract_ref
%param p_adversarial_contract_ref
%param p_username the username
%param p_status the status of the user
%param p_first_name the user's first name
%param p_last_name the user's last name
%param p_personal_title the user's title
%param p_comments any comments on the user
%param p_id the unique party id
%param p_prty_type the prty type
*/
PROCEDURE create_party(p_manu_ref IN VARCHAR2,
p_created_by IN VARCHAR2,
p_shortcode IN VARCHAR2,
p_name IN VARCHAR2,
p_description IN VARCHAR2,
p_mktp_ref IN VARCHAR2,
p_lt_7b_contract_ref IN VARCHAR2,
p_gt_7b_contract_ref IN VARCHAR2,
p_adversarial_contract_ref IN VARCHAR2,
p_username IN VARCHAR2,
p_first_name IN VARCHAR2,
p_last_name IN VARCHAR2,
p_personal_title IN VARCHAR2,
p_comments IN VARCHAR2,
p_id IN INTEGER,
p_prty_type IN VARCHAR2,
p_password IN VARCHAR2,
p_expire_pword IN NUMBER);
--
PROCEDURE create_party_address(p_addr_code IN addresses.code%TYPE,
p_prty_id IN parties.id%TYPE,
p_addr_type IN VARCHAR2);
--
/**
create party contact details
*/
PROCEDURE create_party_contact_details(p_prty_id IN parties.id%TYPE,
p_contact_mech_type IN VARCHAR2,
p_contact_value IN VARCHAR2);
--
END mip_parties; END mip_parties;
/ /
CREATE OR REPLACE PACKAGE BODY mip_parties AS CREATE OR REPLACE PACKAGE BODY mip_parties AS
@@ -58,16 +110,20 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
UPDATES UPDATES
20-Nov-2007 - MM- Upper ing the username check as APEX passes an uppered :APP_USER 20-Nov-2007 - MM- Upper ing the username check as APEX passes an uppered :APP_USER
*/ */
FUNCTION get_user_id(p_username IN VARCHAR2) return NUMBER as userid NUMBER; FUNCTION get_user_id(p_username IN VARCHAR2) RETURN NUMBER AS
cursor c_userid is select id from parties where upper(USERNAME) = upper(p_username); userid NUMBER;
begin CURSOR c_userid IS
open c_userid; SELECT id FROM parties WHERE upper(username) = upper(p_username);
fetch c_userid into userid; BEGIN
close c_userid; OPEN c_userid;
return userid; FETCH c_userid
exception INTO userid;
when others then return null; CLOSE c_userid;
end get_user_id; RETURN userid;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END get_user_id;
/* /*
FUNCTION get_user_role FUNCTION get_user_role
@@ -76,16 +132,22 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
- That id is used to search the party_roles table to get the role keycode. - That id is used to search the party_roles table to get the role keycode.
%param p_username - the name of the user you want to get the id for. %param p_username - the name of the user you want to get the id for.
*/ */
FUNCTION get_user_role(p_username IN VARCHAR2) return varchar2 as rolecode varchar2(80); FUNCTION get_user_role(p_username IN VARCHAR2) RETURN VARCHAR2 AS
cursor c_userrole is select rt_code from party_roles where PRTY_ID = get_user_id(p_username); rolecode VARCHAR2(80);
begin CURSOR c_userrole IS
open c_userrole; SELECT rt_code
fetch c_userrole into rolecode; FROM party_roles
close c_userrole; WHERE prty_id = get_user_id(p_username);
return rolecode; BEGIN
exception OPEN c_userrole;
when others then return null; FETCH c_userrole
end get_user_role; INTO rolecode;
CLOSE c_userrole;
RETURN rolecode;
EXCEPTION
WHEN OTHERS THEN
RETURN NULL;
END get_user_role;
-- --
/** get the password created date for the given username and password /** get the password created date for the given username and password
@@ -93,46 +155,64 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
%return DATE the date the password was created for authenticated username and password combination %return DATE the date the password was created for authenticated username and password combination
*/ */
FUNCTION get_user_password_created(p_username IN VARCHAR2 FUNCTION get_user_password_created(p_username IN VARCHAR2,
,p_password IN VARCHAR2) RETURN DATE AS p_password IN VARCHAR2) RETURN DATE AS
l_password_created_on DATE; l_password_created_on DATE;
BEGIN BEGIN
SELECT created_on SELECT created_on
INTO l_password_created_on INTO l_password_created_on
FROM (SELECT pwd.prty_id FROM (SELECT pwd.prty_id,
,pwd.password_hash pwd.password_hash,
,MAX(pwd.created_on) over(PARTITION BY pwd.prty_id) AS latest_pwd_date MAX(pwd.created_on) over(PARTITION BY pwd.prty_id) AS latest_pwd_date,
,pwd.created_on pwd.created_on
FROM passwords pwd FROM passwords pwd, parties prty
,parties prty
WHERE upper(prty.username) = upper(p_username) WHERE upper(prty.username) = upper(p_username)
AND pwd.prty_id = prty.id) pwd AND pwd.prty_id = prty.id) pwd
WHERE pwd.created_on = pwd.latest_pwd_date WHERE pwd.created_on = pwd.latest_pwd_date
AND pwd.password_hash = mip_security.get_hash(p_username AND pwd.password_hash =
,p_password); mip_security.get_hash(p_username, p_password);
RETURN l_password_created_on; RETURN l_password_created_on;
END get_user_password_created; END get_user_password_created;
-- --
--
-- adds a new party address if required.
-- --
PROCEDURE add_address(p_address addresses%ROWTYPE) AS PROCEDURE add_address(p_address addresses%ROWTYPE) AS
-- --
BEGIN BEGIN
-- --
--not implemented yet - will allow us to check the password is valid based on rule in the functional spec -- check all columns are identical
-- check_password(p_password); -- if they match do nothing, we are reusing an existing address
INSERT INTO addresses -- otherwsie INSERT a new record.
(code, sub_building, building, street, city, postcode) --
VALUES MERGE INTO addresses addr
(to_char(prty_seq.NEXTVAL), USING (SELECT p_address.code AS code,
p_address.sub_building, p_address.sub_building AS sub_building,
p_address.building, p_address.building AS building,
p_address.street, p_address.street AS street,
p_address.city, p_address.city AS city,
p_address.postcode); p_address.postcode AS postcode
FROM dual) l_addr
ON (addr.code = l_addr.code AND
addr.sub_building = l_addr.sub_building AND
addr.building = l_addr.building AND
addr.street = l_addr.street AND
addr.city = l_addr.city AND
addr.postcode = p_address.postcode)
WHEN NOT MATCHED THEN
INSERT
(code, sub_building, building, street, city, postcode)
VALUES
(l_addr.code,
l_addr.sub_building,
l_addr.building,
l_addr.street,
l_addr.city,
l_addr.postcode);
COMMIT; --COMMIT;
-- --
EXCEPTION EXCEPTION
WHEN OTHERS THEN WHEN OTHERS THEN
@@ -140,8 +220,7 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
RAISE; RAISE;
END add_address; END add_address;
/*
/*
PROCEDURE add_party PROCEDURE add_party
- allows an admin user to create new parties for use in the system - allows an admin user to create new parties for use in the system
%param p_username - the name of the user to create %param p_username - the name of the user to create
@@ -151,25 +230,25 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
*/ */
-- --
PROCEDURE add_party(p_role IN VARCHAR2, PROCEDURE add_party(p_role IN VARCHAR2,
p_username IN VARCHAR2, p_username IN VARCHAR2,
p_created_by IN VARCHAR2, p_created_by IN VARCHAR2,
p_name IN VARCHAR2, p_name IN VARCHAR2,
p_mkpt_ref IN VARCHAR2, p_mkpt_ref IN VARCHAR2,
p_shortcode IN VARCHAR2, p_shortcode IN VARCHAR2,
p_lt_7b_contract_ref IN VARCHAR2, p_lt_7b_contract_ref IN VARCHAR2,
p_gt_7b_contract_ref IN VARCHAR2, p_gt_7b_contract_ref IN VARCHAR2,
p_adversarial_contract_ref IN VARCHAR2, p_adversarial_contract_ref IN VARCHAR2,
p_manu_ref IN VARCHAR2, p_manu_ref IN VARCHAR2,
p_description IN VARCHAR2, p_description IN VARCHAR2,
p_status IN VARCHAR2, p_status IN VARCHAR2,
p_first_name IN VARCHAR2, p_first_name IN VARCHAR2,
p_last_name IN VARCHAR2, p_last_name IN VARCHAR2,
p_personal_title IN VARCHAR2, p_personal_title IN VARCHAR2,
p_comments IN VARCHAR2, p_comments IN VARCHAR2,
p_addresscode IN VARCHAR2, p_addresscode IN VARCHAR2,
p_partyrole IN VARCHAR2, p_partyrole IN VARCHAR2,
p_partycontactmech IN VARCHAR2) AS p_partycontactmech IN VARCHAR2) AS
-- --
partyid NUMBER; partyid NUMBER;
BEGIN BEGIN
@@ -182,7 +261,7 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
prty_type, prty_type,
created_on, created_on,
created_by, created_by,
name, NAME,
mktp_ref, mktp_ref,
shortcode, shortcode,
lt_7b_contract_ref, lt_7b_contract_ref,
@@ -216,26 +295,25 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
p_first_name, p_first_name,
p_last_name, p_last_name,
p_personal_title, p_personal_title,
p_comments p_comments)
)
RETURNING parties.id INTO partyid; RETURNING parties.id INTO partyid;
--COMMIT; --COMMIT;
--call the partyaddress to fill in the link between the party and the address --call the partyaddress to fill in the link between the party and the address
if p_addresscode IS NOT NULL then IF p_addresscode IS NOT NULL THEN
add_partyaddress(p_addresscode, partyid); add_partyaddress(p_addresscode, partyid);
end if; END IF;
-- call the party role to fill in the link between party and the role -- call the party role to fill in the link between party and the role
if p_partyrole IS NOT NULL then IF p_partyrole IS NOT NULL THEN
add_partyrole(p_partyrole, partyid); add_partyrole(p_partyrole, partyid);
end if; END IF;
-- call the party contact mechanism to link the party to a contact mech -- call the party contact mechanism to link the party to a contact mech
if p_partycontactmech IS NOT NULL then IF p_partycontactmech IS NOT NULL THEN
add_partycontactmech(p_partycontactmech, partyid); add_partycontactmech(p_partycontactmech, partyid);
end if; END IF;
-- --
END add_party; END add_party;
/* /*
PROCEDURE add_partyaddress PROCEDURE add_partyaddress
- allows the association of a party to a number of addresses - allows the association of a party to a number of addresses
%param p_username - the name of the user to create %param p_username - the name of the user to create
@@ -245,18 +323,18 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
*/ */
-- --
PROCEDURE add_partyaddress(p_addr_code IN VARCHAR2, p_prty_id IN INTEGER) AS PROCEDURE add_partyaddress(p_addr_code IN VARCHAR2, p_prty_id IN INTEGER) AS
-- --
l_addr_code addresses.code%TYPE; l_addr_code addresses.code%TYPE;
l_working_code addresses.code%TYPE; l_working_code addresses.code%TYPE;
-- --
BEGIN BEGIN
l_addr_code := p_addr_code || ':'; l_addr_code := p_addr_code || ':';
--not implemented yet - will allow us to check the password is valid based on rule in the functional spec --not implemented yet - will allow us to check the password is valid based on rule in the functional spec
-- check_password(p_password); -- check_password(p_password);
LOOP LOOP
-- --
l_working_code := SUBSTR(l_addr_code, 1, INSTR(l_addr_code, ':')-1); l_working_code := substr(l_addr_code, 1, instr(l_addr_code, ':') - 1);
-- --
IF l_working_code IS NULL THEN IF l_working_code IS NULL THEN
EXIT; EXIT;
@@ -267,13 +345,13 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
VALUES VALUES
(l_working_code, p_prty_id, SYSDATE, SYSDATE, 'The comments field'); (l_working_code, p_prty_id, SYSDATE, SYSDATE, 'The comments field');
-- --
l_addr_code := SUBSTR(l_addr_code, INSTR(l_addr_code, ':')+1); l_addr_code := substr(l_addr_code, instr(l_addr_code, ':') + 1);
-- --
END LOOP; END LOOP;
-- --
END add_partyaddress; END add_partyaddress;
PROCEDURE add_partyrole(p_role_code IN VARCHAR2, p_prty_id IN NUMBER) AS PROCEDURE add_partyrole(p_role_code IN VARCHAR2, p_prty_id IN NUMBER) AS
-- --
BEGIN BEGIN
-- --
@@ -281,7 +359,12 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
INSERT INTO party_roles INSERT INTO party_roles
(id, rt_code, prty_id, start_date, end_date, description) (id, rt_code, prty_id, start_date, end_date, description)
VALUES VALUES
(prty_seq.NEXTVAL, p_role_code, p_prty_id, SYSDATE, SYSDATE, 'createwd via plsql procedure add_partyrole'); (prty_seq.NEXTVAL,
p_role_code,
p_prty_id,
SYSDATE,
SYSDATE,
'createwd via plsql procedure add_partyrole');
COMMIT; COMMIT;
-- --
@@ -290,7 +373,7 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
ROLLBACK; ROLLBACK;
RAISE; RAISE;
END add_partyrole; END add_partyrole;
/* /*
PROCEDURE add_partycontactmech PROCEDURE add_partycontactmech
- allows the association of a party to a number of addresses - allows the association of a party to a number of addresses
%param p_contact_mech - the name of the contact mechanism code %param p_contact_mech - the name of the contact mechanism code
@@ -298,25 +381,28 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
*/ */
-- --
PROCEDURE add_partycontactmech(p_contact_mech IN VARCHAR2, p_prty_id IN NUMBER) AS PROCEDURE add_partycontactmech(p_contact_mech IN VARCHAR2,
-- p_prty_id IN NUMBER) AS
l_contact_mech contact_mechanisms.comt_code%TYPE; --
l_working_code contact_mechanisms.comt_code%TYPE; l_contact_mech contact_mechanisms.comt_code%TYPE;
comeid contact_mechanisms.id%TYPE; l_working_code contact_mechanisms.comt_code%TYPE;
--l_contact_mech_role contact_mechanisms.comt_code%TYPE; comeid contact_mechanisms.id%TYPE;
--l_working_role contact_mechanisms.comt_code%TYPE; --l_contact_mech_role contact_mechanisms.comt_code%TYPE;
--pcmr_id party_contact_mechanism_roles.id%TYPE --l_working_role contact_mechanisms.comt_code%TYPE;
--pcmr_id party_contact_mechanism_roles.id%TYPE
-- --
-- get the contact mech type -- get the contact mech type
-- create a new contact mech using the type code -- create a new contact mech using the type code
-- create a new party contact mech from the partyid and the newly created contact mech -- create a new party contact mech from the partyid and the newly created contact mech
BEGIN BEGIN
l_contact_mech := p_contact_mech || ':'; l_contact_mech := p_contact_mech || ':';
LOOP LOOP
-- --
l_working_code := SUBSTR(l_contact_mech, 1, INSTR(l_contact_mech, ':')-1); l_working_code := substr(l_contact_mech,
1,
instr(l_contact_mech, ':') - 1);
-- --
IF l_working_code IS NULL THEN IF l_working_code IS NULL THEN
EXIT; EXIT;
@@ -327,11 +413,10 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
-- --
(comt_code, contact_value, id) (comt_code, contact_value, id)
VALUES VALUES
(l_working_code, (l_working_code, 'dunno what this field is for', come_seq.NEXTVAL)
'dunno what this field is for', RETURNING contact_mechanisms.id INTO comeid;
come_seq.nextval) RETURNING contact_mechanisms.id INTO comeid;
/*-- Create the Party contact mechanism role /*-- Create the Party contact mechanism role
--Think this needs to be sorted out much like the contact mechanism listed --Think this needs to be sorted out much like the contact mechanism listed
--above, however not sure about the model and what AH intended --above, however not sure about the model and what AH intended
@@ -350,7 +435,8 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
VALUES VALUES
(comeid, p_prty_id, SYSDATE, SYSDATE, 'The comments field'); (comeid, p_prty_id, SYSDATE, SYSDATE, 'The comments field');
-- --
l_contact_mech := SUBSTR(l_contact_mech, INSTR(l_contact_mech, ':')+1); l_contact_mech := substr(l_contact_mech,
instr(l_contact_mech, ':') + 1);
-- --
END LOOP; END LOOP;
-- --
@@ -366,21 +452,175 @@ CREATE OR REPLACE PACKAGE BODY mip_parties AS
%param p_username - the name of the user you want to find the supplier for. %param p_username - the name of the user you want to find the supplier for.
%param p_supplierid - the id of the supplier you want to check the user against. %param p_supplierid - the id of the supplier you want to check the user against.
*/ */
FUNCTION has_supplier(p_username IN VARCHAR2, p_supplierid IN VARCHAR) return boolean as FUNCTION has_supplier(p_username IN VARCHAR2, p_supplierid IN VARCHAR)
cursor c_userrole is select ID RETURN BOOLEAN AS
from PARTIES p, PARTY_RELATIONSHIPS pr CURSOR c_userrole IS
where p.ID = pr.TO_PARL_PRTY_ID SELECT id
and pr.FROM_PARL_PRTY_ID = get_user_id(p_username) FROM parties p, party_relationships pr
and pr.TO_PARL_RT_CODE = 'SUPP' WHERE p.id = pr.to_parl_prty_id
and pr.FROM_PARL_RT_CODE = 'AGENT'; AND pr.from_parl_prty_id = get_user_id(p_username)
begin AND pr.to_parl_rt_code = 'SUPP'
for userrole_rec in c_userrole loop AND pr.from_parl_rt_code = 'AGENT';
if p_supplierid = userrole_rec.id then BEGIN
return true; FOR userrole_rec IN c_userrole LOOP
end if; IF p_supplierid = userrole_rec.id THEN
end loop; RETURN TRUE;
return false; END IF;
end has_supplier; END LOOP;
RETURN FALSE;
END has_supplier;
/** allows new parties to be created in the system.
%param p_manu_ref the manufacturer's unique reference
%param p_created_by the user that created the party
%param p_shortcode the mktp short code
%param p_name the organization's name
%param p_description description of the manufacturer
%param p_created_on when the party was created
%param p_mktp_ref the mktp's unique reference
%param p_lt_7b_contract_ref
%param p_gt_7b_contract_ref
%param p_adversarial_contract_ref
%param p_username the username
%param p_status the status of the user
%param p_first_name the user's first name
%param p_last_name the user's last name
%param p_personal_title the user's title
%param p_comments any comments on the user
%param p_id the unique party id
%param p_prty_type the prty type
*/
PROCEDURE create_party(p_manu_ref IN VARCHAR2,
p_created_by IN VARCHAR2,
p_shortcode IN VARCHAR2,
p_name IN VARCHAR2,
p_description IN VARCHAR2,
p_mktp_ref IN VARCHAR2,
p_lt_7b_contract_ref IN VARCHAR2,
p_gt_7b_contract_ref IN VARCHAR2,
p_adversarial_contract_ref IN VARCHAR2,
p_username IN VARCHAR2,
p_first_name IN VARCHAR2,
p_last_name IN VARCHAR2,
p_personal_title IN VARCHAR2,
p_comments IN VARCHAR2,
p_id IN INTEGER,
p_prty_type IN VARCHAR2,
p_password IN VARCHAR2,
p_expire_pword IN NUMBER) IS
--
BEGIN
--
INSERT INTO parties
(id,
manu_ref,
created_by,
shortcode,
NAME,
description,
created_on,
mktp_ref,
lt_7b_contract_ref,
gt_7b_contract_ref,
adversarial_contract_ref,
username,
first_name,
last_name,
personal_title,
comments,
prty_type)
VALUES
(p_id,
p_manu_ref,
p_created_by,
p_shortcode,
p_name,
p_description,
SYSDATE,
p_mktp_ref,
p_lt_7b_contract_ref,
p_gt_7b_contract_ref,
p_adversarial_contract_ref,
upper(p_username),
p_first_name,
p_last_name,
p_personal_title,
p_comments,
p_prty_type);
-- if we created a user they need a password creating
IF upper(p_prty_type) = 'PERS' THEN
mip_security.other_user_password(p_prty_id => p_id,
p_username => p_username,
p_password => p_password);
-- set the user's status
IF p_expire_pword IS NOT NULL THEN
mip_security.set_user_status(p_username => p_username,
p_status => 'EXPIRED');
ELSE
-- just open the user
mip_security.set_user_status(p_username => p_username,
p_status => 'OPEN');
END IF;
END IF;
--
END create_party;
--
/**
associate an address with a party
%param p_addr_code the code of the address
%param p_prty_id the party's unique ID
%param p_addr_type the type of address, either HOME or OFFICE
*/
PROCEDURE create_party_address(p_addr_code IN addresses.code%TYPE,
p_prty_id IN parties.id%TYPE,
p_addr_type IN VARCHAR2) IS
BEGIN
INSERT INTO party_addresses
(addr_code, prty_id, start_date, end_date, comments)
VALUES
(p_addr_code,
p_prty_id,
SYSDATE,
NULL,
'Party address created by ' || v('APP_USER'));
INSERT INTO party_address_roles
(start_date,
paddr_addr_code,
paddr_prty_id,
paddr_start_date,
rt_code,
end_date)
VALUES
(SYSDATE, p_addr_code, p_prty_id, SYSDATE, p_addr_type, NULL);
END create_party_address;
--
/**
create party contact details
*/
PROCEDURE create_party_contact_details(p_prty_id IN parties.id%TYPE,
p_contact_mech_type IN VARCHAR2,
p_contact_value IN VARCHAR2) IS
l_come_id NUMBER;
BEGIN
SELECT come_seq.NEXTVAL INTO l_come_id FROM dual;
-- insert the contact mechanism value
INSERT INTO contact_mechanisms(comt_code, contact_value, id)
VALUES(p_contact_mech_type, p_contact_value, l_come_id);
-- associate the contact mechanism with the party.
INSERT INTO party_contact_mechanisms(come_id, prty_id, start_date)
VALUES(l_come_id, p_prty_id, SYSDATE);
END create_party_contact_details;
END mip_parties; END mip_parties;
/ /

View File

@@ -51,6 +51,19 @@ recordThe resultant hash is recorded as the username 'password hash'
PROCEDURE new_password(p_username IN VARCHAR2 PROCEDURE new_password(p_username IN VARCHAR2
,p_password IN VARCHAR2); ,p_password IN VARCHAR2);
/*
creates a new password for another user
*/
PROCEDURE other_user_password(p_prty_id IN number,
p_username IN VARCHAR2,
p_password IN VARCHAR2);
--
/** Updates the user status
*/
PROCEDURE set_user_status(p_username IN VARCHAR2, p_status IN VARCHAR2);
--
/** Authorize access to the given page /** Authorize access to the given page
%param p_app_user The name of the application user %param p_app_user The name of the application user
%param p_page_id The page to be accessed %param p_page_id The page to be accessed
@@ -483,6 +496,33 @@ CREATE OR REPLACE PACKAGE BODY mip_security AS
,SQLERRM); ,SQLERRM);
END new_password; END new_password;
-- --
/*
creates a new password for another user
*/
PROCEDURE other_user_password(p_prty_id IN number,
p_username IN VARCHAR2,
p_password IN VARCHAR2) IS
BEGIN
INSERT INTO passwords
(prty_id
,password_hash
,created_on
,created_by)
VALUES
(p_prty_id
,get_hash(p_username
,p_password)
,SYSDATE
,NULL);
EXCEPTION
WHEN OTHERS THEN
raise_application_error(-20002
,SQLERRM);
END other_user_password;
--
-- --
PROCEDURE redirect_on_expired_account(p_username IN VARCHAR2) IS PROCEDURE redirect_on_expired_account(p_username IN VARCHAR2) IS
BEGIN BEGIN