6 commits - java/code schema/spacewalk
by Michael Mraka
java/code/src/com/redhat/rhn/common/db/datasource/xml/Channel_queries.xml | 4
java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java | 11
java/code/src/com/redhat/rhn/manager/user/UserManager.java | 9
schema/spacewalk/oracle/packages/rhn_channel.pkb | 46
schema/spacewalk/oracle/packages/rhn_channel.pks | 4
schema/spacewalk/postgres/packages/rhn_channel.pkb | 56
schema/spacewalk/postgres/packages/rhn_channel.pks | 2
schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/001-rhn_channel.pkb.sql.oracle | 1220 ---------
schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/001-rhn_channel.pkb.sql.postgresql | 1
schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/048-rhn_channel.pkb.sql.oracle | 1
schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/048-rhn_channel.pkb.sql.postgresql | 62
schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/051-rhn_channel.pkb.sql.oracle | 1222 ++++++++++
schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/051-rhn_channel.pkb.sql.postgresql | 131 +
schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/052-rhn_channel.pks.sql.oracle | 148 +
schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/052-rhn_channel.pks.sql.postgresql | 2
15 files changed, 1567 insertions(+), 1352 deletions(-)
New commits:
commit 7ddb375287397cf326120d3870ee3305596c04a2
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Tue May 29 11:35:53 2012 +0200
upgrade scripts for rhn_channel.pks
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/052-rhn_channel.pks.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/052-rhn_channel.pks.sql.oracle
new file mode 100644
index 0000000..b5f280c
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/052-rhn_channel.pks.sql.oracle
@@ -0,0 +1,148 @@
+--
+-- Copyright (c) 2008--2012 Red Hat, Inc.
+--
+-- This software is licensed to you under the GNU General Public License,
+-- version 2 (GPLv2). There is NO WARRANTY for this software, express or
+-- implied, including the implied warranties of MERCHANTABILITY or FITNESS
+-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+-- along with this software; if not, see
+-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+--
+-- Red Hat trademarks are not licensed under GPLv2. No permission is
+-- granted to use or replicate Red Hat trademarks that are incorporated
+-- in this software or its documentation.
+--
+
+CREATE OR REPLACE
+PACKAGE rhn_channel
+IS
+ version varchar2(100) := '';
+
+ CURSOR server_base_subscriptions(server_id_in NUMBER) IS
+ SELECT C.id
+ FROM rhnChannel C, rhnServerChannel SC
+ WHERE C.id = SC.channel_id
+ AND SC.server_id = server_id_in
+ AND C.parent_channel IS NULL;
+
+ CURSOR check_server_subscription(server_id_in NUMBER, channel_id_in NUMBER) IS
+ SELECT channel_id
+ FROM rhnServerChannel
+ WHERE server_id = server_id_in
+ AND channel_id = channel_id_in;
+
+ CURSOR check_server_parent_membership(server_id_in NUMBER, channel_id_in NUMBER) IS
+ SELECT C.id
+ FROM rhnChannel C, rhnServerChannel SC
+ WHERE C.parent_channel = channel_id_in
+ AND C.id = SC.channel_id
+ AND SC.server_id = server_id_in;
+
+ CURSOR channel_family_perm_cursor(channel_family_id_in NUMBER, org_id_in NUMBER) IS
+ SELECT *
+ FROM rhnOrgChannelFamilyPermissions
+ WHERE channel_family_id = channel_family_id_in
+ AND org_id = org_id_in;
+
+
+ PROCEDURE unsubscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, unsubscribe_children_in number := 0,
+ deleting_server in number := 0,
+ update_family_countsYN IN NUMBER := 1);
+ PROCEDURE subscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, user_id_in number := null, recalcfamily_in number := 1);
+
+ PROCEDURE convert_to_fve(server_id_in IN NUMBER, channel_family_id_val IN NUMBER);
+
+ FUNCTION can_convert_to_fve(server_id_in IN NUMBER, channel_family_id_val IN NUMBER) RETURN NUMBER;
+
+ function can_server_consume_virt_channl(
+ server_id_in IN NUMBER,
+ family_id_in in number)
+ return number;
+ FUNCTION can_server_consume_fve( server_id_in IN NUMBER) RETURN NUMBER;
+
+ FUNCTION guess_server_base(server_id_in IN NUMBER) RETURN NUMBER;
+
+ FUNCTION base_channel_for_release_arch(release_in in varchar2,
+ server_arch_in in varchar2, org_id_in in number := -1,
+ user_id_in in number := null) RETURN number;
+
+ FUNCTION base_channel_rel_archid(release_in in varchar2,
+ server_arch_id_in in number, org_id_in in number := -1,
+ user_id_in in number := null) RETURN number;
+
+ FUNCTION channel_priority(channel_id_in in number) RETURN number;
+
+ PROCEDURE clear_subscriptions(server_id_in IN NUMBER, deleting_server in number := 0,
+ update_family_countsYN IN NUMBER := 1);
+
+ FUNCTION available_family_subscriptions(channel_family_id_in IN NUMBER, org_id_in IN NUMBER) RETURN NUMBER;
+
+ FUNCTION available_fve_family_subs(channel_family_id_in IN NUMBER, org_id_in IN NUMBER) RETURN NUMBER;
+
+ FUNCTION channel_family_current_members(channel_family_id_in IN NUMBER, org_id_in IN NUMBER) return number;
+
+ FUNCTION cfam_curr_fve_members(channel_family_id_in IN NUMBER, org_id_in IN NUMBER) return number;
+
+ PROCEDURE update_family_counts(channel_family_id_in IN NUMBER, org_id_in IN NUMBER);
+ PROCEDURE update_group_family_counts(group_label_in IN VARCHAR2, org_id_in IN NUMBER);
+ FUNCTION family_for_channel(channel_id_in IN NUMBER) RETURN NUMBER;
+
+ FUNCTION available_chan_subscriptions(channel_id_in IN NUMBER, org_id_in IN NUMBER) RETURN NUMBER;
+
+ FUNCTION available_fve_chan_subs(channel_id_in IN NUMBER, org_id_in IN NUMBER) RETURN NUMBER;
+
+ PROCEDURE unsubscribe_server_from_family(server_id_in in number, channel_family_id_in in number);
+
+ PROCEDURE delete_server_channels(server_id_in in number);
+
+ PROCEDURE refresh_newest_package(channel_id_in in number,
+ caller_in in varchar2 := '(unknown)',
+ package_name_id_in in number := null);
+
+ FUNCTION get_org_id(channel_id_in in number) return number;
+ PRAGMA RESTRICT_REFERENCES(get_org_id, WNDS, RNPS, WNPS);
+
+ function get_org_access(channel_id_in in number, org_id_in in number) return number;
+ PRAGMA RESTRICT_REFERENCES(get_org_access, WNDS, RNPS, WNPS);
+
+ function get_cfam_org_access(cfam_id_in in number, org_id_in in number) return number;
+
+ function user_role_check_debug(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ RETURN VARCHAR2;
+ PRAGMA RESTRICT_REFERENCES(user_role_check_debug, WNDS, RNPS, WNPS);
+
+ function user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ RETURN NUMBER;
+ PRAGMA RESTRICT_REFERENCES(user_role_check, WNDS, RNPS, WNPS);
+
+ function loose_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ RETURN NUMBER;
+ PRAGMA RESTRICT_REFERENCES(loose_user_role_check, WNDS, RNPS, WNPS);
+
+ function direct_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ RETURN NUMBER;
+ PRAGMA RESTRICT_REFERENCES(direct_user_role_check, WNDS, RNPS, WNPS);
+
+ function shared_user_role_check(channel_id in number, user_id in number, role in varchar2)
+ RETURN NUMBER;
+ PRAGMA RESTRICT_REFERENCES(shared_user_role_check, WNDS, RNPS, WNPS);
+
+ function org_channel_setting(channel_id_in in number, org_id_in in number, setting_in in varchar2)
+ RETURN NUMBER;
+
+ PROCEDURE update_channel ( channel_id_in in number, invalidate_ss in number := 0,
+ date_to_use in date := sysdate );
+
+ PROCEDURE update_channels_by_package ( package_id_in in number, date_to_use in date := sysdate );
+
+ PROCEDURE update_channels_by_errata ( errata_id_in number, date_to_use in date := sysdate );
+
+
+ PRAGMA RESTRICT_REFERENCES(org_channel_setting, WNDS, RNPS, WNPS);
+
+ PROCEDURE update_needed_cache(channel_id_in in number);
+
+
+END rhn_channel;
+/
+SHOW ERRORS
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/052-rhn_channel.pks.sql.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/052-rhn_channel.pks.sql.postgresql
new file mode 100644
index 0000000..47dade5
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/052-rhn_channel.pks.sql.postgresql
@@ -0,0 +1,2 @@
+--- oracle equivalent source sha1 88c2a4bfc43924379a2a23de123995dfe61f4483
+--- This file has intentionally been left empty.
commit 43979b144561cffc00d0f0fc7d0c81d533c8c984
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Tue May 29 11:31:01 2012 +0200
fixed equivalent source sha1s
diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pkb b/schema/spacewalk/postgres/packages/rhn_channel.pkb
index a1e348b..e06892a 100644
--- a/schema/spacewalk/postgres/packages/rhn_channel.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_channel.pkb
@@ -1,4 +1,4 @@
--- oracle equivalent source sha1 6e73be65e01c5fe26f2630cc52f2fa5f16747d22
+-- oracle equivalent source sha1 d4a14b83901ab741e9eeaf7ff51be401a70b4bb5
--
-- Copyright (c) 2008--2012 Red Hat, Inc.
--
diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pks b/schema/spacewalk/postgres/packages/rhn_channel.pks
index f812144..e8e5780 100644
--- a/schema/spacewalk/postgres/packages/rhn_channel.pks
+++ b/schema/spacewalk/postgres/packages/rhn_channel.pks
@@ -1,4 +1,4 @@
--- oracle equivalent source sha1 4b4523852e4b71efdd41bda69e7492793717252a
+-- oracle equivalent source sha1 88c2a4bfc43924379a2a23de123995dfe61f4483
create schema rhn_channel;
commit 001d74616637e1be61750af61b601080de69007c
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Tue May 29 11:28:07 2012 +0200
changes from 001 and 048 files have been merged into 051-* upgrade file
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/001-rhn_channel.pkb.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/001-rhn_channel.pkb.sql.oracle
deleted file mode 100644
index fa1968a..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/001-rhn_channel.pkb.sql.oracle
+++ /dev/null
@@ -1,1220 +0,0 @@
---
--- Copyright (c) 2008--2012 Red Hat, Inc.
---
--- This software is licensed to you under the GNU General Public License,
--- version 2 (GPLv2). There is NO WARRANTY for this software, express or
--- implied, including the implied warranties of MERCHANTABILITY or FITNESS
--- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
--- along with this software; if not, see
--- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
---
--- Red Hat trademarks are not licensed under GPLv2. No permission is
--- granted to use or replicate Red Hat trademarks that are incorporated
--- in this software or its documentation.
---
-
-CREATE OR REPLACE
-PACKAGE BODY rhn_channel
-IS
- body_version varchar2(100) := '';
-
- -- Cursor that fetches all the possible base channels for a
- -- (server_arch_id, release, org_id) combination
- cursor base_channel_cursor(
- release_in in varchar2,
- server_arch_id_in in number,
- org_id_in in number
- ) return rhnChannel%ROWTYPE is
- select distinct c.*
- from rhnDistChannelMap dcm,
- rhnServerChannelArchCompat scac,
- rhnChannel c,
- rhnChannelPermissions cp
- where cp.org_id = org_id_in
- and cp.channel_id = c.id
- and c.parent_channel is null
- and c.id = dcm.channel_id
- and c.channel_arch_id = dcm.channel_arch_id
- and dcm.release = release_in
- and scac.server_arch_id = server_arch_id_in
- and scac.channel_arch_id = c.channel_arch_id;
-
- procedure obtain_read_lock(channel_family_id_in in number, org_id_in in number)
- is
- read_lock date;
-
- begin
- select created into read_lock
- from rhnPrivateChannelFamily
- where channel_family_id = channel_family_id_in and org_id = org_id_in
- for update;
- end obtain_read_lock;
-
- PROCEDURE subscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, user_id_in in number := null, recalcfamily_in number := 1)
- IS
- channel_parent_val rhnChannel.parent_channel%TYPE;
- parent_subscribed BOOLEAN;
- server_has_base_chan BOOLEAN;
- server_already_in_chan BOOLEAN;
- channel_family_id_val NUMBER;
- server_org_id_val NUMBER;
- available_subscriptions NUMBER;
- available_fve_subs NUMBER;
- consenting_user NUMBER;
- allowed number := 0;
- is_fve CHAR(1) := 'N';
- BEGIN
- if user_id_in is not null then
- allowed := rhn_channel.user_role_check(channel_id_in, user_id_in, 'subscribe');
- else
- allowed := 1;
- end if;
-
- if allowed = 0 then
- rhn_exception.raise_exception('no_subscribe_permissions');
- end if;
-
-
- SELECT parent_channel INTO channel_parent_val FROM rhnChannel WHERE id = channel_id_in;
-
- IF channel_parent_val IS NOT NULL
- THEN
- -- child channel; if attempting to cross-subscribe a child to the wrong base, silently ignore
- parent_subscribed := FALSE;
-
- FOR check_subscription IN check_server_subscription(server_id_in, channel_parent_val)
- LOOP
- parent_subscribed := TRUE;
- END LOOP check_subscription;
-
- IF NOT parent_subscribed
- THEN
- RETURN;
- END IF;
- ELSE
- -- base channel
- server_has_base_chan := FALSE;
- FOR base IN server_base_subscriptions(server_id_in)
- LOOP
- server_has_base_chan := TRUE;
- END LOOP base;
-
- IF server_has_base_chan
- THEN
- rhn_exception.raise_exception('channel_server_one_base');
- END IF;
- END IF;
-
- FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
- LOOP
- server_already_in_chan := TRUE;
- END LOOP check_subscription;
-
- IF server_already_in_chan
- THEN
- RETURN;
- END IF;
-
- channel_family_id_val := rhn_channel.family_for_channel(channel_id_in);
- IF channel_family_id_val IS NULL
- THEN
- rhn_exception.raise_exception('channel_subscribe_no_family');
- END IF;
-
- --
- -- Use the org_id of the server only if the org_id of the channel = NULL.
- -- This is required for subscribing to shared channels.
- --
- SELECT NVL(org_id, (SELECT org_id FROM rhnServer WHERE id = server_id_in))
- INTO server_org_id_val
- FROM rhnChannel
- WHERE id = channel_id_in;
-
- begin
- obtain_read_lock(channel_family_id_val, server_org_id_val);
- exception
- when no_data_found then
- rhn_exception.raise_exception('channel_family_no_subscriptions');
- end;
-
- available_subscriptions := rhn_channel.available_family_subscriptions(channel_family_id_val, server_org_id_val);
- available_fve_subs := rhn_channel.available_fve_family_subs(channel_family_id_val, server_org_id_val);
-
- IF available_subscriptions IS NULL OR
- available_subscriptions > 0 or
- can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 1 OR
- (available_fve_subs > 0 AND can_server_consume_fve(server_id_in) = 1)
- THEN
- if can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 0 AND available_fve_subs > 0 AND can_server_consume_fve(server_id_in) = 1 THEN
- is_fve := 'Y';
- END IF;
- insert into rhnServerHistory (id,server_id,summary,details) (
- select rhn_event_id_seq.nextval,
- server_id_in,
- 'subscribed to channel ' || SUBSTR(c.label, 0, 106),
- c.label
- from rhnChannel c
- where c.id = channel_id_in
- );
- UPDATE rhnServer SET channels_changed = sysdate WHERE id = server_id_in;
- INSERT INTO rhnServerChannel (server_id, channel_id, is_fve) VALUES (server_id_in, channel_id_in, is_fve);
- IF recalcfamily_in > 0
- THEN
- rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
- END IF;
- queue_server(server_id_in, immediate_in);
- ELSE
- rhn_exception.raise_exception('channel_family_no_subscriptions');
- END IF;
-
- END subscribe_server;
-
-
-
- FUNCTION can_convert_to_fve(server_id_in IN NUMBER, channel_family_id_val IN NUMBER)
- RETURN NUMBER
- IS
- CURSOR fve_convertible_entries IS
- select 1 from
- rhnServerFveCapable cap
- where cap.server_id = server_id_in
- AND cap.channel_family_id = channel_family_id_val;
- BEGIN
- FOR entry IN fve_convertible_entries LOOP
- return 1;
- END LOOP;
- RETURN 0;
- END can_convert_to_fve;
-
-
-
- -- Converts server channel_family to use a flex entitlement
- PROCEDURE convert_to_fve(server_id_in IN NUMBER, channel_family_id_val IN NUMBER)
- IS
- available_fve_subs NUMBER;
- server_org_id_val NUMBER;
- BEGIN
-
- --
- -- Use the org_id of the server only if the org_id of the channel = NULL.
- -- This is required for subscribing to shared channels.
- --
- SELECT org_id
- INTO server_org_id_val
- FROM rhnServer
- WHERE id = server_id_in;
-
- begin
- obtain_read_lock(channel_family_id_val, server_org_id_val);
- exception
- when no_data_found then
- rhn_exception.raise_exception('channel_family_no_subscriptions');
- end;
- IF (can_convert_to_fve(server_id_in, channel_family_id_val ) = 0)
- THEN
- rhn_exception.raise_exception('server_cannot_convert_to_flex');
- END IF;
-
- available_fve_subs := rhn_channel.available_fve_family_subs(channel_family_id_val, server_org_id_val);
-
- IF (available_fve_subs > 0)
- THEN
-
- insert into rhnServerHistory (id,server_id,summary,details) (
- select rhn_event_id_seq.nextval,
- server_id_in,
- 'converted to flex entitlement' || SUBSTR(cf.label, 0, 99),
- cf.label
- from rhnChannelFamily cf
- where cf.id = channel_family_id_val
- );
-
- UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
- where sc.server_id = server_id_in and
- sc.channel_id in
- (select cfm.channel_id from rhnChannelFamilyMembers cfm
- where cfm.CHANNEL_FAMILY_ID = channel_family_id_val);
-
- rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
- ELSE
- rhn_exception.raise_exception('not_enough_flex_entitlements');
- END IF;
-
- END convert_to_fve;
-
- function can_server_consume_virt_channl(
- server_id_in in number,
- family_id_in in number )
- return number
- is
-
- cursor server_virt_families is
- select vi.virtual_system_id, cfvsl.channel_family_id
- from
- rhnChannelFamilyVirtSubLevel cfvsl,
- rhnSGTypeVirtSubLevel sgtvsl,
- rhnVirtualInstance vi
- where
- vi.virtual_system_id = server_id_in
- and sgtvsl.virt_sub_level_id = cfvsl.virt_sub_level_id
- and cfvsl.channel_family_id = family_id_in
- and exists (
- select 1
- from rhnServerEntitlementView sev
- where vi.host_system_id = sev.server_id
- and sev.server_group_type_id = sgtvsl.server_group_type_id );
- begin
-
- for server_virt_family in server_virt_families loop
- return 1;
- end loop;
-
- return 0;
-
- end;
-
- FUNCTION can_server_consume_fve(server_id_in IN NUMBER)
- RETURN NUMBER
- IS
- CURSOR vi_entries IS
- SELECT 1
- FROM rhnVirtualInstance vi
- WHERE vi.virtual_system_id = server_id_in;
- vi_count NUMBER;
-
- BEGIN
- FOR vi_entry IN VI_ENTRIES LOOP
- return 1;
- END LOOP;
- RETURN 0;
- END;
-
- function guess_server_base(
- server_id_in in number
- ) RETURN number is
- cursor server_cursor is
- select s.server_arch_id, s.release, s.org_id
- from rhnServer s
- where s.id = server_id_in;
- begin
- for s in server_cursor loop
- for channel in base_channel_cursor(s.release,
- s.server_arch_id, s.org_id)
- loop
- return channel.id;
- end loop base_channel_cursor;
- end loop server_cursor;
- -- Server not found, or no base channel applies to it
- return null;
- end;
-
- -- Private function
- function normalize_server_arch(server_arch_in in varchar2)
- return varchar2
- deterministic
- is
- suffix VARCHAR2(128) := '-redhat-linux';
- suffix_len NUMBER := length(suffix);
- begin
- if server_arch_in is NULL then
- return NULL;
- end if;
- if instr(server_arch_in, '-') > 0
- then
- -- Suffix already present
- return server_arch_in;
- end if;
- return server_arch_in || suffix;
- end normalize_server_arch;
-
- --
- --
- -- Raises:
- -- server_arch_not_found
- -- no_subscribe_permissions
- function base_channel_for_release_arch(
- release_in in varchar2,
- server_arch_in in varchar2,
- org_id_in in number := -1,
- user_id_in in number := null
- ) return number is
- server_arch varchar2(256) := normalize_server_arch(server_arch_in);
- server_arch_id number;
- begin
- -- Look up the server arch
- begin
- select id
- into server_arch_id
- from rhnServerArch
- where label = server_arch;
- exception
- when no_data_found then
- rhn_exception.raise_exception('server_arch_not_found');
- end;
- return base_channel_rel_archid(release_in, server_arch_id,
- org_id_in, user_id_in);
- end base_channel_for_release_arch;
-
- function base_channel_rel_archid(
- release_in in varchar2,
- server_arch_id_in in number,
- org_id_in in number := -1,
- user_id_in in number := null
- ) return number is
- denied_channel_id number := null;
- valid_org_id number := org_id_in;
- valid_user_id number := user_id_in;
- channel_subscribable number;
- begin
- if org_id_in = -1 and user_id_in is not null then
- -- Get the org id from the user id
- begin
- select org_id
- into valid_org_id
- from web_contact
- where id = user_id_in;
- exception
- when no_data_found then
- -- User doesn't exist
- -- XXX Only list public stuff for now
- valid_user_id := null;
- valid_org_id := -1;
- end;
- end if;
-
- for c in base_channel_cursor(release_in, server_arch_id_in, valid_org_id)
- loop
- -- This row is a possible match
- if valid_user_id is null then
- -- User ID not specified, so no user to channel permissions to
- -- check
- return c.id;
- end if;
-
- -- Check user to channel permissions
- select loose_user_role_check(c.id, user_id_in, 'subscribe')
- into channel_subscribable
- from dual;
-
- if channel_subscribable = 1 then
- return c.id;
- end if;
-
- -- Base channel exists, but is not subscribable; keep trying
- denied_channel_id := c.id;
- end loop base_channel_fetch;
-
- if denied_channel_id is not null then
- rhn_exception.raise_exception('no_subscribe_permissions');
- end if;
- -- No base channel applies
- return NULL;
- end base_channel_rel_archid;
-
- PROCEDURE clear_subscriptions(server_id_in IN NUMBER, deleting_server IN NUMBER := 0,
- update_family_countsYN IN NUMBER := 1)
- IS
- cursor server_channels(server_id_in in number) is
- select s.org_id, sc.channel_id, cfm.channel_family_id
- from rhnServer s,
- rhnServerChannel sc,
- rhnChannelFamilyMembers cfm
- where s.id = server_id_in
- and s.id = sc.server_id
- and sc.channel_id = cfm.channel_id
- order by cfm.channel_family_id;
- last_channel_family_id rhnChannelFamilyMembers.channel_family_id%type := -1;
- last_channel_org_id rhnServer.org_id%type := -1;
- BEGIN
- for channel in server_channels(server_id_in)
- loop
- unsubscribe_server(server_id_in, channel.channel_id, 1, 1, deleting_server, 0);
- if update_family_countsYN > 0
- and channel.channel_family_id != last_channel_family_id then
- -- update family counts only once
- -- after all channels with same family has been fetched
- if last_channel_family_id != -1 then
- update_family_counts(last_channel_family_id, last_channel_org_id);
- end if;
- last_channel_family_id := channel.channel_family_id;
- last_channel_org_id := channel.org_id;
- end if;
- end loop channel;
- if update_family_countsYN > 0 and last_channel_family_id != -1 then
- -- update the last family fetched
- update_family_counts(last_channel_family_id, last_channel_org_id);
- end if;
- END clear_subscriptions;
-
- PROCEDURE unsubscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, unsubscribe_children_in number := 0,
- deleting_server IN NUMBER := 0,
- update_family_countsYN IN NUMBER := 1)
- IS
- channel_family_id_val NUMBER;
- server_org_id_val NUMBER;
- available_subscriptions NUMBER;
- server_already_in_chan BOOLEAN;
- cursor channel_family_is_proxy(channel_family_id_in in number) is
- select 1
- from rhnChannelFamily
- where id = channel_family_id_in
- and label = 'rhn-proxy';
- cursor channel_family_is_satellite(channel_family_id_in in number) is
- select 1
- from rhnChannelFamily
- where id = channel_family_id_in
- and label = 'rhn-satellite';
- -- this is *EXACTLY* like check_server_parent_membership, but if we recurse
- -- with the package-level one, we get a "cursor already open", so we need a
- -- copy on our call stack instead. GROAN.
- cursor local_chk_server_parent_memb (
- server_id_in number,
- channel_id_in number ) is
- select c.id
- from rhnChannel c,
- rhnServerChannel sc
- where 1=1
- and c.parent_channel = channel_id_in
- and c.id = sc.channel_id
- and sc.server_id = server_id_in;
- BEGIN
- FOR child IN local_chk_server_parent_memb(server_id_in, channel_id_in)
- LOOP
- if unsubscribe_children_in = 1 then
- unsubscribe_server(server_id_in => server_id_in,
- channel_id_in => child.id,
- immediate_in => immediate_in,
- unsubscribe_children_in => unsubscribe_children_in,
- deleting_server => deleting_server,
- update_family_countsYN => update_family_countsYN);
- else
- rhn_exception.raise_exception('channel_unsubscribe_child_exists');
- end if;
- END LOOP child;
-
- server_already_in_chan := FALSE;
-
- FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
- LOOP
- server_already_in_chan := TRUE;
- END LOOP check_subscription;
-
- IF NOT server_already_in_chan
- THEN
- RETURN;
- END IF;
-
- if deleting_server = 0 then
-
- insert into rhnServerHistory (id,server_id,summary,details) (
- select rhn_event_id_seq.nextval,
- server_id_in,
- 'unsubscribed from channel ' || SUBSTR(c.label, 0, 106),
- c.label
- from rhnChannel c
- where c.id = channel_id_in
- );
-
- UPDATE rhnServer SET channels_changed = sysdate WHERE id = server_id_in;
- end if;
-
- DELETE FROM rhnServerChannel WHERE server_id = server_id_in AND channel_id = channel_id_in;
-
- if deleting_server = 0 then
- queue_server(server_id_in, immediate_in);
- end if;
-
- channel_family_id_val := rhn_channel.family_for_channel(channel_id_in);
- IF channel_family_id_val IS NULL
- THEN
- rhn_exception.raise_exception('channel_unsubscribe_no_family');
- END IF;
-
- for ignore in channel_family_is_satellite(channel_family_id_val) loop
- delete from rhnSatelliteInfo where server_id = server_id_in;
- end loop;
-
- for ignore in channel_family_is_proxy(channel_family_id_val) loop
- delete from rhnProxyInfo where server_id = server_id_in;
- end loop;
- SELECT org_id INTO server_org_id_val
- FROM rhnServer
- WHERE id = server_id_in;
-
- if update_family_countsYN = 1 then
- rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
- end if;
- END unsubscribe_server;
-
-
- FUNCTION family_for_channel(channel_id_in IN NUMBER)
- RETURN NUMBER
- IS
- channel_family_id_val NUMBER;
- BEGIN
- SELECT channel_family_id INTO channel_family_id_val
- FROM rhnChannelFamilyMembers
- WHERE channel_id = channel_id_in;
-
- RETURN channel_family_id_val;
- EXCEPTION
- WHEN NO_DATA_FOUND
- THEN
- RETURN NULL;
- END family_for_channel;
-
- FUNCTION available_family_subscriptions(channel_family_id_in IN NUMBER, org_id_in IN NUMBER)
- RETURN NUMBER
- IS
- cfp channel_family_perm_cursor%ROWTYPE;
- current_members_val NUMBER;
- max_members_val NUMBER;
- found NUMBER;
- BEGIN
- IF NOT channel_family_perm_cursor%ISOPEN
- THEN
- OPEN channel_family_perm_cursor(channel_family_id_in, org_id_in);
- END IF;
-
- FETCH channel_family_perm_cursor INTO cfp;
-
- WHILE channel_family_perm_cursor%FOUND
- LOOP
- found := 1;
-
- current_members_val := cfp.current_members;
- max_members_val := cfp.max_members;
-
- FETCH channel_family_perm_cursor INTO cfp;
- END LOOP;
-
- IF channel_family_perm_cursor%ISOPEN
- THEN
- CLOSE channel_family_perm_cursor;
- END IF;
-
- -- not found: either the channel fam doesn't have an entry in cfp, or the org doesn't have access to it.
- -- either way, there are no available subscriptions
-
- IF found IS NULL
- THEN
- RETURN 0;
- END IF;
-
- -- null max members? in that case, pass it on; NULL means infinite
- IF max_members_val IS NULL
- THEN
- RETURN NULL;
- END IF;
-
- -- otherwise, return the delta
- RETURN max_members_val - current_members_val;
- END available_family_subscriptions;
-
- FUNCTION available_fve_family_subs(channel_family_id_in IN NUMBER, org_id_in IN NUMBER)
- RETURN NUMBER
- IS
- cfp channel_family_perm_cursor%ROWTYPE;
- fve_current_members_val NUMBER;
- fve_max_members_val NUMBER;
- found NUMBER;
-
- BEGIN
- IF NOT channel_family_perm_cursor%ISOPEN THEN
- OPEN channel_family_perm_cursor(channel_family_id_in, org_id_in);
- END IF;
-
- FETCH channel_family_perm_cursor INTO cfp;
-
- WHILE channel_family_perm_cursor%FOUND LOOP
- found := 1;
- fve_current_members_val := cfp.fve_current_members;
- fve_max_members_val := cfp.fve_max_members;
- FETCH channel_family_perm_cursor INTO cfp;
- END LOOP;
-
- IF channel_family_perm_cursor%ISOPEN THEN
- CLOSE channel_family_perm_cursor;
- END IF;
-
- IF found IS NULL THEN
- RETURN 0;
- END IF;
-
- IF fve_max_members_val IS NULL THEN
- RETURN NULL;
- END IF;
-
- RETURN fve_max_members_val - fve_current_members_val;
-
- END available_fve_family_subs;
-
-
- -- *******************************************************************
- -- FUNCTION: channel_family_current_members
- -- Calculates and returns the actual count of systems consuming
- -- physical channel subscriptions.
- -- Called by: update_family_counts
- -- rhn_entitlements.repoll_virt_guest_entitlements
- -- *******************************************************************
- function channel_family_current_members(channel_family_id_in IN NUMBER,
- org_id_in IN NUMBER)
- return number
- is
- current_members_count number := 0;
- begin
- select count(distinct server_id)
- into current_members_count
- from rhnChannelFamilyServerPhysical cfsp
- where cfsp.channel_family_id = channel_family_id_in
- and cfsp.customer_id = org_id_in;
- return current_members_count;
- end;
-
-
- function cfam_curr_fve_members(
- channel_family_id_in IN NUMBER,
- org_id_in IN NUMBER)
- return number
- is
- current_members_count number := 0;
-
- begin
- select count(sc.server_id)
- into current_members_count
- from rhnServerChannel sc,
- rhnChannelFamilyMembers cfm,
- rhnServer s
- where s.org_id = org_id_in
- and s.id = sc.server_id
- and cfm.channel_family_id = channel_family_id_in
- and cfm.channel_id = sc.channel_id
- and exists (
- select 1
- from rhnChannelFamilyServerFve cfsp
- where cfsp.CHANNEL_FAMILY_ID = channel_family_id_in
- and cfsp.server_id = s.id
- );
-
- return current_members_count;
- end;
- PROCEDURE update_family_counts(channel_family_id_in IN NUMBER,
- org_id_in IN NUMBER)
- IS
- BEGIN
- update rhnPrivateChannelFamily
- set current_members = ( channel_family_current_members(channel_family_id_in, org_id_in)),
- fve_current_members = ( cfam_curr_fve_members(channel_family_id_in, org_id_in))
- where org_id = org_id_in
- and channel_family_id = channel_family_id_in;
- END update_family_counts;
-
- PROCEDURE update_group_family_counts(group_label_in IN VARCHAR2,
- org_id_in IN NUMBER)
- IS
- BEGIN
- FOR i IN (
- SELECT DISTINCT CFM.channel_family_id, SG.org_id
- FROM rhnChannelFamilyMembers CFM
- JOIN rhnServerChannel SC
- ON SC.channel_id = CFM.channel_id
- JOIN rhnServerGroupMembers SGM
- ON SC.server_id = SGM.server_id
- JOIN rhnServerGroup SG
- ON SGM.server_group_id = SG.id
- JOIN rhnServerGroupType SGT
- ON SG.group_type = SGT.id
- WHERE SGT.label = group_label_in
- AND SG.org_id = org_id_in
- AND SGT.is_base = 'Y'
- ) LOOP
- rhn_channel.update_family_counts(i.channel_family_id, i.org_id);
- END LOOP;
- END update_group_family_counts;
-
- FUNCTION available_chan_subscriptions(channel_id_in IN NUMBER,
- org_id_in IN NUMBER)
- RETURN NUMBER
- IS
- channel_family_id_val NUMBER;
- BEGIN
- SELECT channel_family_id INTO channel_family_id_val
- FROM rhnChannelFamilyMembers
- WHERE channel_id = channel_id_in;
-
- RETURN rhn_channel.available_family_subscriptions(
- channel_family_id_val, org_id_in);
- END available_chan_subscriptions;
-
- FUNCTION available_fve_chan_subs(channel_id_in IN NUMBER,
- org_id_in IN NUMBER)
- RETURN NUMBER
- IS
- channel_family_id_val NUMBER;
-
- BEGIN
- SELECT channel_family_id INTO channel_family_id_val
- FROM rhnChannelFamilyMembers
- WHERE channel_id = channel_id_in;
-
- RETURN rhn_channel.available_fve_family_subs( channel_family_id_val, org_id_in);
- END available_fve_chan_subs;
-
- procedure unsubscribe_server_from_family(server_id_in in number,
- channel_family_id_in in number)
- is
- begin
- delete
- from rhnServerChannel rsc
- where rsc.server_id = server_id_in
- and channel_id in (
- select rcfm.channel_id
- from rhnChannelFamilyMembers rcfm
- where rcfm.channel_family_id = channel_family_id_in);
- end;
-
- function get_org_id(channel_id_in in number)
- return number
- is
- org_id_out number;
- begin
- select org_id into org_id_out
- from rhnChannel
- where id = channel_id_in;
-
- return org_id_out;
- end get_org_id;
-
- function get_cfam_org_access(cfam_id_in in number, org_id_in in number)
- return number
- is
- cursor families is
- select 1
- from rhnOrgChannelFamilyPermissions cfp
- where cfp.org_id = org_id_in;
- begin
- -- the idea: if we get past this query,
- -- the user has the role, else catch the exception and return 0
- for family in families loop
- return 1;
- end loop;
- return 0;
- end;
-
- function get_org_access(channel_id_in in number, org_id_in in number)
- return number
- is
- throwaway number;
- begin
- -- the idea: if we get past this query,
- -- the org has access to the channel, else catch the exception and return 0
- select distinct 1 into throwaway
- from rhnChannelFamilyMembers CFM,
- rhnOrgChannelFamilyPermissions CFP
- where cfp.org_id = org_id_in
- and CFM.channel_family_id = CFP.channel_family_id
- and CFM.channel_id = channel_id_in
- and (CFP.max_members > 0 or CFP.max_members is null or CFP.fve_max_members > 0 or CFP.fve_max_members is null or CFP.org_id = 1);
-
- return 1;
- exception
- when no_data_found
- then
- return 0;
- end;
-
- -- check if a user has a given role, or if such a role is inferrable
- function user_role_check_debug(channel_id_in in number,
- user_id_in in number,
- role_in in varchar2,
- reason_out out varchar2)
- return number
- is
- org_id number;
- begin
- org_id := rhn_user.get_org_id(user_id_in);
-
- -- channel might be shared
- if role_in = 'subscribe' and
- rhn_channel.shared_user_role_check(channel_id_in, user_id_in, role_in) = 1 then
- return 1;
- end if;
-
- if role_in = 'manage' and
- NVL(rhn_channel.get_org_id(channel_id_in), -1) <> org_id then
- reason_out := 'channel_not_owned';
- return 0;
- end if;
-
- if role_in = 'subscribe' and
- rhn_channel.get_org_access(channel_id_in, org_id) = 0 then
- reason_out := 'channel_not_available';
- return 0;
- end if;
-
- -- channel admins have all roles
- if rhn_user.check_role_implied(user_id_in, 'channel_admin') = 1 then
- reason_out := 'channel_admin';
- return 1;
- end if;
-
- -- the subscribe permission is inferred
- -- UNLESS the not_globally_subscribable flag is set
- if role_in = 'subscribe'
- then
- if rhn_channel.org_channel_setting(channel_id_in,
- org_id,
- 'not_globally_subscribable') = 0 then
- reason_out := 'globally_subscribable';
- return 1;
- end if;
- end if;
-
- -- all other roles (manage right now) are explicitly granted
- reason_out := 'direct_permission';
- return rhn_channel.direct_user_role_check(channel_id_in,
- user_id_in, role_in);
- end;
-
- -- same as above, but with no OUT param; useful in views, etc
- function user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- return number
- is
- throwaway varchar2(256);
- begin
- return rhn_channel.user_role_check_debug(channel_id_in, user_id_in, role_in, throwaway);
- end;
-
- --
- -- For multiorg phase II, this function simply checks to see if the user's
- -- has a trust relationship that includes this channel by id.
- --
- function shared_user_role_check(channel_id in number, user_id in number, role in varchar2)
- return number
- is
- n number;
- oid number;
- begin
- oid := rhn_user.get_org_id(user_id);
- select 1 into n
- from rhnSharedChannelView s
- where s.id = channel_id and s.org_trust_id = oid;
- return 1;
- exception
- when no_data_found then
- return 0;
- end;
-
- -- same as above, but returns 1 if user_id_in is null
- -- This is useful in queries where user_id is not specified
- function loose_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- return number
- is
- begin
- if user_id_in is null then
- return 1;
- end if;
- return user_role_check(channel_id_in, user_id_in, role_in);
- end loose_user_role_check;
-
- -- directly checks the table, no inferred permissions
- function direct_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
- return number
- is
- throwaway number;
- begin
- -- the idea: if we get past this query, the user has the role, else catch the exception and return 0
- select 1 into throwaway
- from rhnChannelPermissionRole CPR,
- rhnChannelPermission CP
- where CP.user_id = user_id_in
- and CP.channel_id = channel_id_in
- and CPR.label = role_in
- and CP.role_id = CPR.id;
-
- return 1;
- exception
- when no_data_found
- then
- return 0;
- end;
-
- -- check if an org has a certain setting
- function org_channel_setting(channel_id_in in number, org_id_in in number, setting_in in varchar2)
- return number
- is
- throwaway number;
- begin
- -- the idea: if we get past this query, the org has the setting, else catch the exception and return 0
- select 1 into throwaway
- from rhnOrgChannelSettingsType OCST,
- rhnOrgChannelSettings OCS
- where OCS.org_id = org_id_in
- and OCS.channel_id = channel_id_in
- and OCST.label = setting_in
- and OCS.setting_id = OCST.id;
-
- return 1;
- exception
- when no_data_found
- then
- return 0;
- end;
-
- FUNCTION channel_priority(channel_id_in IN number)
- RETURN number
- IS
- channel_name varchar2(256);
- priority number;
- end_of_life_val date;
- org_id_val number;
- BEGIN
-
- select name, end_of_life, org_id
- into channel_name, end_of_life_val, org_id_val
- from rhnChannel
- where id = channel_id_in;
-
- if end_of_life_val is not null then
- return -400;
- end if;
-
- if channel_name like 'Red Hat Enterprise Linux%' or channel_name like 'RHEL%' then
- priority := 1000;
- if channel_name not like '%Beta%' then
- priority := priority + 1000;
- end if;
-
- priority := priority +
- case
- when channel_name like '%v. 5%' then 600
- when channel_name like '%v. 4%' then 500
- when channel_name like '%v. 3%' then 400
- when channel_name like '%v. 2%' then 300
- when channel_name like '%v. 1%' then 200
- else 0
- end;
-
- priority := priority +
- case
- when channel_name like 'Red Hat Enterprise Linux (v. 5%' then 60
- when (channel_name like '%AS%' and channel_name not like '%Extras%') then 50
- when (channel_name like '%ES%' and channel_name not like '%Extras%') then 40
- when (channel_name like '%WS%' and channel_name not like '%Extras%') then 30
- when (channel_name like '%Desktop%' and channel_name not like '%Extras%') then 20
- when channel_name like '%Extras%' then 10
- else 0
- end;
-
- priority := priority +
- case
- when channel_name like '%)' then 5
- else 0
- end;
-
- priority := priority +
- case
- when channel_name like '%32-bit x86%' then 4
- when channel_name like '%64-bit Intel Itanium%' then 3
- when channel_name like '%64-bit AMD64/Intel EM64T%' then 2
- else 0
- end;
- elsif channel_name like 'Red Hat Desktop%' then
- priority := 900;
-
- if channel_name not like '%Beta%' then
- priority := priority + 50;
- end if;
-
- priority := priority +
- case
- when channel_name like '%v. 4%' then 40
- when channel_name like '%v. 3%' then 30
- when channel_name like '%v. 2%' then 20
- when channel_name like '%v. 1%' then 10
- else 0
- end;
-
- priority := priority +
- case
- when channel_name like '%32-bit x86%' then 4
- when channel_name like '%64-bit Intel Itanium%' then 3
- when channel_name like '%64-bit AMD64/Intel EM64T%' then 2
- else 0
- end;
-
- elsif org_id_val is not null then
- priority := 600;
- else
- priority := 500;
- end if;
-
- return -priority;
-
- end channel_priority;
-
- -- right now this only does the accounting changes; the cascade
- -- actually does the rhnServerChannel delete.
- procedure delete_server_channels(server_id_in in number)
- is
- begin
- update rhnPrivateChannelFamily
- set current_members = current_members -1
- where org_id in (
- select org_id
- from rhnServer
- where id = server_id_in
- )
- and channel_family_id in (
- select rcfm.channel_family_id
- from rhnChannelFamilyMembers rcfm,
- rhnServerChannel rsc
- where rsc.server_id = server_id_in
- and rsc.channel_id = rcfm.channel_id
- and not exists (
- select 1
- from
- rhnChannelFamilyVirtSubLevel cfvsl,
- rhnSGTypeVirtSubLevel sgtvsl,
- rhnServerEntitlementView sev,
- rhnVirtualInstance vi
- where
- -- system is a virtual instance
- vi.virtual_system_id = server_id_in
- and vi.host_system_id = sev.server_id
- -- system's host has a virt ent
- and sev.label in ('virtualization_host',
- 'virtualization_host_platform')
- and sev.server_group_type_id =
- sgtvsl.server_group_type_id
- -- the host's virt ent grants a cf virt sub level
- and sgtvsl.virt_sub_level_id = cfvsl.virt_sub_level_id
- -- the cf is in that virt sub level
- and cfvsl.channel_family_id = rcfm.channel_family_id
- )
- );
- end;
-
- -- this could certainly be optimized to do updates if needs be
- procedure refresh_newest_package(channel_id_in in number,
- caller_in in varchar2 := '(unknown)',
- package_name_id_in in number := null)
- is
- -- procedure refreshes rows for name_id = package_name_id_in or
- -- all rows if package_name_id_in is null
- begin
- delete from rhnChannelNewestPackage
- where channel_id = channel_id_in
- and (package_name_id_in is null
- or name_id = package_name_id_in);
- insert into rhnChannelNewestPackage
- (channel_id, name_id, evr_id, package_id, package_arch_id)
- (select channel_id,
- name_id, evr_id,
- package_id, package_arch_id
- from rhnChannelNewestPackageView
- where channel_id = channel_id_in
- and (package_name_id_in is null
- or name_id = package_name_id_in)
- );
- insert into rhnChannelNewestPackageAudit (channel_id, caller)
- values (channel_id_in, caller_in);
- update rhnChannel
- set last_modified = greatest(sysdate, last_modified + 1/86400)
- where id = channel_id_in;
- end;
-
- procedure update_channel ( channel_id_in in number, invalidate_ss in number := 0,
- date_to_use in date := sysdate )
- is
-
- channel_last_modified date;
- last_modified_value date;
-
- cursor snapshots is
- select snapshot_id id
- from rhnSnapshotChannel
- where channel_id = channel_id_in;
-
- begin
-
- select last_modified
- into channel_last_modified
- from rhnChannel
- where id = channel_id_in;
-
- last_modified_value := date_to_use;
-
- if last_modified_value <= channel_last_modified then
- last_modified_value := last_modified_value + 1/86400;
- end if;
-
- update rhnChannel set last_modified = last_modified_value
- where id = channel_id_in;
-
- if invalidate_ss = 1 then
- for snapshot in snapshots loop
- update rhnSnapshot
- set invalid = lookup_snapshot_invalid_reason('channel_modified')
- where id = snapshot.id;
- end loop;
- end if;
-
- end update_channel;
-
- procedure update_channels_by_package ( package_id_in in number, date_to_use in date := sysdate )
- is
-
- cursor channels is
- select channel_id
- from rhnChannelPackage
- where package_id = package_id_in
- order by channel_id;
-
- begin
- for channel in channels loop
- -- we want to invalidate the snapshot assocated with the channel when we
- -- do this b/c we know we've added or removed or packages
- rhn_channel.update_channel ( channel.channel_id, 1, date_to_use );
- end loop;
- end update_channels_by_package;
-
-
- procedure update_channels_by_errata ( errata_id_in number, date_to_use in date := sysdate )
- is
-
- cursor channels is
- select channel_id
- from rhnChannelErrata
- where errata_id = errata_id_in
- order by channel_id;
-
- begin
- for channel in channels loop
- -- we won't invalidate snapshots, b/c just changing the errata associated with
- -- a channel shouldn't invalidate snapshots
- rhn_channel.update_channel ( channel.channel_id, 0, date_to_use );
- end loop;
- end update_channels_by_errata;
-
- procedure update_needed_cache(channel_id_in in number)
- is
- -- update of needed cache ican be commited on a per server basis
- -- b/c failure of update for a server means nothing for the other servers
- begin
- -- we intentionaly do a loop here instead of one huge select
- -- b/c we want to break update into smaller transaction to unblock other sessions
- -- querying rhnServerNeededCache
- for server in (
- select sc.server_id as id
- from rhnServerChannel sc
- where sc.channel_id = channel_id_in
- ) loop
- rhn_server.update_needed_cache(server.id);
- commit;
- end loop;
- end update_needed_cache;
-
-END rhn_channel;
-/
-SHOW ERRORS
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/001-rhn_channel.pkb.sql.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/001-rhn_channel.pkb.sql.postgresql
deleted file mode 100644
index 0a2df63..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/001-rhn_channel.pkb.sql.postgresql
+++ /dev/null
@@ -1 +0,0 @@
--- oracle equivalent source sha1 6e73be65e01c5fe26f2630cc52f2fa5f16747d22
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/048-rhn_channel.pkb.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/048-rhn_channel.pkb.sql.oracle
deleted file mode 100644
index cf2393b..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/048-rhn_channel.pkb.sql.oracle
+++ /dev/null
@@ -1 +0,0 @@
--- This file has intentionally been left empty.
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/048-rhn_channel.pkb.sql.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/048-rhn_channel.pkb.sql.postgresql
deleted file mode 100644
index 80c854f..0000000
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/048-rhn_channel.pkb.sql.postgresql
+++ /dev/null
@@ -1,62 +0,0 @@
--- oracle equivalent source sha1 b04dab2ff31049a8744e5ce1531ccd8b00152bbc
---
---update pg_setting
-update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_path';
-
- -- Converts server channel_family to use a flex entitlement
- create or replace function convert_to_fve(server_id_in IN NUMERIC, channel_family_id_val IN NUMERIC)
- returns void
- as $$
- declare
- available_fve_subs NUMERIC;
- server_org_id_val NUMERIC;
- BEGIN
-
- --
- -- Use the org_id of the server only if the org_id of the channel = NULL.
- -- This is required for subscribing to shared channels.
- --
- SELECT org_id
- INTO server_org_id_val
- FROM rhnServer
- WHERE id = server_id_in;
-
-
- perform rhn_channel.obtain_read_lock(channel_family_id_val, server_org_id_val);
- if not found then
- perform rhn_exception.raise_exception('channel_family_no_subscriptions');
- end if;
- IF (rhn_channel.can_convert_to_fve(server_id_in, channel_family_id_val ) = 0)
- THEN
- perform rhn_exception.raise_exception('server_cannot_convert_to_flex');
- END IF;
-
- available_fve_subs := rhn_channel.available_fve_family_subs(channel_family_id_val, server_org_id_val);
-
- IF (available_fve_subs > 0)
- THEN
-
- insert into rhnServerHistory (id,server_id,summary,details) (
- select nextval('rhn_event_id_seq'),
- server_id_in,
- 'converted to flex entitlement' || SUBSTR(cf.label, 0, 99),
- cf.label
- from rhnChannelFamily cf
- where cf.id = channel_family_id_val
- );
-
- UPDATE rhnServerChannel sc set is_fve = 'Y'
- where sc.server_id = server_id_in and
- sc.channel_id in
- (select cfm.channel_id from rhnChannelFamilyMembers cfm
- where cfm.CHANNEL_FAMILY_ID = channel_family_id_val);
-
- perform rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
- ELSE
- perform rhn_exception.raise_exception('not_enough_flex_entitlements');
- END IF;
-
- END$$ language plpgsql;
-
--- restore the original setting
-update pg_settings set setting = overlay( setting placing '' from 1 for (length('rhn_channel')+1) ) where name = 'search_path';
commit 901adda878334720bf1263b87c982653fc464887
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Tue May 29 11:26:39 2012 +0200
upgrade scripts for user_role_check_debug() changes
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/051-rhn_channel.pkb.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/051-rhn_channel.pkb.sql.oracle
new file mode 100644
index 0000000..fc2c60a
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/051-rhn_channel.pkb.sql.oracle
@@ -0,0 +1,1222 @@
+--
+-- Copyright (c) 2008--2012 Red Hat, Inc.
+--
+-- This software is licensed to you under the GNU General Public License,
+-- version 2 (GPLv2). There is NO WARRANTY for this software, express or
+-- implied, including the implied warranties of MERCHANTABILITY or FITNESS
+-- FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+-- along with this software; if not, see
+-- http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+--
+-- Red Hat trademarks are not licensed under GPLv2. No permission is
+-- granted to use or replicate Red Hat trademarks that are incorporated
+-- in this software or its documentation.
+--
+
+CREATE OR REPLACE
+PACKAGE BODY rhn_channel
+IS
+ body_version varchar2(100) := '';
+
+ -- Cursor that fetches all the possible base channels for a
+ -- (server_arch_id, release, org_id) combination
+ cursor base_channel_cursor(
+ release_in in varchar2,
+ server_arch_id_in in number,
+ org_id_in in number
+ ) return rhnChannel%ROWTYPE is
+ select distinct c.*
+ from rhnDistChannelMap dcm,
+ rhnServerChannelArchCompat scac,
+ rhnChannel c,
+ rhnChannelPermissions cp
+ where cp.org_id = org_id_in
+ and cp.channel_id = c.id
+ and c.parent_channel is null
+ and c.id = dcm.channel_id
+ and c.channel_arch_id = dcm.channel_arch_id
+ and dcm.release = release_in
+ and scac.server_arch_id = server_arch_id_in
+ and scac.channel_arch_id = c.channel_arch_id;
+
+ procedure obtain_read_lock(channel_family_id_in in number, org_id_in in number)
+ is
+ read_lock date;
+
+ begin
+ select created into read_lock
+ from rhnPrivateChannelFamily
+ where channel_family_id = channel_family_id_in and org_id = org_id_in
+ for update;
+ end obtain_read_lock;
+
+ PROCEDURE subscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, user_id_in in number := null, recalcfamily_in number := 1)
+ IS
+ channel_parent_val rhnChannel.parent_channel%TYPE;
+ parent_subscribed BOOLEAN;
+ server_has_base_chan BOOLEAN;
+ server_already_in_chan BOOLEAN;
+ channel_family_id_val NUMBER;
+ server_org_id_val NUMBER;
+ available_subscriptions NUMBER;
+ available_fve_subs NUMBER;
+ consenting_user NUMBER;
+ allowed number := 0;
+ is_fve CHAR(1) := 'N';
+ BEGIN
+ if user_id_in is not null then
+ allowed := rhn_channel.user_role_check(channel_id_in, user_id_in, 'subscribe');
+ else
+ allowed := 1;
+ end if;
+
+ if allowed = 0 then
+ rhn_exception.raise_exception('no_subscribe_permissions');
+ end if;
+
+
+ SELECT parent_channel INTO channel_parent_val FROM rhnChannel WHERE id = channel_id_in;
+
+ IF channel_parent_val IS NOT NULL
+ THEN
+ -- child channel; if attempting to cross-subscribe a child to the wrong base, silently ignore
+ parent_subscribed := FALSE;
+
+ FOR check_subscription IN check_server_subscription(server_id_in, channel_parent_val)
+ LOOP
+ parent_subscribed := TRUE;
+ END LOOP check_subscription;
+
+ IF NOT parent_subscribed
+ THEN
+ RETURN;
+ END IF;
+ ELSE
+ -- base channel
+ server_has_base_chan := FALSE;
+ FOR base IN server_base_subscriptions(server_id_in)
+ LOOP
+ server_has_base_chan := TRUE;
+ END LOOP base;
+
+ IF server_has_base_chan
+ THEN
+ rhn_exception.raise_exception('channel_server_one_base');
+ END IF;
+ END IF;
+
+ FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
+ LOOP
+ server_already_in_chan := TRUE;
+ END LOOP check_subscription;
+
+ IF server_already_in_chan
+ THEN
+ RETURN;
+ END IF;
+
+ channel_family_id_val := rhn_channel.family_for_channel(channel_id_in);
+ IF channel_family_id_val IS NULL
+ THEN
+ rhn_exception.raise_exception('channel_subscribe_no_family');
+ END IF;
+
+ --
+ -- Use the org_id of the server only if the org_id of the channel = NULL.
+ -- This is required for subscribing to shared channels.
+ --
+ SELECT NVL(org_id, (SELECT org_id FROM rhnServer WHERE id = server_id_in))
+ INTO server_org_id_val
+ FROM rhnChannel
+ WHERE id = channel_id_in;
+
+ begin
+ obtain_read_lock(channel_family_id_val, server_org_id_val);
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception('channel_family_no_subscriptions');
+ end;
+
+ available_subscriptions := rhn_channel.available_family_subscriptions(channel_family_id_val, server_org_id_val);
+ available_fve_subs := rhn_channel.available_fve_family_subs(channel_family_id_val, server_org_id_val);
+
+ IF available_subscriptions IS NULL OR
+ available_subscriptions > 0 or
+ can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 1 OR
+ (available_fve_subs > 0 AND can_server_consume_fve(server_id_in) = 1)
+ THEN
+ if can_server_consume_virt_channl(server_id_in, channel_family_id_val) = 0 AND available_fve_subs > 0 AND can_server_consume_fve(server_id_in) = 1 THEN
+ is_fve := 'Y';
+ END IF;
+ insert into rhnServerHistory (id,server_id,summary,details) (
+ select rhn_event_id_seq.nextval,
+ server_id_in,
+ 'subscribed to channel ' || SUBSTR(c.label, 0, 106),
+ c.label
+ from rhnChannel c
+ where c.id = channel_id_in
+ );
+ UPDATE rhnServer SET channels_changed = sysdate WHERE id = server_id_in;
+ INSERT INTO rhnServerChannel (server_id, channel_id, is_fve) VALUES (server_id_in, channel_id_in, is_fve);
+ IF recalcfamily_in > 0
+ THEN
+ rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
+ END IF;
+ queue_server(server_id_in, immediate_in);
+ ELSE
+ rhn_exception.raise_exception('channel_family_no_subscriptions');
+ END IF;
+
+ END subscribe_server;
+
+
+
+ FUNCTION can_convert_to_fve(server_id_in IN NUMBER, channel_family_id_val IN NUMBER)
+ RETURN NUMBER
+ IS
+ CURSOR fve_convertible_entries IS
+ select 1 from
+ rhnServerFveCapable cap
+ where cap.server_id = server_id_in
+ AND cap.channel_family_id = channel_family_id_val;
+ BEGIN
+ FOR entry IN fve_convertible_entries LOOP
+ return 1;
+ END LOOP;
+ RETURN 0;
+ END can_convert_to_fve;
+
+
+
+ -- Converts server channel_family to use a flex entitlement
+ PROCEDURE convert_to_fve(server_id_in IN NUMBER, channel_family_id_val IN NUMBER)
+ IS
+ available_fve_subs NUMBER;
+ server_org_id_val NUMBER;
+ BEGIN
+
+ --
+ -- Use the org_id of the server only if the org_id of the channel = NULL.
+ -- This is required for subscribing to shared channels.
+ --
+ SELECT org_id
+ INTO server_org_id_val
+ FROM rhnServer
+ WHERE id = server_id_in;
+
+ begin
+ obtain_read_lock(channel_family_id_val, server_org_id_val);
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception('channel_family_no_subscriptions');
+ end;
+ IF (can_convert_to_fve(server_id_in, channel_family_id_val ) = 0)
+ THEN
+ rhn_exception.raise_exception('server_cannot_convert_to_flex');
+ END IF;
+
+ available_fve_subs := rhn_channel.available_fve_family_subs(channel_family_id_val, server_org_id_val);
+
+ IF (available_fve_subs > 0)
+ THEN
+
+ insert into rhnServerHistory (id,server_id,summary,details) (
+ select rhn_event_id_seq.nextval,
+ server_id_in,
+ 'converted to flex entitlement' || SUBSTR(cf.label, 0, 99),
+ cf.label
+ from rhnChannelFamily cf
+ where cf.id = channel_family_id_val
+ );
+
+ UPDATE rhnServerChannel sc set sc.is_fve = 'Y'
+ where sc.server_id = server_id_in and
+ sc.channel_id in
+ (select cfm.channel_id from rhnChannelFamilyMembers cfm
+ where cfm.CHANNEL_FAMILY_ID = channel_family_id_val);
+
+ rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
+ ELSE
+ rhn_exception.raise_exception('not_enough_flex_entitlements');
+ END IF;
+
+ END convert_to_fve;
+
+ function can_server_consume_virt_channl(
+ server_id_in in number,
+ family_id_in in number )
+ return number
+ is
+
+ cursor server_virt_families is
+ select vi.virtual_system_id, cfvsl.channel_family_id
+ from
+ rhnChannelFamilyVirtSubLevel cfvsl,
+ rhnSGTypeVirtSubLevel sgtvsl,
+ rhnVirtualInstance vi
+ where
+ vi.virtual_system_id = server_id_in
+ and sgtvsl.virt_sub_level_id = cfvsl.virt_sub_level_id
+ and cfvsl.channel_family_id = family_id_in
+ and exists (
+ select 1
+ from rhnServerEntitlementView sev
+ where vi.host_system_id = sev.server_id
+ and sev.server_group_type_id = sgtvsl.server_group_type_id );
+ begin
+
+ for server_virt_family in server_virt_families loop
+ return 1;
+ end loop;
+
+ return 0;
+
+ end;
+
+ FUNCTION can_server_consume_fve(server_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ CURSOR vi_entries IS
+ SELECT 1
+ FROM rhnVirtualInstance vi
+ WHERE vi.virtual_system_id = server_id_in;
+ vi_count NUMBER;
+
+ BEGIN
+ FOR vi_entry IN VI_ENTRIES LOOP
+ return 1;
+ END LOOP;
+ RETURN 0;
+ END;
+
+ function guess_server_base(
+ server_id_in in number
+ ) RETURN number is
+ cursor server_cursor is
+ select s.server_arch_id, s.release, s.org_id
+ from rhnServer s
+ where s.id = server_id_in;
+ begin
+ for s in server_cursor loop
+ for channel in base_channel_cursor(s.release,
+ s.server_arch_id, s.org_id)
+ loop
+ return channel.id;
+ end loop base_channel_cursor;
+ end loop server_cursor;
+ -- Server not found, or no base channel applies to it
+ return null;
+ end;
+
+ -- Private function
+ function normalize_server_arch(server_arch_in in varchar2)
+ return varchar2
+ deterministic
+ is
+ suffix VARCHAR2(128) := '-redhat-linux';
+ suffix_len NUMBER := length(suffix);
+ begin
+ if server_arch_in is NULL then
+ return NULL;
+ end if;
+ if instr(server_arch_in, '-') > 0
+ then
+ -- Suffix already present
+ return server_arch_in;
+ end if;
+ return server_arch_in || suffix;
+ end normalize_server_arch;
+
+ --
+ --
+ -- Raises:
+ -- server_arch_not_found
+ -- no_subscribe_permissions
+ function base_channel_for_release_arch(
+ release_in in varchar2,
+ server_arch_in in varchar2,
+ org_id_in in number := -1,
+ user_id_in in number := null
+ ) return number is
+ server_arch varchar2(256) := normalize_server_arch(server_arch_in);
+ server_arch_id number;
+ begin
+ -- Look up the server arch
+ begin
+ select id
+ into server_arch_id
+ from rhnServerArch
+ where label = server_arch;
+ exception
+ when no_data_found then
+ rhn_exception.raise_exception('server_arch_not_found');
+ end;
+ return base_channel_rel_archid(release_in, server_arch_id,
+ org_id_in, user_id_in);
+ end base_channel_for_release_arch;
+
+ function base_channel_rel_archid(
+ release_in in varchar2,
+ server_arch_id_in in number,
+ org_id_in in number := -1,
+ user_id_in in number := null
+ ) return number is
+ denied_channel_id number := null;
+ valid_org_id number := org_id_in;
+ valid_user_id number := user_id_in;
+ channel_subscribable number;
+ begin
+ if org_id_in = -1 and user_id_in is not null then
+ -- Get the org id from the user id
+ begin
+ select org_id
+ into valid_org_id
+ from web_contact
+ where id = user_id_in;
+ exception
+ when no_data_found then
+ -- User doesn't exist
+ -- XXX Only list public stuff for now
+ valid_user_id := null;
+ valid_org_id := -1;
+ end;
+ end if;
+
+ for c in base_channel_cursor(release_in, server_arch_id_in, valid_org_id)
+ loop
+ -- This row is a possible match
+ if valid_user_id is null then
+ -- User ID not specified, so no user to channel permissions to
+ -- check
+ return c.id;
+ end if;
+
+ -- Check user to channel permissions
+ select loose_user_role_check(c.id, user_id_in, 'subscribe')
+ into channel_subscribable
+ from dual;
+
+ if channel_subscribable = 1 then
+ return c.id;
+ end if;
+
+ -- Base channel exists, but is not subscribable; keep trying
+ denied_channel_id := c.id;
+ end loop base_channel_fetch;
+
+ if denied_channel_id is not null then
+ rhn_exception.raise_exception('no_subscribe_permissions');
+ end if;
+ -- No base channel applies
+ return NULL;
+ end base_channel_rel_archid;
+
+ PROCEDURE clear_subscriptions(server_id_in IN NUMBER, deleting_server IN NUMBER := 0,
+ update_family_countsYN IN NUMBER := 1)
+ IS
+ cursor server_channels(server_id_in in number) is
+ select s.org_id, sc.channel_id, cfm.channel_family_id
+ from rhnServer s,
+ rhnServerChannel sc,
+ rhnChannelFamilyMembers cfm
+ where s.id = server_id_in
+ and s.id = sc.server_id
+ and sc.channel_id = cfm.channel_id
+ order by cfm.channel_family_id;
+ last_channel_family_id rhnChannelFamilyMembers.channel_family_id%type := -1;
+ last_channel_org_id rhnServer.org_id%type := -1;
+ BEGIN
+ for channel in server_channels(server_id_in)
+ loop
+ unsubscribe_server(server_id_in, channel.channel_id, 1, 1, deleting_server, 0);
+ if update_family_countsYN > 0
+ and channel.channel_family_id != last_channel_family_id then
+ -- update family counts only once
+ -- after all channels with same family has been fetched
+ if last_channel_family_id != -1 then
+ update_family_counts(last_channel_family_id, last_channel_org_id);
+ end if;
+ last_channel_family_id := channel.channel_family_id;
+ last_channel_org_id := channel.org_id;
+ end if;
+ end loop channel;
+ if update_family_countsYN > 0 and last_channel_family_id != -1 then
+ -- update the last family fetched
+ update_family_counts(last_channel_family_id, last_channel_org_id);
+ end if;
+ END clear_subscriptions;
+
+ PROCEDURE unsubscribe_server(server_id_in IN NUMBER, channel_id_in NUMBER, immediate_in NUMBER := 1, unsubscribe_children_in number := 0,
+ deleting_server IN NUMBER := 0,
+ update_family_countsYN IN NUMBER := 1)
+ IS
+ channel_family_id_val NUMBER;
+ server_org_id_val NUMBER;
+ available_subscriptions NUMBER;
+ server_already_in_chan BOOLEAN;
+ cursor channel_family_is_proxy(channel_family_id_in in number) is
+ select 1
+ from rhnChannelFamily
+ where id = channel_family_id_in
+ and label = 'rhn-proxy';
+ cursor channel_family_is_satellite(channel_family_id_in in number) is
+ select 1
+ from rhnChannelFamily
+ where id = channel_family_id_in
+ and label = 'rhn-satellite';
+ -- this is *EXACTLY* like check_server_parent_membership, but if we recurse
+ -- with the package-level one, we get a "cursor already open", so we need a
+ -- copy on our call stack instead. GROAN.
+ cursor local_chk_server_parent_memb (
+ server_id_in number,
+ channel_id_in number ) is
+ select c.id
+ from rhnChannel c,
+ rhnServerChannel sc
+ where 1=1
+ and c.parent_channel = channel_id_in
+ and c.id = sc.channel_id
+ and sc.server_id = server_id_in;
+ BEGIN
+ FOR child IN local_chk_server_parent_memb(server_id_in, channel_id_in)
+ LOOP
+ if unsubscribe_children_in = 1 then
+ unsubscribe_server(server_id_in => server_id_in,
+ channel_id_in => child.id,
+ immediate_in => immediate_in,
+ unsubscribe_children_in => unsubscribe_children_in,
+ deleting_server => deleting_server,
+ update_family_countsYN => update_family_countsYN);
+ else
+ rhn_exception.raise_exception('channel_unsubscribe_child_exists');
+ end if;
+ END LOOP child;
+
+ server_already_in_chan := FALSE;
+
+ FOR check_subscription IN check_server_subscription(server_id_in, channel_id_in)
+ LOOP
+ server_already_in_chan := TRUE;
+ END LOOP check_subscription;
+
+ IF NOT server_already_in_chan
+ THEN
+ RETURN;
+ END IF;
+
+ if deleting_server = 0 then
+
+ insert into rhnServerHistory (id,server_id,summary,details) (
+ select rhn_event_id_seq.nextval,
+ server_id_in,
+ 'unsubscribed from channel ' || SUBSTR(c.label, 0, 106),
+ c.label
+ from rhnChannel c
+ where c.id = channel_id_in
+ );
+
+ UPDATE rhnServer SET channels_changed = sysdate WHERE id = server_id_in;
+ end if;
+
+ DELETE FROM rhnServerChannel WHERE server_id = server_id_in AND channel_id = channel_id_in;
+
+ if deleting_server = 0 then
+ queue_server(server_id_in, immediate_in);
+ end if;
+
+ channel_family_id_val := rhn_channel.family_for_channel(channel_id_in);
+ IF channel_family_id_val IS NULL
+ THEN
+ rhn_exception.raise_exception('channel_unsubscribe_no_family');
+ END IF;
+
+ for ignore in channel_family_is_satellite(channel_family_id_val) loop
+ delete from rhnSatelliteInfo where server_id = server_id_in;
+ end loop;
+
+ for ignore in channel_family_is_proxy(channel_family_id_val) loop
+ delete from rhnProxyInfo where server_id = server_id_in;
+ end loop;
+ SELECT org_id INTO server_org_id_val
+ FROM rhnServer
+ WHERE id = server_id_in;
+
+ if update_family_countsYN = 1 then
+ rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
+ end if;
+ END unsubscribe_server;
+
+
+ FUNCTION family_for_channel(channel_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ channel_family_id_val NUMBER;
+ BEGIN
+ SELECT channel_family_id INTO channel_family_id_val
+ FROM rhnChannelFamilyMembers
+ WHERE channel_id = channel_id_in;
+
+ RETURN channel_family_id_val;
+ EXCEPTION
+ WHEN NO_DATA_FOUND
+ THEN
+ RETURN NULL;
+ END family_for_channel;
+
+ FUNCTION available_family_subscriptions(channel_family_id_in IN NUMBER, org_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ cfp channel_family_perm_cursor%ROWTYPE;
+ current_members_val NUMBER;
+ max_members_val NUMBER;
+ found NUMBER;
+ BEGIN
+ IF NOT channel_family_perm_cursor%ISOPEN
+ THEN
+ OPEN channel_family_perm_cursor(channel_family_id_in, org_id_in);
+ END IF;
+
+ FETCH channel_family_perm_cursor INTO cfp;
+
+ WHILE channel_family_perm_cursor%FOUND
+ LOOP
+ found := 1;
+
+ current_members_val := cfp.current_members;
+ max_members_val := cfp.max_members;
+
+ FETCH channel_family_perm_cursor INTO cfp;
+ END LOOP;
+
+ IF channel_family_perm_cursor%ISOPEN
+ THEN
+ CLOSE channel_family_perm_cursor;
+ END IF;
+
+ -- not found: either the channel fam doesn't have an entry in cfp, or the org doesn't have access to it.
+ -- either way, there are no available subscriptions
+
+ IF found IS NULL
+ THEN
+ RETURN 0;
+ END IF;
+
+ -- null max members? in that case, pass it on; NULL means infinite
+ IF max_members_val IS NULL
+ THEN
+ RETURN NULL;
+ END IF;
+
+ -- otherwise, return the delta
+ RETURN max_members_val - current_members_val;
+ END available_family_subscriptions;
+
+ FUNCTION available_fve_family_subs(channel_family_id_in IN NUMBER, org_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ cfp channel_family_perm_cursor%ROWTYPE;
+ fve_current_members_val NUMBER;
+ fve_max_members_val NUMBER;
+ found NUMBER;
+
+ BEGIN
+ IF NOT channel_family_perm_cursor%ISOPEN THEN
+ OPEN channel_family_perm_cursor(channel_family_id_in, org_id_in);
+ END IF;
+
+ FETCH channel_family_perm_cursor INTO cfp;
+
+ WHILE channel_family_perm_cursor%FOUND LOOP
+ found := 1;
+ fve_current_members_val := cfp.fve_current_members;
+ fve_max_members_val := cfp.fve_max_members;
+ FETCH channel_family_perm_cursor INTO cfp;
+ END LOOP;
+
+ IF channel_family_perm_cursor%ISOPEN THEN
+ CLOSE channel_family_perm_cursor;
+ END IF;
+
+ IF found IS NULL THEN
+ RETURN 0;
+ END IF;
+
+ IF fve_max_members_val IS NULL THEN
+ RETURN NULL;
+ END IF;
+
+ RETURN fve_max_members_val - fve_current_members_val;
+
+ END available_fve_family_subs;
+
+
+ -- *******************************************************************
+ -- FUNCTION: channel_family_current_members
+ -- Calculates and returns the actual count of systems consuming
+ -- physical channel subscriptions.
+ -- Called by: update_family_counts
+ -- rhn_entitlements.repoll_virt_guest_entitlements
+ -- *******************************************************************
+ function channel_family_current_members(channel_family_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ return number
+ is
+ current_members_count number := 0;
+ begin
+ select count(distinct server_id)
+ into current_members_count
+ from rhnChannelFamilyServerPhysical cfsp
+ where cfsp.channel_family_id = channel_family_id_in
+ and cfsp.customer_id = org_id_in;
+ return current_members_count;
+ end;
+
+
+ function cfam_curr_fve_members(
+ channel_family_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ return number
+ is
+ current_members_count number := 0;
+
+ begin
+ select count(sc.server_id)
+ into current_members_count
+ from rhnServerChannel sc,
+ rhnChannelFamilyMembers cfm,
+ rhnServer s
+ where s.org_id = org_id_in
+ and s.id = sc.server_id
+ and cfm.channel_family_id = channel_family_id_in
+ and cfm.channel_id = sc.channel_id
+ and exists (
+ select 1
+ from rhnChannelFamilyServerFve cfsp
+ where cfsp.CHANNEL_FAMILY_ID = channel_family_id_in
+ and cfsp.server_id = s.id
+ );
+
+ return current_members_count;
+ end;
+ PROCEDURE update_family_counts(channel_family_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ IS
+ BEGIN
+ update rhnPrivateChannelFamily
+ set current_members = ( channel_family_current_members(channel_family_id_in, org_id_in)),
+ fve_current_members = ( cfam_curr_fve_members(channel_family_id_in, org_id_in))
+ where org_id = org_id_in
+ and channel_family_id = channel_family_id_in;
+ END update_family_counts;
+
+ PROCEDURE update_group_family_counts(group_label_in IN VARCHAR2,
+ org_id_in IN NUMBER)
+ IS
+ BEGIN
+ FOR i IN (
+ SELECT DISTINCT CFM.channel_family_id, SG.org_id
+ FROM rhnChannelFamilyMembers CFM
+ JOIN rhnServerChannel SC
+ ON SC.channel_id = CFM.channel_id
+ JOIN rhnServerGroupMembers SGM
+ ON SC.server_id = SGM.server_id
+ JOIN rhnServerGroup SG
+ ON SGM.server_group_id = SG.id
+ JOIN rhnServerGroupType SGT
+ ON SG.group_type = SGT.id
+ WHERE SGT.label = group_label_in
+ AND SG.org_id = org_id_in
+ AND SGT.is_base = 'Y'
+ ) LOOP
+ rhn_channel.update_family_counts(i.channel_family_id, i.org_id);
+ END LOOP;
+ END update_group_family_counts;
+
+ FUNCTION available_chan_subscriptions(channel_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ channel_family_id_val NUMBER;
+ BEGIN
+ SELECT channel_family_id INTO channel_family_id_val
+ FROM rhnChannelFamilyMembers
+ WHERE channel_id = channel_id_in;
+
+ RETURN rhn_channel.available_family_subscriptions(
+ channel_family_id_val, org_id_in);
+ END available_chan_subscriptions;
+
+ FUNCTION available_fve_chan_subs(channel_id_in IN NUMBER,
+ org_id_in IN NUMBER)
+ RETURN NUMBER
+ IS
+ channel_family_id_val NUMBER;
+
+ BEGIN
+ SELECT channel_family_id INTO channel_family_id_val
+ FROM rhnChannelFamilyMembers
+ WHERE channel_id = channel_id_in;
+
+ RETURN rhn_channel.available_fve_family_subs( channel_family_id_val, org_id_in);
+ END available_fve_chan_subs;
+
+ procedure unsubscribe_server_from_family(server_id_in in number,
+ channel_family_id_in in number)
+ is
+ begin
+ delete
+ from rhnServerChannel rsc
+ where rsc.server_id = server_id_in
+ and channel_id in (
+ select rcfm.channel_id
+ from rhnChannelFamilyMembers rcfm
+ where rcfm.channel_family_id = channel_family_id_in);
+ end;
+
+ function get_org_id(channel_id_in in number)
+ return number
+ is
+ org_id_out number;
+ begin
+ select org_id into org_id_out
+ from rhnChannel
+ where id = channel_id_in;
+
+ return org_id_out;
+ end get_org_id;
+
+ function get_cfam_org_access(cfam_id_in in number, org_id_in in number)
+ return number
+ is
+ cursor families is
+ select 1
+ from rhnOrgChannelFamilyPermissions cfp
+ where cfp.org_id = org_id_in;
+ begin
+ -- the idea: if we get past this query,
+ -- the user has the role, else catch the exception and return 0
+ for family in families loop
+ return 1;
+ end loop;
+ return 0;
+ end;
+
+ function get_org_access(channel_id_in in number, org_id_in in number)
+ return number
+ is
+ throwaway number;
+ begin
+ -- the idea: if we get past this query,
+ -- the org has access to the channel, else catch the exception and return 0
+ select distinct 1 into throwaway
+ from rhnChannelFamilyMembers CFM,
+ rhnOrgChannelFamilyPermissions CFP
+ where cfp.org_id = org_id_in
+ and CFM.channel_family_id = CFP.channel_family_id
+ and CFM.channel_id = channel_id_in
+ and (CFP.max_members > 0 or CFP.max_members is null or CFP.fve_max_members > 0 or CFP.fve_max_members is null or CFP.org_id = 1);
+
+ return 1;
+ exception
+ when no_data_found
+ then
+ return 0;
+ end;
+
+ -- check if a user has a given role, or if such a role is inferrable
+ -- returns NULL if OK, error message otherwise
+ function user_role_check_debug(channel_id_in in number,
+ user_id_in in number,
+ role_in in varchar2)
+ return varchar2
+ is
+ org_id number;
+ begin
+ org_id := rhn_user.get_org_id(user_id_in);
+
+ -- channel might be shared
+ if role_in = 'subscribe' and
+ rhn_channel.shared_user_role_check(channel_id_in, user_id_in, role_in) = 1 then
+ return NULL;
+ end if;
+
+ if role_in = 'manage' and
+ NVL(rhn_channel.get_org_id(channel_id_in), -1) <> org_id then
+ return 'channel_not_owned';
+ end if;
+
+ if role_in = 'subscribe' and
+ rhn_channel.get_org_access(channel_id_in, org_id) = 0 then
+ return 'channel_not_available';
+ end if;
+
+ -- channel admins have all roles
+ if rhn_user.check_role_implied(user_id_in, 'channel_admin') = 1 then
+ return NULL;
+ end if;
+
+ -- the subscribe permission is inferred
+ -- UNLESS the not_globally_subscribable flag is set
+ if role_in = 'subscribe'
+ then
+ if rhn_channel.org_channel_setting(channel_id_in,
+ org_id,
+ 'not_globally_subscribable') = 0 then
+ return NULL;
+ end if;
+ end if;
+
+ -- all other roles (manage right now) are explicitly granted
+ if rhn_channel.direct_user_role_check(channel_id_in,
+ user_id_in, role_in) = 1 then
+ return NULL;
+ end if;
+ return 'direct_permission';
+ end;
+
+ -- same as above, but with 1/0 output; useful in views, etc
+ function user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ return number
+ is
+ begin
+ if rhn_channel.user_role_check_debug(channel_id_in,
+ user_id_in, role_in) is NULL then
+ return 1;
+ else
+ return 0;
+ end if;
+ end;
+
+ --
+ -- For multiorg phase II, this function simply checks to see if the user's
+ -- has a trust relationship that includes this channel by id.
+ --
+ function shared_user_role_check(channel_id in number, user_id in number, role in varchar2)
+ return number
+ is
+ n number;
+ oid number;
+ begin
+ oid := rhn_user.get_org_id(user_id);
+ select 1 into n
+ from rhnSharedChannelView s
+ where s.id = channel_id and s.org_trust_id = oid;
+ return 1;
+ exception
+ when no_data_found then
+ return 0;
+ end;
+
+ -- same as above, but returns 1 if user_id_in is null
+ -- This is useful in queries where user_id is not specified
+ function loose_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ return number
+ is
+ begin
+ if user_id_in is null then
+ return 1;
+ end if;
+ return user_role_check(channel_id_in, user_id_in, role_in);
+ end loose_user_role_check;
+
+ -- directly checks the table, no inferred permissions
+ function direct_user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ return number
+ is
+ throwaway number;
+ begin
+ -- the idea: if we get past this query, the user has the role, else catch the exception and return 0
+ select 1 into throwaway
+ from rhnChannelPermissionRole CPR,
+ rhnChannelPermission CP
+ where CP.user_id = user_id_in
+ and CP.channel_id = channel_id_in
+ and CPR.label = role_in
+ and CP.role_id = CPR.id;
+
+ return 1;
+ exception
+ when no_data_found
+ then
+ return 0;
+ end;
+
+ -- check if an org has a certain setting
+ function org_channel_setting(channel_id_in in number, org_id_in in number, setting_in in varchar2)
+ return number
+ is
+ throwaway number;
+ begin
+ -- the idea: if we get past this query, the org has the setting, else catch the exception and return 0
+ select 1 into throwaway
+ from rhnOrgChannelSettingsType OCST,
+ rhnOrgChannelSettings OCS
+ where OCS.org_id = org_id_in
+ and OCS.channel_id = channel_id_in
+ and OCST.label = setting_in
+ and OCS.setting_id = OCST.id;
+
+ return 1;
+ exception
+ when no_data_found
+ then
+ return 0;
+ end;
+
+ FUNCTION channel_priority(channel_id_in IN number)
+ RETURN number
+ IS
+ channel_name varchar2(256);
+ priority number;
+ end_of_life_val date;
+ org_id_val number;
+ BEGIN
+
+ select name, end_of_life, org_id
+ into channel_name, end_of_life_val, org_id_val
+ from rhnChannel
+ where id = channel_id_in;
+
+ if end_of_life_val is not null then
+ return -400;
+ end if;
+
+ if channel_name like 'Red Hat Enterprise Linux%' or channel_name like 'RHEL%' then
+ priority := 1000;
+ if channel_name not like '%Beta%' then
+ priority := priority + 1000;
+ end if;
+
+ priority := priority +
+ case
+ when channel_name like '%v. 5%' then 600
+ when channel_name like '%v. 4%' then 500
+ when channel_name like '%v. 3%' then 400
+ when channel_name like '%v. 2%' then 300
+ when channel_name like '%v. 1%' then 200
+ else 0
+ end;
+
+ priority := priority +
+ case
+ when channel_name like 'Red Hat Enterprise Linux (v. 5%' then 60
+ when (channel_name like '%AS%' and channel_name not like '%Extras%') then 50
+ when (channel_name like '%ES%' and channel_name not like '%Extras%') then 40
+ when (channel_name like '%WS%' and channel_name not like '%Extras%') then 30
+ when (channel_name like '%Desktop%' and channel_name not like '%Extras%') then 20
+ when channel_name like '%Extras%' then 10
+ else 0
+ end;
+
+ priority := priority +
+ case
+ when channel_name like '%)' then 5
+ else 0
+ end;
+
+ priority := priority +
+ case
+ when channel_name like '%32-bit x86%' then 4
+ when channel_name like '%64-bit Intel Itanium%' then 3
+ when channel_name like '%64-bit AMD64/Intel EM64T%' then 2
+ else 0
+ end;
+ elsif channel_name like 'Red Hat Desktop%' then
+ priority := 900;
+
+ if channel_name not like '%Beta%' then
+ priority := priority + 50;
+ end if;
+
+ priority := priority +
+ case
+ when channel_name like '%v. 4%' then 40
+ when channel_name like '%v. 3%' then 30
+ when channel_name like '%v. 2%' then 20
+ when channel_name like '%v. 1%' then 10
+ else 0
+ end;
+
+ priority := priority +
+ case
+ when channel_name like '%32-bit x86%' then 4
+ when channel_name like '%64-bit Intel Itanium%' then 3
+ when channel_name like '%64-bit AMD64/Intel EM64T%' then 2
+ else 0
+ end;
+
+ elsif org_id_val is not null then
+ priority := 600;
+ else
+ priority := 500;
+ end if;
+
+ return -priority;
+
+ end channel_priority;
+
+ -- right now this only does the accounting changes; the cascade
+ -- actually does the rhnServerChannel delete.
+ procedure delete_server_channels(server_id_in in number)
+ is
+ begin
+ update rhnPrivateChannelFamily
+ set current_members = current_members -1
+ where org_id in (
+ select org_id
+ from rhnServer
+ where id = server_id_in
+ )
+ and channel_family_id in (
+ select rcfm.channel_family_id
+ from rhnChannelFamilyMembers rcfm,
+ rhnServerChannel rsc
+ where rsc.server_id = server_id_in
+ and rsc.channel_id = rcfm.channel_id
+ and not exists (
+ select 1
+ from
+ rhnChannelFamilyVirtSubLevel cfvsl,
+ rhnSGTypeVirtSubLevel sgtvsl,
+ rhnServerEntitlementView sev,
+ rhnVirtualInstance vi
+ where
+ -- system is a virtual instance
+ vi.virtual_system_id = server_id_in
+ and vi.host_system_id = sev.server_id
+ -- system's host has a virt ent
+ and sev.label in ('virtualization_host',
+ 'virtualization_host_platform')
+ and sev.server_group_type_id =
+ sgtvsl.server_group_type_id
+ -- the host's virt ent grants a cf virt sub level
+ and sgtvsl.virt_sub_level_id = cfvsl.virt_sub_level_id
+ -- the cf is in that virt sub level
+ and cfvsl.channel_family_id = rcfm.channel_family_id
+ )
+ );
+ end;
+
+ -- this could certainly be optimized to do updates if needs be
+ procedure refresh_newest_package(channel_id_in in number,
+ caller_in in varchar2 := '(unknown)',
+ package_name_id_in in number := null)
+ is
+ -- procedure refreshes rows for name_id = package_name_id_in or
+ -- all rows if package_name_id_in is null
+ begin
+ delete from rhnChannelNewestPackage
+ where channel_id = channel_id_in
+ and (package_name_id_in is null
+ or name_id = package_name_id_in);
+ insert into rhnChannelNewestPackage
+ (channel_id, name_id, evr_id, package_id, package_arch_id)
+ (select channel_id,
+ name_id, evr_id,
+ package_id, package_arch_id
+ from rhnChannelNewestPackageView
+ where channel_id = channel_id_in
+ and (package_name_id_in is null
+ or name_id = package_name_id_in)
+ );
+ insert into rhnChannelNewestPackageAudit (channel_id, caller)
+ values (channel_id_in, caller_in);
+ update rhnChannel
+ set last_modified = greatest(sysdate, last_modified + 1/86400)
+ where id = channel_id_in;
+ end;
+
+ procedure update_channel ( channel_id_in in number, invalidate_ss in number := 0,
+ date_to_use in date := sysdate )
+ is
+
+ channel_last_modified date;
+ last_modified_value date;
+
+ cursor snapshots is
+ select snapshot_id id
+ from rhnSnapshotChannel
+ where channel_id = channel_id_in;
+
+ begin
+
+ select last_modified
+ into channel_last_modified
+ from rhnChannel
+ where id = channel_id_in;
+
+ last_modified_value := date_to_use;
+
+ if last_modified_value <= channel_last_modified then
+ last_modified_value := last_modified_value + 1/86400;
+ end if;
+
+ update rhnChannel set last_modified = last_modified_value
+ where id = channel_id_in;
+
+ if invalidate_ss = 1 then
+ for snapshot in snapshots loop
+ update rhnSnapshot
+ set invalid = lookup_snapshot_invalid_reason('channel_modified')
+ where id = snapshot.id;
+ end loop;
+ end if;
+
+ end update_channel;
+
+ procedure update_channels_by_package ( package_id_in in number, date_to_use in date := sysdate )
+ is
+
+ cursor channels is
+ select channel_id
+ from rhnChannelPackage
+ where package_id = package_id_in
+ order by channel_id;
+
+ begin
+ for channel in channels loop
+ -- we want to invalidate the snapshot assocated with the channel when we
+ -- do this b/c we know we've added or removed or packages
+ rhn_channel.update_channel ( channel.channel_id, 1, date_to_use );
+ end loop;
+ end update_channels_by_package;
+
+
+ procedure update_channels_by_errata ( errata_id_in number, date_to_use in date := sysdate )
+ is
+
+ cursor channels is
+ select channel_id
+ from rhnChannelErrata
+ where errata_id = errata_id_in
+ order by channel_id;
+
+ begin
+ for channel in channels loop
+ -- we won't invalidate snapshots, b/c just changing the errata associated with
+ -- a channel shouldn't invalidate snapshots
+ rhn_channel.update_channel ( channel.channel_id, 0, date_to_use );
+ end loop;
+ end update_channels_by_errata;
+
+ procedure update_needed_cache(channel_id_in in number)
+ is
+ -- update of needed cache ican be commited on a per server basis
+ -- b/c failure of update for a server means nothing for the other servers
+ begin
+ -- we intentionaly do a loop here instead of one huge select
+ -- b/c we want to break update into smaller transaction to unblock other sessions
+ -- querying rhnServerNeededCache
+ for server in (
+ select sc.server_id as id
+ from rhnServerChannel sc
+ where sc.channel_id = channel_id_in
+ ) loop
+ rhn_server.update_needed_cache(server.id);
+ commit;
+ end loop;
+ end update_needed_cache;
+
+END rhn_channel;
+/
+SHOW ERRORS
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/051-rhn_channel.pkb.sql.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/051-rhn_channel.pkb.sql.postgresql
new file mode 100644
index 0000000..1541f7f
--- /dev/null
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/051-rhn_channel.pkb.sql.postgresql
@@ -0,0 +1,131 @@
+-- oracle equivalent source sha1 d4a14b83901ab741e9eeaf7ff51be401a70b4bb5
+--
+--update pg_setting
+update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_path';
+
+ -- Converts server channel_family to use a flex entitlement
+ create or replace function convert_to_fve(server_id_in IN NUMERIC, channel_family_id_val IN NUMERIC)
+ returns void
+ as $$
+ declare
+ available_fve_subs NUMERIC;
+ server_org_id_val NUMERIC;
+ BEGIN
+
+ --
+ -- Use the org_id of the server only if the org_id of the channel = NULL.
+ -- This is required for subscribing to shared channels.
+ --
+ SELECT org_id
+ INTO server_org_id_val
+ FROM rhnServer
+ WHERE id = server_id_in;
+
+
+ perform rhn_channel.obtain_read_lock(channel_family_id_val, server_org_id_val);
+ if not found then
+ perform rhn_exception.raise_exception('channel_family_no_subscriptions');
+ end if;
+ IF (rhn_channel.can_convert_to_fve(server_id_in, channel_family_id_val ) = 0)
+ THEN
+ perform rhn_exception.raise_exception('server_cannot_convert_to_flex');
+ END IF;
+
+ available_fve_subs := rhn_channel.available_fve_family_subs(channel_family_id_val, server_org_id_val);
+
+ IF (available_fve_subs > 0)
+ THEN
+
+ insert into rhnServerHistory (id,server_id,summary,details) (
+ select nextval('rhn_event_id_seq'),
+ server_id_in,
+ 'converted to flex entitlement' || SUBSTR(cf.label, 0, 99),
+ cf.label
+ from rhnChannelFamily cf
+ where cf.id = channel_family_id_val
+ );
+
+ UPDATE rhnServerChannel sc set is_fve = 'Y'
+ where sc.server_id = server_id_in and
+ sc.channel_id in
+ (select cfm.channel_id from rhnChannelFamilyMembers cfm
+ where cfm.CHANNEL_FAMILY_ID = channel_family_id_val);
+
+ perform rhn_channel.update_family_counts(channel_family_id_val, server_org_id_val);
+ ELSE
+ perform rhn_exception.raise_exception('not_enough_flex_entitlements');
+ END IF;
+
+ END$$ language plpgsql;
+
+ drop function user_role_check_debug(channel_id_in in numeric,
+ user_id_in in numeric,
+ role_in in varchar,
+ status out numeric,
+ reason_out out varchar);
+
+ create or replace function user_role_check_debug(channel_id_in in numeric,
+ user_id_in in numeric,
+ role_in in varchar)
+ returns varchar
+ as $$
+ declare
+ org_id numeric;
+ begin
+ org_id := rhn_user.get_org_id(user_id_in);
+
+ -- channel might be shared
+ if role_in = 'subscribe' and
+ rhn_channel.shared_user_role_check(channel_id_in, user_id_in, role_in) = 1 then
+ return NULL;
+ end if;
+
+ if role_in = 'manage' and
+ COALESCE(rhn_channel.get_org_id(channel_id_in), -1) <> org_id then
+ return 'channel_not_owned';
+ end if;
+
+ if role_in = 'subscribe' and
+ rhn_channel.get_org_access(channel_id_in, org_id) = 0 then
+ return 'channel_not_available';
+ end if;
+
+ -- channel admins have all roles
+ if rhn_user.check_role_implied(user_id_in, 'channel_admin') = 1 then
+ return NULL;
+ end if;
+
+ -- the subscribe permission is inferred
+ -- UNLESS the not_globally_subscribable flag is set
+ if role_in = 'subscribe'
+ then
+ if rhn_channel.org_channel_setting(channel_id_in,
+ org_id,
+ 'not_globally_subscribable') = 0 then
+ return NULL;
+ end if;
+ end if;
+
+ -- all other roles (manage right now) are explicitly granted
+ if rhn_channel.direct_user_role_check(channel_id_in,
+ user_id_in, role_in) = 1 then
+ return NULL;
+ end if;
+ return 'direct_permission';
+ end$$ language plpgsql;
+
+ -- same as above, but with 1/0 output; useful in views, etc
+ create or replace function user_role_check(channel_id_in in numeric, user_id_in in numeric, role_in in varchar)
+ returns numeric
+ as $$
+ begin
+ if rhn_channel.user_role_check_debug(channel_id_in,
+ user_id_in, role_in) is NULL then
+ return 1;
+ else
+ return 0;
+ end if;
+ end$$ language plpgsql;
+
+-- restore the original setting
+update pg_settings set setting = overlay( setting placing '' from 1 for (length('rhn_channel')+1) ) where name = 'search_path';
commit 9411263c9a31ec66efbe424ee106cba9951c4fe7
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Tue May 29 11:01:38 2012 +0200
modified java stack to use new user_role_check_debug()
diff --git a/java/code/src/com/redhat/rhn/common/db/datasource/xml/Channel_queries.xml b/java/code/src/com/redhat/rhn/common/db/datasource/xml/Channel_queries.xml
index 3b0ce1f..2ab6889 100644
--- a/java/code/src/com/redhat/rhn/common/db/datasource/xml/Channel_queries.xml
+++ b/java/code/src/com/redhat/rhn/common/db/datasource/xml/Channel_queries.xml
@@ -196,8 +196,8 @@ ORDER BY UPPER(C.name)
</mode>
<callable-mode name="verify_channel_role">
- <query params="result, cid, user_id, role, reason">
- {:result = call rhn_channel.user_role_check_debug(:cid, :user_id, :role, :reason)}
+ <query params="result, cid, user_id, role">
+ {:result = call rhn_channel.user_role_check_debug(:cid, :user_id, :role)}
</query>
</callable-mode>
diff --git a/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java b/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java
index 181c866..5931155 100644
--- a/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java
+++ b/java/code/src/com/redhat/rhn/manager/channel/ChannelManager.java
@@ -1161,14 +1161,13 @@ public class ChannelManager extends BaseManager {
inParams.put("role", role);
Map outParams = new HashMap();
- outParams.put("result", new Integer(Types.NUMERIC));
- outParams.put("reason", new Integer(Types.VARCHAR));
+ outParams.put("result", new Integer(Types.VARCHAR));
Map result = m.execute(inParams, outParams);
- boolean accessible = BooleanUtils.toBoolean(
- ((Long) result.get("result")).intValue());
- if (!accessible) {
- String reason = (String) result.get("reason");
+ boolean accessible = true;
+ String reason = (String) result.get("result");
+ if (reason != null) {
+ accessible = false;
throw new InvalidChannelRoleException(reason);
}
return accessible;
diff --git a/java/code/src/com/redhat/rhn/manager/user/UserManager.java b/java/code/src/com/redhat/rhn/manager/user/UserManager.java
index 0db591c..a73b776 100644
--- a/java/code/src/com/redhat/rhn/manager/user/UserManager.java
+++ b/java/code/src/com/redhat/rhn/manager/user/UserManager.java
@@ -144,12 +144,13 @@ public class UserManager extends BaseManager {
inParams.put("role", role);
Map outParams = new HashMap();
- outParams.put("result", new Integer(Types.NUMERIC));
- outParams.put("reason", new Integer(Types.VARCHAR));
+ outParams.put("result", new Integer(Types.VARCHAR));
Map result = m.execute(inParams, outParams);
- boolean accessible = BooleanUtils.toBoolean(
- ((Long)result.get("result")).intValue());
+ boolean accessible = false;
+ if (result.get("result") == null) {
+ accessible = true;
+ }
return accessible;
}
commit a604aa41ae1d8db86902cefa1eb314ba6a2f18cf
Author: Michael Mraka <michael.mraka(a)redhat.com>
Date: Tue May 29 10:40:25 2012 +0200
get rid of out parameters in user_role_check_debug
diff --git a/schema/spacewalk/oracle/packages/rhn_channel.pkb b/schema/spacewalk/oracle/packages/rhn_channel.pkb
index fa1968a..d73e695 100644
--- a/schema/spacewalk/oracle/packages/rhn_channel.pkb
+++ b/schema/spacewalk/oracle/packages/rhn_channel.pkb
@@ -824,11 +824,11 @@ IS
end;
-- check if a user has a given role, or if such a role is inferrable
+ -- returns NULL if OK, error message otherwise
function user_role_check_debug(channel_id_in in number,
user_id_in in number,
- role_in in varchar2,
- reason_out out varchar2)
- return number
+ role_in in varchar2)
+ return varchar2
is
org_id number;
begin
@@ -837,52 +837,54 @@ IS
-- channel might be shared
if role_in = 'subscribe' and
rhn_channel.shared_user_role_check(channel_id_in, user_id_in, role_in) = 1 then
- return 1;
+ return NULL;
end if;
if role_in = 'manage' and
NVL(rhn_channel.get_org_id(channel_id_in), -1) <> org_id then
- reason_out := 'channel_not_owned';
- return 0;
- end if;
+ return 'channel_not_owned';
+ end if;
if role_in = 'subscribe' and
rhn_channel.get_org_access(channel_id_in, org_id) = 0 then
- reason_out := 'channel_not_available';
- return 0;
- end if;
+ return 'channel_not_available';
+ end if;
-- channel admins have all roles
if rhn_user.check_role_implied(user_id_in, 'channel_admin') = 1 then
- reason_out := 'channel_admin';
- return 1;
- end if;
+ return NULL;
+ end if;
-- the subscribe permission is inferred
- -- UNLESS the not_globally_subscribable flag is set
+ -- UNLESS the not_globally_subscribable flag is set
if role_in = 'subscribe'
then
if rhn_channel.org_channel_setting(channel_id_in,
org_id,
'not_globally_subscribable') = 0 then
- reason_out := 'globally_subscribable';
- return 1;
+ return NULL;
end if;
end if;
-- all other roles (manage right now) are explicitly granted
- reason_out := 'direct_permission';
- return rhn_channel.direct_user_role_check(channel_id_in,
- user_id_in, role_in);
+ if rhn_channel.direct_user_role_check(channel_id_in,
+ user_id_in, role_in) = 1 then
+ return NULL;
+ end if;
+ return 'direct_permission';
end;
- -- same as above, but with no OUT param; useful in views, etc
+ -- same as above, but with 1/0 output; useful in views, etc
function user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
return number
is
- throwaway varchar2(256);
begin
- return rhn_channel.user_role_check_debug(channel_id_in, user_id_in, role_in, throwaway);
+ if rhn_channel.user_role_check_debug(channel_id_in,
+ user_id_in, role_in) is NULL then
+ return 1;
+ else
+ return 0;
+ end if;
end;
--
diff --git a/schema/spacewalk/oracle/packages/rhn_channel.pks b/schema/spacewalk/oracle/packages/rhn_channel.pks
index afda8b5..7a301bd 100644
--- a/schema/spacewalk/oracle/packages/rhn_channel.pks
+++ b/schema/spacewalk/oracle/packages/rhn_channel.pks
@@ -107,8 +107,8 @@ IS
function get_cfam_org_access(cfam_id_in in number, org_id_in in number) return number;
- function user_role_check_debug(channel_id_in in number, user_id_in in number, role_in in varchar2, reason_out out varchar2)
- RETURN NUMBER;
+ function user_role_check_debug(channel_id_in in number, user_id_in in number, role_in in varchar2)
+ RETURN VARCHAR2;
PRAGMA RESTRICT_REFERENCES(user_role_check_debug, WNDS, RNPS, WNPS);
function user_role_check(channel_id_in in number, user_id_in in number, role_in in varchar2)
diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pkb b/schema/spacewalk/postgres/packages/rhn_channel.pkb
index 34d9282..a1e348b 100644
--- a/schema/spacewalk/postgres/packages/rhn_channel.pkb
+++ b/schema/spacewalk/postgres/packages/rhn_channel.pkb
@@ -840,11 +840,11 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
end$$ language plpgsql;
-- check if a user has a given role, or if such a role is inferrable
+ -- returns NULL if OK, error message otherwise
create or replace function user_role_check_debug(channel_id_in in numeric,
user_id_in in numeric,
- role_in in varchar,
- status out numeric,
- reason_out out varchar)
+ role_in in varchar)
+ returns varchar
as $$
declare
org_id numeric;
@@ -854,60 +854,54 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_
-- channel might be shared
if role_in = 'subscribe' and
rhn_channel.shared_user_role_check(channel_id_in, user_id_in, role_in) = 1 then
- status := 1;
- return;
+ return NULL;
end if;
if role_in = 'manage' and
COALESCE(rhn_channel.get_org_id(channel_id_in), -1) <> org_id then
- reason_out := 'channel_not_owned';
- status := 0;
- return;
- end if;
+ return 'channel_not_owned';
+ end if;
if role_in = 'subscribe' and
rhn_channel.get_org_access(channel_id_in, org_id) = 0 then
- reason_out := 'channel_not_available';
- status := 0;
- return;
- end if;
+ return 'channel_not_available';
+ end if;
-- channel admins have all roles
if rhn_user.check_role_implied(user_id_in, 'channel_admin') = 1 then
- reason_out := 'channel_admin';
- status := 1;
- return;
- end if;
+ return NULL;
+ end if;
-- the subscribe permission is inferred
- -- UNLESS the not_globally_subscribable flag is set
+ -- UNLESS the not_globally_subscribable flag is set
if role_in = 'subscribe'
then
if rhn_channel.org_channel_setting(channel_id_in,
org_id,
'not_globally_subscribable') = 0 then
- reason_out := 'globally_subscribable';
- status := 1;
- return;
+ return NULL;
end if;
end if;
-- all other roles (manage right now) are explicitly granted
- reason_out := 'direct_permission';
- status := rhn_channel.direct_user_role_check(channel_id_in,
- user_id_in, role_in);
- return;
+ if rhn_channel.direct_user_role_check(channel_id_in,
+ user_id_in, role_in) = 1 then
+ return NULL;
+ end if;
+ return 'direct_permission';
end$$ language plpgsql;
- -- same as above, but with no OUT param; useful in views, etc
+ -- same as above, but with 1/0 output; useful in views, etc
create or replace function user_role_check(channel_id_in in numeric, user_id_in in numeric, role_in in varchar)
returns numeric
as $$
- declare
- throwaway record;
begin
- throwaway := rhn_channel.user_role_check_debug(channel_id_in, user_id_in, role_in);
- return throwaway.status;
+ if rhn_channel.user_role_check_debug(channel_id_in,
+ user_id_in, role_in) is NULL then
+ return 1;
+ else
+ return 0;
+ end if;
end$$ language plpgsql;
--
11 years, 11 months
java/code
by Šimon Lukašík
java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java | 4 +--
java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java | 13 +++++++---
2 files changed, 12 insertions(+), 5 deletions(-)
New commits:
commit 61143cb4c7a25deb5bc447b578a706d96dd6e635
Author: Simon Lukasik <slukasik(a)redhat.com>
Date: Tue May 29 15:36:55 2012 +0200
A checkstyle fix.
Addressing:
./code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java:36:27: Name 'IDENT_INDEX' must match pattern '^[a-z][a-zA-Z0-9]*$'.
./code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java:37:27: Name 'INDEX_SEARCH' must match pattern '^[a-z][a-zA-Z0-9]*$'.
./code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java:38:27: Name 'SYSTEM_LIST' must match pattern '^[a-z][a-zA-Z0-9]*$'.
./code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java:40:5: Missing a Javadoc comment.
./code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java:49:27: Name 'SEARCH_STRING' must match pattern '^[a-z][a-zA-Z0-9]*$'.
./code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java:50:27: Name 'WHERE_TO_SEARCH' must match pattern '^[a-z][a-zA-Z0-9]*$'.
diff --git a/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java b/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java
index 831abe8..3a16605 100644
--- a/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java
@@ -46,8 +46,8 @@ import com.redhat.rhn.frontend.taglibs.list.ListTagHelper;
*/
public class XccdfSearchAction extends RhnAction {
- private static String SEARCH_STRING = "search_string";
- private static String WHERE_TO_SEARCH = "whereToSearch";
+ private static final String SEARCH_STRING = "search_string";
+ private static final String WHERE_TO_SEARCH = "whereToSearch";
private static Logger log = Logger.getLogger(XccdfSearchAction.class);
/** {@inheritDoc} */
diff --git a/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java b/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java
index a153b55..ca28bd9 100644
--- a/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java
+++ b/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java
@@ -33,10 +33,17 @@ import com.redhat.rhn.manager.audit.ScapManager;
*/
public class XccdfSearchHelper extends RhnAction {
- private static String IDENT_INDEX = "xccdfIdent";
- private static String INDEX_SEARCH = "index.search";
- private static String SYSTEM_LIST = "system_list";
+ private static final String IDENT_INDEX = "xccdfIdent";
+ private static final String INDEX_SEARCH = "index.search";
+ private static final String SYSTEM_LIST = "system_list";
+ /**
+ * Perform search over XCCDF
+ * @param searchString A string to search within xccdf:Rules
+ * @param whereToSearch Where to search for scans, either ssm or all machines
+ * @param context A context of cuyrrent request
+ * @return a list of xccdf:rule-results
+ */
public static List performSearch(String searchString, String whereToSearch,
RequestContext context)
throws MalformedURLException, XmlRpcException, XmlRpcFault {
11 years, 11 months
Changes to 'refs/tags/spacewalk-java-1.8.77-1'
by Šimon Lukašík
Tag 'spacewalk-java-1.8.77-1' created by Simon Lukasik <slukasik(a)redhat.com> at 2012-05-29 12:41 +0000
Tagging package [spacewalk-java] version [1.8.77-1] in directory [java/].
Changes since spacewalk-java-1.8.76-1:
Milan Zazrivec (1):
get rid of jabberd xsl templates in spacewalk-setup
Simon Lukasik (6):
Promote some of the rule's columns to fragment.
Start indexing XCCDF idents.
OpenSCAP integration -- A simple search page.
Add option to search scap within SSM.
Fail gracefully on empty list of systems
Automatic commit of package [spacewalk-java] release [1.8.77-1].
---
java/code/src/com/redhat/rhn/common/db/datasource/xml/scap_queries.xml | 37 ++
java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java | 149 ++++++++++
java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java | 91 ++++++
java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml | 6
java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml | 21 +
java/code/src/com/redhat/rhn/frontend/xmlrpc/system/scap/SystemScapHandler.java | 5
java/code/src/com/redhat/rhn/manager/audit/ScapManager.java | 31 ++
java/code/webapp/WEB-INF/nav/sitenav-authenticated.xml | 5
java/code/webapp/WEB-INF/pages/audit/scap/xccdfsearch.jsp | 73 ++++
java/code/webapp/WEB-INF/pages/common/fragments/audit/rule-common-columns.jspf | 28 +
java/code/webapp/WEB-INF/pages/systems/details/audit/xccdfdetails.jsp | 20 -
java/code/webapp/WEB-INF/struts-config.xml | 15 +
java/spacewalk-java.spec | 8
rel-eng/packages/spacewalk-java | 2
search-server/spacewalk-search/scripts/Reindex.groovy | 6
search-server/spacewalk-search/src/config/com/redhat/satellite/search/db/config.xml | 1
search-server/spacewalk-search/src/config/com/redhat/satellite/search/db/xccdf_ident.xml | 42 ++
search-server/spacewalk-search/src/java/com/redhat/satellite/search/DeleteIndexes.java | 2
search-server/spacewalk-search/src/java/com/redhat/satellite/search/db/models/XccdfIdent.java | 38 ++
search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/IndexManager.java | 6
search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/builder/BuilderFactory.java | 4
search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/builder/XccdfIdentDocumentBuilder.java | 51 +++
search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/ScheduleManager.java | 8
search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/tasks/IndexXccdfIdentTask.java | 107 +++++++
search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/tests/ScheduleManagerTest.java | 1
spacewalk/setup/share/jabberd/c2s.xsl | 27 -
spacewalk/setup/share/jabberd/s2s.xsl | 34 --
spacewalk/setup/share/jabberd/sm.xsl | 17 -
web/html/nav/sitenav-authenticated.xml | 5
29 files changed, 736 insertions(+), 104 deletions(-)
---
11 years, 11 months
java/spacewalk-java.spec rel-eng/packages
by Šimon Lukašík
java/spacewalk-java.spec | 8 +++++++-
rel-eng/packages/spacewalk-java | 2 +-
2 files changed, 8 insertions(+), 2 deletions(-)
New commits:
commit fec7156bae1376a45a435c5a3e08886adf529a28
Author: Simon Lukasik <slukasik(a)redhat.com>
Date: Tue May 29 14:41:57 2012 +0200
Automatic commit of package [spacewalk-java] release [1.8.77-1].
diff --git a/java/spacewalk-java.spec b/java/spacewalk-java.spec
index ab6386c..2b2c5df 100644
--- a/java/spacewalk-java.spec
+++ b/java/spacewalk-java.spec
@@ -22,7 +22,7 @@ Name: spacewalk-java
Summary: Spacewalk Java site packages
Group: Applications/Internet
License: GPLv2
-Version: 1.8.76
+Version: 1.8.77
Release: 1%{?dist}
URL: https://fedorahosted.org/spacewalk
Source0: https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
@@ -605,6 +605,12 @@ fi
%{jardir}/postgresql-jdbc.jar
%changelog
+* Tue May 29 2012 Simon Lukasik <slukasik(a)redhat.com> 1.8.77-1
+- Fail gracefully on empty list of systems
+- Add option to search scap within SSM.
+- OpenSCAP integration -- A simple search page.
+- Promote some of the rule's columns to fragment.
+
* Tue May 29 2012 Tomas Lestach <tlestach(a)redhat.com> 1.8.76-1
- 814659 - add an extra entitlement check before the key creation
- Enhancements pt_BR localization at webUI
diff --git a/rel-eng/packages/spacewalk-java b/rel-eng/packages/spacewalk-java
index 90364b3..50c85bf 100644
--- a/rel-eng/packages/spacewalk-java
+++ b/rel-eng/packages/spacewalk-java
@@ -1 +1 @@
-1.8.76-1 java/
+1.8.77-1 java/
11 years, 11 months
5 commits - java/code search-server/spacewalk-search web/html
by Šimon Lukašík
java/code/src/com/redhat/rhn/common/db/datasource/xml/scap_queries.xml | 37 ++
java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java | 149 ++++++++++
java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java | 91 ++++++
java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml | 6
java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml | 21 +
java/code/src/com/redhat/rhn/frontend/xmlrpc/system/scap/SystemScapHandler.java | 5
java/code/src/com/redhat/rhn/manager/audit/ScapManager.java | 31 ++
java/code/webapp/WEB-INF/nav/sitenav-authenticated.xml | 5
java/code/webapp/WEB-INF/pages/audit/scap/xccdfsearch.jsp | 73 ++++
java/code/webapp/WEB-INF/pages/common/fragments/audit/rule-common-columns.jspf | 28 +
java/code/webapp/WEB-INF/pages/systems/details/audit/xccdfdetails.jsp | 20 -
java/code/webapp/WEB-INF/struts-config.xml | 15 +
search-server/spacewalk-search/scripts/Reindex.groovy | 6
search-server/spacewalk-search/src/config/com/redhat/satellite/search/db/config.xml | 1
search-server/spacewalk-search/src/config/com/redhat/satellite/search/db/xccdf_ident.xml | 42 ++
search-server/spacewalk-search/src/java/com/redhat/satellite/search/DeleteIndexes.java | 2
search-server/spacewalk-search/src/java/com/redhat/satellite/search/db/models/XccdfIdent.java | 38 ++
search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/IndexManager.java | 6
search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/builder/BuilderFactory.java | 4
search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/builder/XccdfIdentDocumentBuilder.java | 51 +++
search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/ScheduleManager.java | 8
search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/tasks/IndexXccdfIdentTask.java | 107 +++++++
search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/tests/ScheduleManagerTest.java | 1
web/html/nav/sitenav-authenticated.xml | 5
24 files changed, 728 insertions(+), 24 deletions(-)
New commits:
commit 7be11b102bf1854ec7c038fb4b3227172dd1b0c0
Author: Simon Lukasik <slukasik(a)redhat.com>
Date: Mon May 28 18:11:04 2012 +0200
Fail gracefully on empty list of systems
Addressing:
2012-05-28 10:30:06,416 [TP-Processor3] ERROR com.redhat.rhn.frontend.xmlrpc.BaseHandler - Caused by:
java.lang.NullPointerException
at com.redhat.rhn.frontend.xmlrpc.system.scap.SystemScapHandler.scheduleXccdfScan(SystemScapHandler.java:156)
at com.redhat.rhn.frontend.xmlrpc.system.scap.SystemScapHandler.scheduleXccdfScan(SystemScapHandler.java:122)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at com.redhat.rhn.frontend.xmlrpc.BaseHandler.invoke(BaseHandler.java:108)
at redstone.xmlrpc.XmlRpcDispatcher.dispatch(XmlRpcDispatcher.java:123)
at com.redhat.rhn.frontend.xmlrpc.RhnXmlRpcServer.execute(RhnXmlRpcServer.java:54)
at com.redhat.rhn.frontend.xmlrpc.XmlRpcServlet.doPost(XmlRpcServlet.java:162)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
(...)
diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/scap/SystemScapHandler.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/scap/SystemScapHandler.java
index ebc30a4..b6ff28d 100644
--- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/scap/SystemScapHandler.java
+++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/system/scap/SystemScapHandler.java
@@ -27,6 +27,7 @@ import com.redhat.rhn.domain.user.User;
import com.redhat.rhn.frontend.dto.XccdfRuleResultDto;
import com.redhat.rhn.frontend.dto.XccdfTestResultDto;
import com.redhat.rhn.frontend.xmlrpc.BaseHandler;
+import com.redhat.rhn.frontend.xmlrpc.InvalidSystemException;
import com.redhat.rhn.manager.MissingCapabilityException;
import com.redhat.rhn.manager.MissingEntitlementException;
import com.redhat.rhn.manager.action.ActionManager;
@@ -145,6 +146,10 @@ public class SystemScapHandler extends BaseHandler {
String xccdfPath, String oscapParams, Date date) {
User loggedInUser = getLoggedInUser(sessionKey);
+ if (serverIds.isEmpty()) {
+ throw new InvalidSystemException();
+ }
+
HashSet<Long> longServerIds = new HashSet<Long>();
for (Iterator it = serverIds.iterator(); it.hasNext();) {
longServerIds.add(new Long((Integer) it.next()));
commit 1f7a2b0e009c6e0af01f3bca9e0e4e640be4de84
Author: Simon Lukasik <slukasik(a)redhat.com>
Date: Fri May 25 13:40:57 2012 +0200
Add option to search scap within SSM.
diff --git a/java/code/src/com/redhat/rhn/common/db/datasource/xml/scap_queries.xml b/java/code/src/com/redhat/rhn/common/db/datasource/xml/scap_queries.xml
index 8403b4c..592cd8d 100644
--- a/java/code/src/com/redhat/rhn/common/db/datasource/xml/scap_queries.xml
+++ b/java/code/src/com/redhat/rhn/common/db/datasource/xml/scap_queries.xml
@@ -131,6 +131,25 @@
</query>
</mode>
+<mode name="ruleresults_by_idents_for_ssm" class="com.redhat.rhn.frontend.dto.XccdfRuleResultDto">
+ <query params="user_id">
+ SELECT DISTINCT rr.id, rrt.label, rr.testresult_id AS test_result_id
+ FROM rhnXccdfRuleresult rr,
+ rhnXccdfRuleresultType rrt,
+ rhnXccdfRuleIdentMap rim,
+ rhnXccdfTestResult tr,
+ rhnSet st
+ WHERE rim.ident_id IN (%s)
+ AND rim.rresult_id = rr.id
+ AND rr.result_id = rrt.id
+ AND tr.id = testresult_id
+ AND tr.server_id = st.element
+ AND st.user_id = :user_id
+ AND st.label = 'system_list'
+ ORDER BY rr.id DESC
+ </query>
+</mode>
+
<mode name="idents_per_ruleresult" class="com.redhat.rhn.frontend.dto.XccdfIdentDto">
<query params="rr_id">
SELECT xi.id, xi.identifier, xis.system
diff --git a/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java b/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java
index 9743cef..831abe8 100644
--- a/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java
@@ -47,6 +47,7 @@ import com.redhat.rhn.frontend.taglibs.list.ListTagHelper;
public class XccdfSearchAction extends RhnAction {
private static String SEARCH_STRING = "search_string";
+ private static String WHERE_TO_SEARCH = "whereToSearch";
private static Logger log = Logger.getLogger(XccdfSearchAction.class);
/** {@inheritDoc} */
@@ -114,11 +115,15 @@ public class XccdfSearchAction extends RhnAction {
throws MalformedURLException, XmlRpcException, XmlRpcFault {
RequestContext context = new RequestContext(request);
String searchString = request.getParameter(SEARCH_STRING);
+ String whereToSearch = request.getParameter(WHERE_TO_SEARCH);
request.setAttribute(SEARCH_STRING, searchString);
+ form.set(WHERE_TO_SEARCH,
+ "system_list".equals(whereToSearch) ? whereToSearch : "all");
if (!StringUtils.isBlank(searchString)) {
- List results = XccdfSearchHelper.performSearch(searchString, context);
+ List results = XccdfSearchHelper.performSearch(searchString, whereToSearch,
+ context);
request.setAttribute(RequestContext.PAGE_LIST,
results != null ? results : Collections.EMPTY_LIST);
}
diff --git a/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java b/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java
index 57cd699..a153b55 100644
--- a/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java
+++ b/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java
@@ -35,8 +35,10 @@ public class XccdfSearchHelper extends RhnAction {
private static String IDENT_INDEX = "xccdfIdent";
private static String INDEX_SEARCH = "index.search";
+ private static String SYSTEM_LIST = "system_list";
- public static List performSearch(String searchString, RequestContext context)
+ public static List performSearch(String searchString, String whereToSearch,
+ RequestContext context)
throws MalformedURLException, XmlRpcException, XmlRpcFault {
ArrayList args = new ArrayList();
args.add(context.getWebSession().getId());
@@ -52,7 +54,14 @@ public class XccdfSearchHelper extends RhnAction {
Long id = new Long((String)item.get("id"));
identIds.add(id);
}
- return ScapManager.ruleResultsByIdentIds(context.getCurrentUser(), identIds);
+
+ if (SYSTEM_LIST.equals(whereToSearch)) {
+ return ScapManager.ruleResultsByIdentIdsForSsm(context.getCurrentUser(),
+ identIds);
+ }
+ else {
+ return ScapManager.ruleResultsByIdentIds(context.getCurrentUser(), identIds);
+ }
}
private static String preprocessSearchString(String searchString) {
diff --git a/java/code/src/com/redhat/rhn/manager/audit/ScapManager.java b/java/code/src/com/redhat/rhn/manager/audit/ScapManager.java
index caf2f7a..46cc269 100644
--- a/java/code/src/com/redhat/rhn/manager/audit/ScapManager.java
+++ b/java/code/src/com/redhat/rhn/manager/audit/ScapManager.java
@@ -145,6 +145,22 @@ public class ScapManager extends BaseManager {
}
/**
+ * Get xccdf:rule-results by ident's ids, but only those in relation
+ * with some of the SSM systems.
+ * @param user requesting results
+ * @param identIds list of xccdf:ident ids
+ * @return the result
+ */
+ public static List<XccdfRuleResultDto> ruleResultsByIdentIdsForSsm(
+ User user, List<Long> identIds) {
+ SelectMode m = ModeFactory.getMode("scap_queries",
+ "ruleresults_by_idents_for_ssm");
+ HashMap params = new HashMap();
+ params.put("user_id", user.getId());
+ return m.execute(params, identIds);
+ }
+
+ /**
* Show xccdf:ident results for given rule-result
* @param ruleResultId of XccdfRuleResultDto
* @return the list of idents
diff --git a/java/code/webapp/WEB-INF/pages/audit/scap/xccdfsearch.jsp b/java/code/webapp/WEB-INF/pages/audit/scap/xccdfsearch.jsp
index c48de4b..55d85fe 100644
--- a/java/code/webapp/WEB-INF/pages/audit/scap/xccdfsearch.jsp
+++ b/java/code/webapp/WEB-INF/pages/audit/scap/xccdfsearch.jsp
@@ -33,6 +33,18 @@
</span>
</td>
</tr>
+ <tr><th><bean:message key="systemsearch.jsp.wheretosearch"/></th>
+ <td>
+ <div style="text-align: left">
+ <html:radio property="whereToSearch" value="all" styleId="whereToSearch-all"/>
+ <label for="whereToSearch-all"><bean:message key="systemsearch.jsp.searchallsystems"/></label>
+ </div>
+ <div style="text-align: left">
+ <html:radio property="whereToSearch" value="system_list" styleId="whereToSearch-system_list"/>
+ <label for="whereToSearch-system_list"><bean:message key="systemsearch.jsp.searchSSM"/></label>
+ </div>
+ </td>
+ </tr>
</table>
</div> <!-- search-choices-group -->
</div> <!-- search-choices -->
@@ -53,6 +65,7 @@
<!-- there are two forms here, need to keep the formvars around for pagination -->
<input type="hidden" name="submitted" value="true"/>
<input type="hidden" name="search_string" value="${search_string}"/>
+ <input type="hidden" name="whereToSearch" value="${whereToSearch}"/>
</rl:listset>
</c:if>
diff --git a/java/code/webapp/WEB-INF/struts-config.xml b/java/code/webapp/WEB-INF/struts-config.xml
index 0fb7027..0565d64 100644
--- a/java/code/webapp/WEB-INF/struts-config.xml
+++ b/java/code/webapp/WEB-INF/struts-config.xml
@@ -236,6 +236,7 @@
<form-bean name="xccdfSearchForm"
type="com.redhat.rhn.frontend.struts.ScrubbingDynaActionForm">
<form-property name="search_string" type="java.lang.String"/>
+ <form-property name="whereToSearch" type="java.lang.String"/>
<form-property name="submitted" type="java.lang.Boolean" />
</form-bean>
<form-bean name="errataSearchForm"
commit b2c78eafd7efd1a3ed7e1a733fbb844c045729c4
Author: Simon Lukasik <slukasik(a)redhat.com>
Date: Tue May 22 12:22:14 2012 +0200
OpenSCAP integration -- A simple search page.
diff --git a/java/code/src/com/redhat/rhn/common/db/datasource/xml/scap_queries.xml b/java/code/src/com/redhat/rhn/common/db/datasource/xml/scap_queries.xml
index ff67100..8403b4c 100644
--- a/java/code/src/com/redhat/rhn/common/db/datasource/xml/scap_queries.xml
+++ b/java/code/src/com/redhat/rhn/common/db/datasource/xml/scap_queries.xml
@@ -113,6 +113,24 @@
</query>
</mode>
+<mode name="ruleresults_by_idents" class="com.redhat.rhn.frontend.dto.XccdfRuleResultDto">
+ <query params="user_id">
+ SELECT DISTINCT rr.id, rrt.label, rr.testresult_id AS test_result_id
+ FROM rhnXccdfRuleresult rr,
+ rhnXccdfRuleresultType rrt,
+ rhnXccdfRuleIdentMap rim,
+ rhnXccdfTestresult tr,
+ rhnUserServerPerms usp
+ WHERE rim.ident_id IN (%s)
+ AND rim.rresult_id = rr.id
+ AND rr.result_id = rrt.id
+ AND tr.id = rr.testresult_id
+ AND tr.server_id = usp.server_id
+ AND usp.user_id = :user_id
+ ORDER BY rr.id DESC
+ </query>
+</mode>
+
<mode name="idents_per_ruleresult" class="com.redhat.rhn.frontend.dto.XccdfIdentDto">
<query params="rr_id">
SELECT xi.id, xi.identifier, xis.system
diff --git a/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java b/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java
new file mode 100644
index 0000000..9743cef
--- /dev/null
+++ b/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchAction.java
@@ -0,0 +1,144 @@
+/**
+ * Copyright (c) 2012 Red Hat, Inc.
+ *
+ * This software is licensed to you under the GNU General Public License,
+ * version 2 (GPLv2). There is NO WARRANTY for this software, express or
+ * implied, including the implied warranties of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+ * along with this software; if not, see
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ * Red Hat trademarks are not licensed under GPLv2. No permission is
+ * granted to use or replicate Red Hat trademarks that are incorporated
+ * in this software or its documentation.
+ */
+package com.redhat.rhn.frontend.action.audit.scap;
+
+import java.net.MalformedURLException;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang.StringUtils;
+import org.apache.struts.action.ActionErrors;
+import org.apache.struts.action.ActionForm;
+import org.apache.struts.action.ActionForward;
+import org.apache.struts.action.ActionMapping;
+import org.apache.struts.action.ActionMessage;
+import org.apache.struts.action.ActionMessages;
+import org.apache.struts.action.DynaActionForm;
+import org.directwebremoting.util.Logger;
+
+import redstone.xmlrpc.XmlRpcException;
+import redstone.xmlrpc.XmlRpcFault;
+
+import com.redhat.rhn.frontend.struts.RequestContext;
+import com.redhat.rhn.frontend.struts.RhnAction;
+import com.redhat.rhn.frontend.struts.RhnHelper;
+import com.redhat.rhn.frontend.taglibs.list.ListTagHelper;
+
+/**
+ * XccdfSearchAction
+ */
+public class XccdfSearchAction extends RhnAction {
+
+ private static String SEARCH_STRING = "search_string";
+ private static Logger log = Logger.getLogger(XccdfSearchAction.class);
+
+ /** {@inheritDoc} */
+ public ActionForward execute(ActionMapping mapping, ActionForm formIn,
+ HttpServletRequest request, HttpServletResponse response) {
+ ActionErrors errors = new ActionErrors();
+ DynaActionForm form = (DynaActionForm) formIn;
+ String searchString = request.getParameter(SEARCH_STRING);
+
+ request.setAttribute(ListTagHelper.PARENT_URL, request.getRequestURI());
+
+ if (!isSubmitted(form)) {
+ try {
+ setupForm(request, form);
+ return getStrutsDelegate().forwardParams(
+ mapping.findForward(RhnHelper.DEFAULT_FORWARD),
+ request.getParameterMap());
+ }
+ catch (XmlRpcException xre) {
+ log.error("Could not connect to search server.", xre);
+ errors.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage("packages.search.connection_error"));
+ }
+ catch (XmlRpcFault e) {
+ log.info("Caught Exception :" + e);
+ log.info("ErrorCode = " + e.getErrorCode());
+ e.printStackTrace();
+ if (e.getErrorCode() == 100) {
+ log.error("Invalid search query", e);
+ errors.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage("packages.search.could_not_parse_query",
+ searchString));
+ }
+ else if (e.getErrorCode() == 200) {
+ log.error("Index files appear to be missing: ", e);
+ errors.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage("packages.search.index_files_missing",
+ searchString));
+ }
+ else {
+ errors.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage("packages.search.could_not_execute_query",
+ searchString));
+ }
+ }
+ catch (MalformedURLException e) {
+ log.error("Could not connect to server.", e);
+ errors.add(ActionMessages.GLOBAL_MESSAGE,
+ new ActionMessage("packages.search.connection_error"));
+ }
+ }
+
+ if (!errors.isEmpty()) {
+ addErrors(request, errors);
+ return getStrutsDelegate().forwardParams(
+ mapping.findForward(RhnHelper.DEFAULT_FORWARD),
+ createForwardParams(request));
+ }
+ return getStrutsDelegate().forwardParams(
+ mapping.findForward("success"),
+ createForwardParams(request));
+ }
+
+ private void setupForm(HttpServletRequest request, DynaActionForm form)
+ throws MalformedURLException, XmlRpcException, XmlRpcFault {
+ RequestContext context = new RequestContext(request);
+ String searchString = request.getParameter(SEARCH_STRING);
+
+ request.setAttribute(SEARCH_STRING, searchString);
+
+ if (!StringUtils.isBlank(searchString)) {
+ List results = XccdfSearchHelper.performSearch(searchString, context);
+ request.setAttribute(RequestContext.PAGE_LIST,
+ results != null ? results : Collections.EMPTY_LIST);
+ }
+ else {
+ request.setAttribute(RequestContext.PAGE_LIST, Collections.EMPTY_LIST);
+ }
+ }
+
+ private Map createForwardParams(HttpServletRequest request) {
+ Map forwardParams = makeParamMap(request);
+ // keep all params except submitted, in order for the new list
+ // tag pagination to work we need to pass along all the formvars it
+ // generated.
+ Enumeration paramNames = request.getParameterNames();
+ while (paramNames.hasMoreElements()) {
+ String name = (String) paramNames.nextElement();
+ if (!SUBMITTED.equals(name)) {
+ forwardParams.put(name, request.getParameter(name));
+ }
+ }
+ return forwardParams;
+ }
+}
diff --git a/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java b/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java
new file mode 100644
index 0000000..57cd699
--- /dev/null
+++ b/java/code/src/com/redhat/rhn/frontend/action/audit/scap/XccdfSearchHelper.java
@@ -0,0 +1,82 @@
+/**
+ * Copyright (c) 2012 Red Hat, Inc.
+ *
+ * This software is licensed to you under the GNU General Public License,
+ * version 2 (GPLv2). There is NO WARRANTY for this software, express or
+ * implied, including the implied warranties of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+ * along with this software; if not, see
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ * Red Hat trademarks are not licensed under GPLv2. No permission is
+ * granted to use or replicate Red Hat trademarks that are incorporated
+ * in this software or its documentation.
+ */
+package com.redhat.rhn.frontend.action.audit.scap;
+
+import java.net.MalformedURLException;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import redstone.xmlrpc.XmlRpcClient;
+import redstone.xmlrpc.XmlRpcException;
+import redstone.xmlrpc.XmlRpcFault;
+
+import com.redhat.rhn.common.conf.ConfigDefaults;
+import com.redhat.rhn.frontend.struts.RequestContext;
+import com.redhat.rhn.frontend.struts.RhnAction;
+import com.redhat.rhn.manager.audit.ScapManager;
+
+/**
+ * XccdfSearchHelper
+ */
+public class XccdfSearchHelper extends RhnAction {
+
+ private static String IDENT_INDEX = "xccdfIdent";
+ private static String INDEX_SEARCH = "index.search";
+
+ public static List performSearch(String searchString, RequestContext context)
+ throws MalformedURLException, XmlRpcException, XmlRpcFault {
+ ArrayList args = new ArrayList();
+ args.add(context.getWebSession().getId());
+ args.add(IDENT_INDEX);
+ args.add(preprocessSearchString(searchString));
+ args.add(true); //fine grained
+ List searchResult = invokeSearchServer(INDEX_SEARCH, args);
+ // searchResult contains id to rhnXccdfIdent relation,
+ // while we want to return RuleResults
+ List<Long> identIds = new ArrayList<Long>();
+ for (int x = searchResult.size() - 1; x >= 0; x--) {
+ Map item = (Map) searchResult.get(x);
+ Long id = new Long((String)item.get("id"));
+ identIds.add(id);
+ }
+ return ScapManager.ruleResultsByIdentIds(context.getCurrentUser(), identIds);
+ }
+
+ private static String preprocessSearchString(String searchString) {
+ return "identifier:(" + keywordsToUpper(searchString) + ")";
+ }
+
+ private static String keywordsToUpper(String searchString) {
+ StringBuffer buf = new StringBuffer(searchString.length() + 1);
+ for (String s : searchString.split(" ")) {
+ if (s.trim().equalsIgnoreCase("AND") ||
+ s.trim().equalsIgnoreCase("OR") ||
+ s.trim().equalsIgnoreCase("NOT")) {
+ s = s.toUpperCase();
+ }
+ buf.append(s);
+ buf.append(" ");
+ }
+ return buf.toString().trim();
+ }
+
+ private static List invokeSearchServer(String path, List args)
+ throws MalformedURLException, XmlRpcException, XmlRpcFault {
+ XmlRpcClient client = new XmlRpcClient(
+ ConfigDefaults.get().getSearchServerUrl(), true);
+ return (List) client.invoke(path, args);
+ }
+}
diff --git a/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml b/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml
index 549bc4f..e0f656a 100644
--- a/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml
+++ b/java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_en_US.xml
@@ -373,6 +373,12 @@ http://www.oasis-open.org/committees/xliff/documents/xliff-core-1.1.xsd"
<context context-type="sourcefile">Navigation Menu</context>
</context-group>
</trans-unit>
+ <trans-unit id="All Scans">
+<source>All Scans</source>
+ <context-group name="ctx">
+ <context context-type="sourcefile">Navigation Menu</context>
+ </context-group>
+ </trans-unit>
<trans-unit id="audit.nav.logreview">
<source>Log Review</source>
<context-group name="ctx">
diff --git a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml
index 3a01190..2283fc2 100644
--- a/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml
+++ b/java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml
@@ -12117,6 +12117,27 @@ the <strong>Red Hat Enterprise Linux System Administration Guide.</stro
</trans-unit>
</group>
+ <group>
+ <context-group name="ctx">
+ <context context-type="sourcefile">Search of OpenSCAP scans</context>
+ </context-group>
+ <trans-unit id="scapsearch.jsp.toolbar">
+ <source>OpenSCAP Search</source>
+ </trans-unit>
+ <trans-unit id="scapsearch.jsp.summary">
+ <source>OpenSCAP Search will return finished OpenSCAP scans from all scans you have access.</source>
+ </trans-unit>
+ <trans-unit id="scapsearch.jsp.instructions">
+ <source>Specify your search criteria below.</source>
+ </trans-unit>
+ <trans-unit id="scapsearch.jsp.searchfor">
+ <source>Search XCCDF Rules For</source>
+ </trans-unit>
+ <trans-unit id="scapsearch.jsp.whatsearch.tip">
+ <source><strong>Examples:</strong> 'no_hashes_outside_shadow', 'CCE-14300-8'</source>
+ </trans-unit>
+ </group>
+
<!-- Action common -->
<group>
<context-group name="ctx">
diff --git a/java/code/src/com/redhat/rhn/manager/audit/ScapManager.java b/java/code/src/com/redhat/rhn/manager/audit/ScapManager.java
index 4eeb25a..caf2f7a 100644
--- a/java/code/src/com/redhat/rhn/manager/audit/ScapManager.java
+++ b/java/code/src/com/redhat/rhn/manager/audit/ScapManager.java
@@ -130,6 +130,21 @@ public class ScapManager extends BaseManager {
}
/**
+ * Get xccdf:rule-results by ident's ids
+ * @param user attempting to view results
+ * @param identIds list of xccdf:ident ids
+ * @return the result
+ */
+ public static List<XccdfRuleResultDto> ruleResultsByIdentIds(User user,
+ List<Long> identIds) {
+ SelectMode m = ModeFactory.getMode("scap_queries",
+ "ruleresults_by_idents");
+ HashMap params = new HashMap();
+ params.put("user_id", user.getId());
+ return m.execute(params, identIds);
+ }
+
+ /**
* Show xccdf:ident results for given rule-result
* @param ruleResultId of XccdfRuleResultDto
* @return the list of idents
diff --git a/java/code/webapp/WEB-INF/nav/sitenav-authenticated.xml b/java/code/webapp/WEB-INF/nav/sitenav-authenticated.xml
index 98148b0..6250800 100644
--- a/java/code/webapp/WEB-INF/nav/sitenav-authenticated.xml
+++ b/java/code/webapp/WEB-INF/nav/sitenav-authenticated.xml
@@ -171,7 +171,10 @@
</rhn-tab>
<rhn-tab name="Audit" url="/rhn/audit/ListXccdf.do">
<rhn-tab-directory>/rhn/audit</rhn-tab-directory>
- <rhn-tab name="OpenSCAP" url="/rhn/audit/ListXccdf.do" />
+ <rhn-tab name="OpenSCAP" url="/rhn/audit/ListXccdf.do">
+ <rhn-tab name="All Scans" url="/rhn/audit/ListXccdf.do"/>
+ <rhn-tab name="Advanced Search" url="/rhn/audit/scap/Search.do"/>
+ </rhn-tab>
<rhn-tab name="audit.nav.logreview" url="/rhn/audit/Overview.do" acl="not is_satellite()">
<rhn-tab name="Overview" url="/rhn/audit/Overview.do" />
<rhn-tab name="Reviews" url="/rhn/audit/Machine.do" />
diff --git a/java/code/webapp/WEB-INF/pages/audit/scap/xccdfsearch.jsp b/java/code/webapp/WEB-INF/pages/audit/scap/xccdfsearch.jsp
new file mode 100644
index 0000000..c48de4b
--- /dev/null
+++ b/java/code/webapp/WEB-INF/pages/audit/scap/xccdfsearch.jsp
@@ -0,0 +1,60 @@
+<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
+<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
+<%@ taglib uri="http://rhn.redhat.com/rhn" prefix="rhn" %>
+<%@ taglib uri="http://rhn.redhat.com/tags/list" prefix="rl" %>
+<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
+
+<html:xhtml/>
+<html>
+<body>
+
+<rhn:toolbar base="h1" img="/img/rhn-icon-search.gif" imgAlt="search.alt.img">
+ <bean:message key="scapsearch.jsp.toolbar"/>
+</rhn:toolbar>
+
+<p><bean:message key="scapsearch.jsp.summary"/></p>
+<p><bean:message key="scapsearch.jsp.instructions"/></p>
+
+<html:form action="/audit/scap/Search.do">
+ <rhn:csrf/>
+ <div class="search-choises">
+ <div class="search-choices-group">
+ <table class="details">
+ <tr><th><bean:message key="scapsearch.jsp.searchfor"/>:</th>
+ <td>
+ <html:text property="search_string" name="search_string"
+ value="${search_string}" maxlength="100" accesskey="4"/>
+ <html:submit>
+ <bean:message key="button.search" />
+ </html:submit>
+ <br/>
+ <span class="small-text">
+ <bean:message key="scapsearch.jsp.whatsearch.tip"/>
+ </span>
+ </td>
+ </tr>
+ </table>
+ </div> <!-- search-choices-group -->
+ </div> <!-- search-choices -->
+ <input type="hidden" name="submitted" value="true"/>
+</html:form>
+
+<c:if test="${(search_string != null && search_string != '')}">
+ <c:set var="pageList" value="${requestScope.pageList}"/>
+ <hr/>
+
+ <rl:listset name="searchSet" legend="xccdf">
+ <rhn:csrf/>
+ <rl:list emptykey="generic.jsp.none" name="searchResults" dataset="pageList">
+ <rl:decorator name="PageSizeDecorator"/>
+ <%@ include file="/WEB-INF/pages/common/fragments/audit/rule-common-columns.jspf" %>
+ </rl:list>
+
+ <!-- there are two forms here, need to keep the formvars around for pagination -->
+ <input type="hidden" name="submitted" value="true"/>
+ <input type="hidden" name="search_string" value="${search_string}"/>
+ </rl:listset>
+</c:if>
+
+</body>
+</html>
diff --git a/java/code/webapp/WEB-INF/pages/common/fragments/audit/rule-common-columns.jspf b/java/code/webapp/WEB-INF/pages/common/fragments/audit/rule-common-columns.jspf
index 12f6623..885580f 100644
--- a/java/code/webapp/WEB-INF/pages/common/fragments/audit/rule-common-columns.jspf
+++ b/java/code/webapp/WEB-INF/pages/common/fragments/audit/rule-common-columns.jspf
@@ -1,6 +1,13 @@
<rl:column headerkey="system.audit.xccdfdetails.jsp.idref" sortattr="documentIdref"
sortable="true" styleclass="first-column">
- <a href="/rhn/systems/details/audit/RuleDetails.do?sid=${param.sid}&rrid=${current.id}">
+ <c:choose>
+ <c:when test="${not empty param.sid}">
+ <a href="/rhn/systems/details/audit/RuleDetails.do?sid=${param.sid}&rrid=${current.id}">
+ </c:when>
+ <c:otherwise>
+ <a href="/rhn/systems/details/audit/RuleDetails.do?sid=${current.testResult.server.id}&rrid=${current.id}">
+ </c:otherwise>
+ </c:choose>
<c:choose>
<c:when test="${empty current.documentIdref}">
<bean:message key="system.audit.xccdfdetails.jsp.unknown"/>
diff --git a/java/code/webapp/WEB-INF/struts-config.xml b/java/code/webapp/WEB-INF/struts-config.xml
index 204f81e..0fb7027 100644
--- a/java/code/webapp/WEB-INF/struts-config.xml
+++ b/java/code/webapp/WEB-INF/struts-config.xml
@@ -233,6 +233,11 @@
<form-property name="end_minute" type="java.lang.Integer" />
<form-property name="end_am_pm" type="java.lang.Integer" />
</form-bean>
+ <form-bean name="xccdfSearchForm"
+ type="com.redhat.rhn.frontend.struts.ScrubbingDynaActionForm">
+ <form-property name="search_string" type="java.lang.String"/>
+ <form-property name="submitted" type="java.lang.Boolean" />
+ </form-bean>
<form-bean name="errataSearchForm"
type="com.redhat.rhn.frontend.struts.ScrubbingDynaActionForm">
<form-property name="search_string" type="java.lang.String"/>
@@ -1937,6 +1942,15 @@
<forward name="default" path="/WEB-INF/pages/audit/listxccdf.jsp"/>
</action>
+ <action path="/audit/scap/Search"
+ name="xccdfSearchForm"
+ scope="request"
+ input="/WEB-INF/pages/audit/scap/xccdfsearch.jsp"
+ type="com.redhat.rhn.frontend.action.audit.scap.XccdfSearchAction">
+ <forward name="default" path="/WEB-INF/pages/audit/scap/xccdfsearch.jsp"/>
+ <forward name="success" path="/audit/scap/Search.do" redirect="true" />
+ </action>
+
<!-- ===== ERRATA ===== -->
<action path="/errata/Search"
name="errataSearchForm"
diff --git a/web/html/nav/sitenav-authenticated.xml b/web/html/nav/sitenav-authenticated.xml
index 31ff60d..f2ae908 100644
--- a/web/html/nav/sitenav-authenticated.xml
+++ b/web/html/nav/sitenav-authenticated.xml
@@ -121,7 +121,10 @@
</rhn-tab>
<rhn-tab name="Audit" url="/rhn/audit/ListXccdf.do">
<rhn-tab-directory>/rhn/audit</rhn-tab-directory>
- <rhn-tab name="OpenSCAP" url="/rhn/audit/ListXccdf.do" />
+ <rhn-tab name="OpenSCAP" url="/rhn/audit/ListXccdf.do">
+ <rhn-tab name="All Scans" url="/rhn/audit/ListXccdf.do"/>
+ <rhn-tab name="Advanced Search" url="/rhn/audit/scap/Search.do"/>
+ </rhn-tab>
<rhn-tab name="audit.nav.logreview" url="/rhn/audit/Overview.do" acl="not is_satellite()">
<rhn-tab name="Overview" url="/rhn/audit/Overview.do" />
<rhn-tab name="Reviews" url="/rhn/audit/Machine.do" />
commit e4bc48112bda523334060a3f0858157c9b9a594e
Author: Simon Lukasik <slukasik(a)redhat.com>
Date: Mon May 21 14:59:48 2012 +0200
Start indexing XCCDF idents.
diff --git a/search-server/spacewalk-search/scripts/Reindex.groovy b/search-server/spacewalk-search/scripts/Reindex.groovy
index 49e94e0..61c429f 100644
--- a/search-server/spacewalk-search/scripts/Reindex.groovy
+++ b/search-server/spacewalk-search/scripts/Reindex.groovy
@@ -21,7 +21,8 @@ def deleteQuery(config, queryName) {
Configuration config = new Configuration()
deleteQueries = ["deleteLastErrata", "deleteLastPackage",
"deleteLastServer", "deleteLastHardwareDevice",
- "deleteLastSnapshotTag", "deleteLastServerCustomInfo"]
+ "deleteLastSnapshotTag", "deleteLastServerCustomInfo",
+ "deleteLastXccdfIdent"]
deleteQueries.each{deleteQuery(config, it)}
println "Database has been prepared so we can re-index."
@@ -31,7 +32,8 @@ println "Previous indexes will be deleted on filesystem under ${indexWorkDir}"
dirs = [indexWorkDir+"/package", indexWorkDir+"/errata",
indexWorkDir+"/server", indexWorkDir+"/hwdevice",
- indexWorkDir+"/snapshotTag", indexWorkDir+"/serverCustomInfo"]
+ indexWorkDir+"/snapshotTag", indexWorkDir+"/serverCustomInfo",
+ indexWorkDir+"/xccdfIdent"]
dirs.each {
cmd = "rm -r $it"
def proc = cmd.execute()
diff --git a/search-server/spacewalk-search/src/config/com/redhat/satellite/search/db/config.xml b/search-server/spacewalk-search/src/config/com/redhat/satellite/search/db/config.xml
index 4fb411b..655d953 100644
--- a/search-server/spacewalk-search/src/config/com/redhat/satellite/search/db/config.xml
+++ b/search-server/spacewalk-search/src/config/com/redhat/satellite/search/db/config.xml
@@ -35,4 +35,5 @@
<sqlMap resource="com/redhat/satellite/search/db/hwdevice.xml" />
<sqlMap resource="com/redhat/satellite/search/db/snapshot_tag.xml" />
<sqlMap resource="com/redhat/satellite/search/db/server_custom_info.xml" />
+ <sqlMap resource="com/redhat/satellite/search/db/xccdf_ident.xml" />
</sqlMapConfig>
diff --git a/search-server/spacewalk-search/src/config/com/redhat/satellite/search/db/xccdf_ident.xml b/search-server/spacewalk-search/src/config/com/redhat/satellite/search/db/xccdf_ident.xml
new file mode 100644
index 0000000..ab060a6
--- /dev/null
+++ b/search-server/spacewalk-search/src/config/com/redhat/satellite/search/db/xccdf_ident.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!DOCTYPE sqlMap
+ PUBLIC "-//ibatis.apache.org//DTD SQL Map 2.0//EN"
+ "http://ibatis.apache.org/dtd/sql-map-2.dtd">
+
+<sqlMap namespace="xccdfIdent">
+ <select id="getXccdfIdentById" parameterClass="java.util.Map"
+ resultClass="com.redhat.satellite.search.db.models.XccdfIdent">
+ SELECT id, identifier
+ FROM rhnXccdfIdent
+ WHERE id > #id#
+ ORDER BY id ASC
+ </select>
+ <select id="queryAllXccdfIdentIds" resultClass="Long">
+ SELECT id
+ FROM rhnXccdfIdent
+ </select>
+
+ <insert id="createLastXccdfIdent" parameterClass="java.util.Map">
+ INSERT INTO rhnIndexerWork
+ VALUES ('xccdf_ident', #id#, #last_modified#)
+ </insert>
+ <select id="getLastXccdfIdentId" resultClass="java.lang.Long">
+ SELECT last_id
+ FROM rhnIndexerWork
+ WHERE object_type='xccdf_ident'
+ </select>
+ <select id="getLastXccdfIdentIndexRun" resultClass="java.util.Date">
+ SELECT last_modified
+ FROM rhnIndexerWork
+ WHERE object_type='xccdf_ident'
+ </select>
+ <update id="updateLastXccdfIdent" parameterClass="java.util.Map">
+ UPDATE rhnIndexerWork
+ SET last_id = #id#, last_modified = #last_modified#
+ WHERE object_type = 'xccdf_ident'
+ </update>
+ <delete id="deleteLastXccdfIdent">
+ DELETE FROM rhnIndexerWork
+ WHERE object_type = 'xccdf_ident'
+ </delete>
+</sqlMap>
diff --git a/search-server/spacewalk-search/src/java/com/redhat/satellite/search/DeleteIndexes.java b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/DeleteIndexes.java
index bcc2e89..c6fd0af 100644
--- a/search-server/spacewalk-search/src/java/com/redhat/satellite/search/DeleteIndexes.java
+++ b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/DeleteIndexes.java
@@ -114,6 +114,8 @@ public class DeleteIndexes {
indexWorkDir + File.separator + "snapshotTag"));
indexes.add(new IndexInfo("deleteLastServerCustomInfo",
indexWorkDir + File.separator + "serverCustomInfo"));
+ indexes.add(new IndexInfo("deleteLastXccdfIdent",
+ indexWorkDir + File.separator + "xccdfIdent"));
for (IndexInfo info : indexes) {
deleteQuery(databaseManager, info.getQueryName());
if (!deleteIndexPath(info.getDirPath())) {
diff --git a/search-server/spacewalk-search/src/java/com/redhat/satellite/search/db/models/XccdfIdent.java b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/db/models/XccdfIdent.java
new file mode 100644
index 0000000..61f1c51
--- /dev/null
+++ b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/db/models/XccdfIdent.java
@@ -0,0 +1,38 @@
+/**
+ * Copyright (c) 2012 Red Hat, Inc.
+ *
+ * This software is licensed to you under the GNU General Public License,
+ * version 2 (GPLv2). There is NO WARRANTY for this software, express or
+ * implied, including the implied warranties of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+ * along with this software; if not, see
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ * Red Hat trademarks are not licensed under GPLv2. No permission is
+ * granted to use or replicate Red Hat trademarks that are incorporated
+ * in this software or its documentation.
+ */
+package com.redhat.satellite.search.db.models;
+
+/**
+ * XccdfIdent
+ * @version $Rev$
+ */
+public class XccdfIdent extends GenericRecord {
+
+ private String identifier;
+
+ /**
+ * @return the xccdf:identifier
+ */
+ public String getIdentifier() {
+ return identifier;
+ }
+
+ /**
+ * @param identifierIn the identifier to set
+ */
+ public void setIdentifier(String identifierIn) {
+ this.identifier = identifierIn;
+ }
+}
diff --git a/search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/IndexManager.java b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/IndexManager.java
index 9f9667c..70ede4d 100644
--- a/search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/IndexManager.java
+++ b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/IndexManager.java
@@ -499,6 +499,12 @@ public class IndexManager {
else if (indexName.compareTo(BuilderFactory.SERVER_CUSTOM_INFO_TYPE) == 0) {
pr = new ServerCustomInfoResult(x, hits.score(x), doc);
}
+ else if (indexName.compareTo(BuilderFactory.XCCDF_IDENT_TYPE) == 0) {
+ pr = new Result(x,
+ doc.getField("id").stringValue(),
+ doc.getField("identifier").stringValue(),
+ hits.score(x));
+ }
else {
pr = new Result(x,
doc.getField("id").stringValue(),
diff --git a/search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/builder/BuilderFactory.java b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/builder/BuilderFactory.java
index 2d6971a..0730049 100644
--- a/search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/builder/BuilderFactory.java
+++ b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/builder/BuilderFactory.java
@@ -28,6 +28,7 @@ public class BuilderFactory {
public static final String HARDWARE_DEVICE_TYPE = "hwdevice";
public static final String SNAPSHOT_TAG_TYPE = "snapshotTag";
public static final String SERVER_CUSTOM_INFO_TYPE = "serverCustomInfo";
+ public static final String XCCDF_IDENT_TYPE = "xccdfIdent";
/**
* Private constructor.
*/
@@ -59,6 +60,9 @@ public class BuilderFactory {
else if (SERVER_CUSTOM_INFO_TYPE.equals(type)) {
return new ServerCustomInfoDocumentBuilder();
}
+ else if (XCCDF_IDENT_TYPE.equals(type)) {
+ return new XccdfIdentDocumentBuilder();
+ }
else {
throw new UnsupportedOperationException(type +
" is an unsuppported type");
diff --git a/search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/builder/XccdfIdentDocumentBuilder.java b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/builder/XccdfIdentDocumentBuilder.java
new file mode 100644
index 0000000..461e475
--- /dev/null
+++ b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/index/builder/XccdfIdentDocumentBuilder.java
@@ -0,0 +1,51 @@
+/**
+ * Copyright (c) 2012 Red Hat, Inc.
+ *
+ * This software is licensed to you under the GNU General Public License,
+ * version 2 (GPLv2). There is NO WARRANTY for this software, express or
+ * implied, including the implied warranties of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+ * along with this software; if not, see
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ * Red Hat trademarks are not licensed under GPLv2. No permission is
+ * granted to use or replicate Red Hat trademarks that are incorporated
+ * in this software or its documentation.
+ */
+package com.redhat.satellite.search.index.builder;
+
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+
+import java.util.Iterator;
+import java.util.Map;
+
+
+/**
+ * XccdfIdentDocumentBuilder
+ * @version $Rev$
+ */
+public class XccdfIdentDocumentBuilder implements DocumentBuilder {
+
+ /**
+ * {@inheritDoc}
+ */
+ public Document buildDocument(Long objId, Map<String, String> metadata) {
+ Document doc = new Document();
+ doc.add(new Field("id", objId.toString(), Field.Store.YES,
+ Field.Index.UN_TOKENIZED));
+
+ for (Iterator<String> iter = metadata.keySet().iterator(); iter.hasNext();) {
+ Field.Store store = Field.Store.YES;
+ Field.Index tokenize = Field.Index.TOKENIZED;
+
+ String name = iter.next();
+ String value = metadata.get(name);
+
+ doc.add(new Field(name, String.valueOf(value), store,
+ tokenize));
+ }
+ return doc;
+ }
+
+}
diff --git a/search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/ScheduleManager.java b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/ScheduleManager.java
index 4e016e7..2413424 100644
--- a/search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/ScheduleManager.java
+++ b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/ScheduleManager.java
@@ -25,6 +25,7 @@ import com.redhat.satellite.search.scheduler.tasks.IndexSnapshotTagsTask;
import com.redhat.satellite.search.scheduler.tasks.IndexServerCustomInfoTask;
import com.redhat.satellite.search.scheduler.tasks.IndexSystemsTask;
import com.redhat.satellite.search.scheduler.tasks.IndexHardwareDevicesTask;
+import com.redhat.satellite.search.scheduler.tasks.IndexXccdfIdentTask;
import org.apache.log4j.Logger;
@@ -132,6 +133,10 @@ public class ScheduleManager implements Startable {
mode, interval,
IndexServerCustomInfoTask.class, jobData);
+ scheduleJob(scheduler, BuilderFactory.XCCDF_IDENT_TYPE,
+ mode, interval,
+ IndexXccdfIdentTask.class, jobData);
+
scheduler.start();
}
catch (SchedulerException e) {
@@ -157,7 +162,8 @@ public class ScheduleManager implements Startable {
BuilderFactory.PACKAGES_TYPE.equals(indexName) ||
BuilderFactory.SERVER_CUSTOM_INFO_TYPE.equals(indexName) ||
BuilderFactory.SERVER_TYPE.equals(indexName) ||
- BuilderFactory.SNAPSHOT_TAG_TYPE.equals(indexName)) {
+ BuilderFactory.SNAPSHOT_TAG_TYPE.equals(indexName) ||
+ BuilderFactory.XCCDF_IDENT_TYPE.equals(indexName)) {
return true;
}
else if (BuilderFactory.DOCS_TYPE.equals(indexName)) {
diff --git a/search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/tasks/IndexXccdfIdentTask.java b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/tasks/IndexXccdfIdentTask.java
new file mode 100644
index 0000000..5490ebf
--- /dev/null
+++ b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/tasks/IndexXccdfIdentTask.java
@@ -0,0 +1,107 @@
+/**
+ * Copyright (c) 2012 Red Hat, Inc.
+ *
+ * This software is licensed to you under the GNU General Public License,
+ * version 2 (GPLv2). There is NO WARRANTY for this software, express or
+ * implied, including the implied warranties of MERCHANTABILITY or FITNESS
+ * FOR A PARTICULAR PURPOSE. You should have received a copy of GPLv2
+ * along with this software; if not, see
+ * http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt.
+ *
+ * Red Hat trademarks are not licensed under GPLv2. No permission is
+ * granted to use or replicate Red Hat trademarks that are incorporated
+ * in this software or its documentation.
+ */
+package com.redhat.satellite.search.scheduler.tasks;
+
+import com.redhat.satellite.search.db.models.GenericRecord;
+import com.redhat.satellite.search.db.models.XccdfIdent;
+import com.redhat.satellite.search.index.builder.BuilderFactory;
+
+import org.apache.log4j.Logger;
+
+import java.util.HashMap;
+import java.util.Map;
+
+/**
+ * IndexXccdfIdentTask
+ * @version $Rev$
+ */
+public class IndexXccdfIdentTask extends GenericIndexTask {
+
+ private static Logger log = Logger.getLogger(IndexXccdfIdentTask.class);
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected Map<String, String> getFieldMap(GenericRecord data)
+ throws ClassCastException {
+ XccdfIdent dev = (XccdfIdent)data;
+ Map<String, String> attrs = new HashMap<String, String>();
+ attrs.put("id", new Long(dev.getId()).toString());
+ attrs.put("identifier", dev.getIdentifier());
+ return attrs;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public String getIndexName() {
+ return BuilderFactory.XCCDF_IDENT_TYPE;
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected String getQueryCreateLastRecord() {
+ return "createLastXccdfIdent";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected String getQueryLastRecord() {
+ return "getLastXccdfIdentId";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected String getQueryLastIndexDate() {
+ return "getLastXccdfIdentIndexRun";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected String getQueryRecordsToIndex() {
+ return "getXccdfIdentById";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ protected String getQueryUpdateLastRecord() {
+ return "updateLastXccdfIdent";
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ public String getUniqueFieldId() {
+ return "id";
+ }
+ /**
+ * {@inheritDoc}
+ */
+ public String getQueryAllIds() {
+ return "queryAllXccdfIdentIds";
+ }
+}
diff --git a/search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/tests/ScheduleManagerTest.java b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/tests/ScheduleManagerTest.java
index 382c3c7..46788fd 100644
--- a/search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/tests/ScheduleManagerTest.java
+++ b/search-server/spacewalk-search/src/java/com/redhat/satellite/search/scheduler/tests/ScheduleManagerTest.java
@@ -40,6 +40,7 @@ public class ScheduleManagerTest extends BaseTestCase {
assertTrue(sm.triggerIndexTask(BuilderFactory.SERVER_CUSTOM_INFO_TYPE));
assertTrue(sm.triggerIndexTask(BuilderFactory.SERVER_TYPE));
assertTrue(sm.triggerIndexTask(BuilderFactory.SNAPSHOT_TAG_TYPE));
+ assertTrue(sm.triggerIndexTask(BuilderFactory.XCCDF_IDENT_TYPE));
assertFalse(sm.triggerIndexTask(BuilderFactory.DOCS_TYPE));
assertFalse(sm.triggerIndexTask(null));
assertFalse(sm.triggerIndexTask("biteme"));
commit 723009c9d821a5642b28e7dac6ed0962a7f4ea9c
Author: Simon Lukasik <slukasik(a)redhat.com>
Date: Tue May 22 16:58:23 2012 +0200
Promote some of the rule's columns to fragment.
diff --git a/java/code/webapp/WEB-INF/pages/common/fragments/audit/rule-common-columns.jspf b/java/code/webapp/WEB-INF/pages/common/fragments/audit/rule-common-columns.jspf
new file mode 100644
index 0000000..12f6623
--- /dev/null
+++ b/java/code/webapp/WEB-INF/pages/common/fragments/audit/rule-common-columns.jspf
@@ -0,0 +1,21 @@
+<rl:column headerkey="system.audit.xccdfdetails.jsp.idref" sortattr="documentIdref"
+ sortable="true" styleclass="first-column">
+ <a href="/rhn/systems/details/audit/RuleDetails.do?sid=${param.sid}&rrid=${current.id}">
+ <c:choose>
+ <c:when test="${empty current.documentIdref}">
+ <bean:message key="system.audit.xccdfdetails.jsp.unknown"/>
+ </c:when>
+ <c:otherwise>
+ <c:out value="${current.documentIdref}"/>
+ </c:otherwise>
+ </c:choose>
+ </a>
+</rl:column>
+
+<rl:column headerkey="system.audit.xccdfdetails.jsp.idents" sortattr="identsString" sortable="true">
+ <c:out value="${current.identsString}"/>
+</rl:column>
+
+<rl:column headerkey="system.audit.xccdfdetails.jsp.result" sortattr="label" sortable="true" filterattr="label">
+ <c:out value="${current.label}"/>
+</rl:column>
diff --git a/java/code/webapp/WEB-INF/pages/systems/details/audit/xccdfdetails.jsp b/java/code/webapp/WEB-INF/pages/systems/details/audit/xccdfdetails.jsp
index cb489a3..e03d7d3 100644
--- a/java/code/webapp/WEB-INF/pages/systems/details/audit/xccdfdetails.jsp
+++ b/java/code/webapp/WEB-INF/pages/systems/details/audit/xccdfdetails.jsp
@@ -56,26 +56,8 @@
<rl:list>
<rl:decorator name="PageSizeDecorator"/>
- <rl:column headerkey="system.audit.xccdfdetails.jsp.idref" sortattr="documentIdref"
- sortable="true" styleclass="first-column">
- <a href="/rhn/systems/details/audit/RuleDetails.do?sid=${param.sid}&rrid=${current.id}">
- <c:choose>
- <c:when test="${empty current.documentIdref}">
- <bean:message key="system.audit.xccdfdetails.jsp.unknown"/>
- </c:when>
- <c:otherwise>
- <c:out value="${current.documentIdref}"/>
- </c:otherwise>
- </c:choose>
- </a>
+ <%@ include file="/WEB-INF/pages/common/fragments/audit/rule-common-columns.jspf" %>
- </rl:column>
- <rl:column headerkey="system.audit.xccdfdetails.jsp.idents" sortattr="identsString" sortable="true">
- <c:out value="${current.identsString}"/>
- </rl:column>
- <rl:column headerkey="system.audit.xccdfdetails.jsp.result" sortattr="label" sortable="true" filterattr="label">
- <c:out value="${current.label}"/>
- </rl:column>
</rl:list>
</rl:listset>
11 years, 11 months
spacewalk/setup
by Milan Zazrivec
spacewalk/setup/share/jabberd/c2s.xsl | 27 ---------------------------
spacewalk/setup/share/jabberd/s2s.xsl | 34 ----------------------------------
spacewalk/setup/share/jabberd/sm.xsl | 17 -----------------
3 files changed, 78 deletions(-)
New commits:
commit 8f81743d290e918ebdda475a9c1c7534fe6673e2
Author: Milan Zazrivec <mzazrivec(a)redhat.com>
Date: Tue May 29 11:49:12 2012 +0200
get rid of jabberd xsl templates in spacewalk-setup
xsl templates for jabberd configuration have been moved over to a new
package: spacewalk-setup-jabberd
diff --git a/spacewalk/setup/share/jabberd/c2s.xsl b/spacewalk/setup/share/jabberd/c2s.xsl
deleted file mode 100644
index 9c5a0e7..0000000
--- a/spacewalk/setup/share/jabberd/c2s.xsl
+++ /dev/null
@@ -1,27 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
-
-<xsl:template match="@*|node()">
- <xsl:copy>
- <xsl:apply-templates select="@*|node()"/>
- </xsl:copy>
-</xsl:template>
-
-<xsl:template match="/c2s/local/id">
- <xsl:copy>
- <xsl:attribute name="require-starttls">false</xsl:attribute>
- <xsl:attribute name="pemfile">/etc/pki/spacewalk/jabberd/server.pem</xsl:attribute>
- <xsl:attribute name="realm"></xsl:attribute>
- <xsl:attribute name="register-enable">true</xsl:attribute>
- <xsl:text>@hostname@</xsl:text>
- </xsl:copy>
-</xsl:template>
-
-<xsl:template match="/c2s/authreg/module">
- <xsl:copy>
- <xsl:text>db</xsl:text>
- </xsl:copy>
-</xsl:template>
-
-</xsl:stylesheet>
diff --git a/spacewalk/setup/share/jabberd/s2s.xsl b/spacewalk/setup/share/jabberd/s2s.xsl
deleted file mode 100644
index 95459c5..0000000
--- a/spacewalk/setup/share/jabberd/s2s.xsl
+++ /dev/null
@@ -1,34 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
-
-<xsl:template match="@*|node()">
- <xsl:copy>
- <xsl:apply-templates select="@*|node()"/>
- </xsl:copy>
-</xsl:template>
-
-<xsl:template match="/s2s/local">
- <xsl:copy>
- <xsl:if test="not(resolver)">
- <xsl:text>
- </xsl:text>
- <xsl:comment>
- Helper DNS resolver component - if this component is not
- connected, dialback connections will fail
- (default: resolver) </xsl:comment>
- <xsl:text>
- </xsl:text>
- <resolver>resolver</resolver>
- <xsl:text>
- </xsl:text>
- </xsl:if>
- <xsl:apply-templates select="@*|node()" />
- </xsl:copy>
-</xsl:template>
-
-<xsl:template match="/s2s/check/interval">
- <xsl:copy>3</xsl:copy>
-</xsl:template>
-
-</xsl:stylesheet>
diff --git a/spacewalk/setup/share/jabberd/sm.xsl b/spacewalk/setup/share/jabberd/sm.xsl
deleted file mode 100644
index 83ce864..0000000
--- a/spacewalk/setup/share/jabberd/sm.xsl
+++ /dev/null
@@ -1,17 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
-<xsl:output method="xml" indent="yes" omit-xml-declaration="yes" />
-
-<xsl:template match="@*|node()">
- <xsl:copy>
- <xsl:apply-templates select="@*|node()"/>
- </xsl:copy>
-</xsl:template>
-
-<xsl:template match="/sm/id">
- <xsl:copy>
- <xsl:text>@hostname@</xsl:text>
- </xsl:copy>
-</xsl:template>
-
-</xsl:stylesheet>
11 years, 11 months
Changes to 'refs/tags/spacewalk-java-1.8.76-1'
by Tomas Lestach
Tag 'spacewalk-java-1.8.76-1' created by Tomas Lestach <tlestach(a)redhat.com> at 2012-05-29 08:40 +0000
Tagging package [spacewalk-java] version [1.8.76-1] in directory [java/].
Changes since spacewalk-schema-1.8.42-1:
Jan Pazdziora (1):
Disable web_customer_mod_trig while updating web_customer, so that modified does not get modified.
Marcelo Moreira de Mello (1):
Enhancements pt_BR localization at webUI
Tomas Lestach (2):
814659 - add an extra entitlement check before the key creation
Automatic commit of package [spacewalk-java] release [1.8.76-1].
---
java/code/src/com/redhat/rhn/frontend/action/token/ActivationKeyDetailsAction.java | 7
java/code/src/com/redhat/rhn/frontend/strings/java/StringResource_pt_BR.xml | 6
java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_pt_BR.xml | 74 +++++-----
java/code/src/com/redhat/rhn/frontend/strings/nav/StringResource_pt_BR.xml | 10 -
java/spacewalk-java.spec | 6
rel-eng/packages/spacewalk-java | 2
schema/spacewalk/upgrade/spacewalk-schema-1.0-to-spacewalk-schema-1.1/022-web_customer.sql | 4
7 files changed, 59 insertions(+), 50 deletions(-)
---
11 years, 11 months
java/spacewalk-java.spec rel-eng/packages
by Tomas Lestach
java/spacewalk-java.spec | 6 +++++-
rel-eng/packages/spacewalk-java | 2 +-
2 files changed, 6 insertions(+), 2 deletions(-)
New commits:
commit b9721ddf72b37ba0f79a2c1f3d3a8171a1a6dbfe
Author: Tomas Lestach <tlestach(a)redhat.com>
Date: Tue May 29 10:40:44 2012 +0200
Automatic commit of package [spacewalk-java] release [1.8.76-1].
diff --git a/java/spacewalk-java.spec b/java/spacewalk-java.spec
index ecda104..ab6386c 100644
--- a/java/spacewalk-java.spec
+++ b/java/spacewalk-java.spec
@@ -22,7 +22,7 @@ Name: spacewalk-java
Summary: Spacewalk Java site packages
Group: Applications/Internet
License: GPLv2
-Version: 1.8.75
+Version: 1.8.76
Release: 1%{?dist}
URL: https://fedorahosted.org/spacewalk
Source0: https://fedorahosted.org/releases/s/p/spacewalk/%{name}-%{version}.tar.gz
@@ -605,6 +605,10 @@ fi
%{jardir}/postgresql-jdbc.jar
%changelog
+* Tue May 29 2012 Tomas Lestach <tlestach(a)redhat.com> 1.8.76-1
+- 814659 - add an extra entitlement check before the key creation
+- Enhancements pt_BR localization at webUI
+
* Fri May 25 2012 Tomas Lestach <tlestach(a)redhat.com> 1.8.75-1
- store also config revision changed_by_id
- fix ConfigurationFactoryTest.testRemoveConfigChannel
diff --git a/rel-eng/packages/spacewalk-java b/rel-eng/packages/spacewalk-java
index 3581371..90364b3 100644
--- a/rel-eng/packages/spacewalk-java
+++ b/rel-eng/packages/spacewalk-java
@@ -1 +1 @@
-1.8.75-1 java/
+1.8.76-1 java/
11 years, 11 months
java/code
by Tomas Lestach
java/code/src/com/redhat/rhn/frontend/action/token/ActivationKeyDetailsAction.java | 7 +++++--
1 file changed, 5 insertions(+), 2 deletions(-)
New commits:
commit c433e664d89fede154400dc0fbffc79702f57f01
Author: Tomas Lestach <tlestach(a)redhat.com>
Date: Tue May 29 10:37:43 2012 +0200
814659 - add an extra entitlement check before the key creation
diff --git a/java/code/src/com/redhat/rhn/frontend/action/token/ActivationKeyDetailsAction.java b/java/code/src/com/redhat/rhn/frontend/action/token/ActivationKeyDetailsAction.java
index a230ff1..7ced127 100644
--- a/java/code/src/com/redhat/rhn/frontend/action/token/ActivationKeyDetailsAction.java
+++ b/java/code/src/com/redhat/rhn/frontend/action/token/ActivationKeyDetailsAction.java
@@ -317,15 +317,18 @@ public class ActivationKeyDetailsAction extends RhnAction {
usageLimit = Long.valueOf(daForm.getString(USAGE_LIMIT));
}
+ List<String> selected = Arrays.asList((String[])daForm.get(SELECTED_ENTS));
+ manager.validateAddOnEntitlements(selected, true);
+
ActivationKey key = manager.createNewActivationKey(user,
daForm.getString(KEY),
daForm.getString(DESCRIPTION),
usageLimit,
lookupChannel(daForm, user),
Boolean.TRUE.equals(daForm.get(ORG_DEFAULT)));
- String[] selected = (String[])daForm.get(SELECTED_ENTS);
+
if (selected != null) {
- manager.addEntitlements(key, Arrays.asList(selected));
+ manager.addEntitlements(key, selected);
}
ActionMessages msg = new ActionMessages();
addToMessage(msg, "activation-key.java.created", key.getNote());
11 years, 11 months
schema/spacewalk
by Jan Pazdziora
schema/spacewalk/upgrade/spacewalk-schema-1.0-to-spacewalk-schema-1.1/022-web_customer.sql | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
New commits:
commit 07f6c961ab258ba600ed7d5100b070c8dd6cdae1
Author: Jan Pazdziora <jpazdziora(a)redhat.com>
Date: Mon May 28 16:42:51 2012 +0200
Disable web_customer_mod_trig while updating web_customer, so that modified does not get modified.
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.0-to-spacewalk-schema-1.1/022-web_customer.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.0-to-spacewalk-schema-1.1/022-web_customer.sql
index e8a6e85..02f37f8 100644
--- a/schema/spacewalk/upgrade/spacewalk-schema-1.0-to-spacewalk-schema-1.1/022-web_customer.sql
+++ b/schema/spacewalk/upgrade/spacewalk-schema-1.0-to-spacewalk-schema-1.1/022-web_customer.sql
@@ -1,5 +1,5 @@
--
--- Copyright (c) 2008--2010 Red Hat, Inc.
+-- Copyright (c) 2008--2012 Red Hat, Inc.
--
-- This software is licensed to you under the GNU General Public License,
-- version 2 (GPLv2). There is NO WARRANTY for this software, express or
@@ -15,11 +15,13 @@
--
--
+alter trigger web_customer_mod_trig disable;
alter table web_customer add
staging_content_enabled CHAR(1)
DEFAULT ('N') NOT NULL
CONSTRAINT web_customer_stage_content_chk
CHECK (staging_content_enabled in ( 'Y' , 'N' ));
+alter trigger web_customer_mod_trig enable;
alter table web_customer drop column oracle_customer_id;
alter table web_customer drop column oracle_customer_number;
11 years, 11 months