backend/satellite_tools/exporter/exportLib.py | 1 backend/server/handlers/xmlrpc/errata.py | 1 backend/server/handlers/xmlrpc/registration.py | 2 backend/server/importlib/backendOracle.py | 3 backend/server/importlib/channelImport.py | 1 backend/server/rhnChannel.py | 195 - java/code/src/com/redhat/rhn/common/db/datasource/xml/Channel_queries.xml | 6 java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java | 41 java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml | 43 java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.java | 57 java/code/src/com/redhat/rhn/frontend/action/channel/manage/DistChannelMapDeleteAction.java | 63 java/code/src/com/redhat/rhn/frontend/action/channel/manage/DistChannelMapEditAction.java | 153 + java/code/src/com/redhat/rhn/frontend/action/channel/manage/DistChannelMapSetupAction.java | 3 java/code/src/com/redhat/rhn/frontend/action/channel/manage/validation/distChannelMapForm.xsd | 21 java/code/src/com/redhat/rhn/frontend/strings/jsp/StringResource_en_US.xml | 63 java/code/src/com/redhat/rhn/frontend/xmlrpc/distchannel/DistChannelHandler.java | 132 - java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/DistChannelMapSerializer.java | 4 java/code/webapp/WEB-INF/nav/sitenav-authenticated.xml | 4 java/code/webapp/WEB-INF/pages/channel/manage/distchannelmap.jsp | 32 java/code/webapp/WEB-INF/pages/channel/manage/distchannelmapdelete.jsp | 69 java/code/webapp/WEB-INF/pages/channel/manage/distchannelmapedit.jsp | 109 java/code/webapp/WEB-INF/struts-config.xml | 40 rel-eng/packages/spacewalk-schema | 2 schema/spacewalk/common/tables/rhnDistChannelMap.sql | 14 schema/spacewalk/common/views/rhnOrgDistChannelMap.sql | 45 schema/spacewalk/oracle/packages/rhn_channel.pkb | 16 schema/spacewalk/postgres/packages/rhn_channel.pkb | 34 schema/spacewalk/spacewalk-schema.spec | 9 schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/145-rhnDistChannelMap.sql.oracle | 11 schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/145-rhnDistChannelMap.sql.postgresql | 13 schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/146-rhnDistChannelMap-data.sql | 1 schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/147-rhnOrgDistChannelMap.sql | 45 schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/148-rhnOrgDistChannelMap-trigger.sql.oracle | 10 schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/148-rhnOrgDistChannelMap-trigger.sql.postgresql | 17 schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/149-rhn_channel.pkb.sql.oracle | 1205 ++++++++++ schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/149-rhn_channel.pkb.sql.postgresql | 121 + 36 files changed, 2346 insertions(+), 240 deletions(-)
New commits: commit 9c70fb525d2430c7a9e4669133c1fc68faf7f678 Author: Tomas Lestach tlestach@redhat.com Date: Tue Oct 30 15:09:31 2012 +0100
Automatic commit of package [spacewalk-schema] release [1.8.84-1].
diff --git a/rel-eng/packages/spacewalk-schema b/rel-eng/packages/spacewalk-schema index 6cc1084..4abeb86 100644 --- a/rel-eng/packages/spacewalk-schema +++ b/rel-eng/packages/spacewalk-schema @@ -1 +1 @@ -1.8.83-1 schema/spacewalk/ +1.8.84-1 schema/spacewalk/ diff --git a/schema/spacewalk/spacewalk-schema.spec b/schema/spacewalk/spacewalk-schema.spec index 8e995f3..40fb0fa 100644 --- a/schema/spacewalk/spacewalk-schema.spec +++ b/schema/spacewalk/spacewalk-schema.spec @@ -2,7 +2,7 @@ Name: spacewalk-schema Group: Applications/Internet Summary: Oracle SQL schema for Spacewalk server
-Version: 1.8.83 +Version: 1.8.84 Release: 1%{?dist} Source0: %{name}-%{version}.tar.gz
@@ -68,6 +68,13 @@ rm -rf $RPM_BUILD_ROOT %{_mandir}/man1/spacewalk-sql*
%changelog +* Tue Oct 30 2012 Tomas Lestach tlestach@redhat.com 1.8.84-1 +- channel permission shall be guaranteed by the rhnOrgDistChannelMap +- update rhn_channel package to use rhnOrgDistChannelMap +- introduce rhnOrgDistChannelMap +- create rhnDistChannelMap triggers to auto fill in id +- add id and org_id to rhnDistChannelMap + * Tue Oct 30 2012 Jan Pazdziora 1.8.83-1 - Adding the RPM-GPG-KEY-spacewalk-2012 key id. - Update the copyright year.
commit fd9f964330c368298ce647a7884ce1e02e021c81 Author: Tomas Lestach tlestach@redhat.com Date: Tue Oct 30 14:43:11 2012 +0100
channel permission shall be guaranteed by the rhnOrgDistChannelMap
removing rhnChannelPermissions join to make working registration with username and password to a shared channel from a different org using dist channel map
diff --git a/schema/spacewalk/oracle/packages/rhn_channel.pkb b/schema/spacewalk/oracle/packages/rhn_channel.pkb index 954bf4a..e44c9e0 100644 --- a/schema/spacewalk/oracle/packages/rhn_channel.pkb +++ b/schema/spacewalk/oracle/packages/rhn_channel.pkb @@ -28,11 +28,8 @@ IS select distinct c.* from rhnOrgDistChannelMap odcm, 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 + rhnChannel c + where c.parent_channel is null and c.id = odcm.channel_id and c.channel_arch_id = odcm.channel_arch_id and odcm.release = release_in diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pkb b/schema/spacewalk/postgres/packages/rhn_channel.pkb index 94ab657..b123890 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 08ad46fa502e57b5e6f47b7d1c3919d20c490d09 +-- oracle equivalent source sha1 a57a1f03708569c16c3cd0d747a0736a2877a714 -- -- Copyright (c) 2008--2012 Red Hat, Inc. -- @@ -297,11 +297,8 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_ select distinct c.* from rhnOrgDistChannelMap odcm, 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 + rhnChannel c + where c.parent_channel is null and c.id = odcm.channel_id and c.channel_arch_id = odcm.channel_arch_id and odcm.release = release_in @@ -387,11 +384,8 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_ select distinct c.* from rhnOrgDistChannelMap odcm, 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 + rhnChannel c + where c.parent_channel is null and c.id = odcm.channel_id and c.channel_arch_id = odcm.channel_arch_id and odcm.release = release_in diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/149-rhn_channel.pkb.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/149-rhn_channel.pkb.sql.oracle index e06f3e3..a7ebaee 100644 --- a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/149-rhn_channel.pkb.sql.oracle +++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/149-rhn_channel.pkb.sql.oracle @@ -13,11 +13,8 @@ IS select distinct c.* from rhnOrgDistChannelMap odcm, 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 + rhnChannel c + where c.parent_channel is null and c.id = odcm.channel_id and c.channel_arch_id = odcm.channel_arch_id and odcm.release = release_in diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/149-rhn_channel.pkb.sql.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/149-rhn_channel.pkb.sql.postgresql index e22cb97..84137a0 100644 --- a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/149-rhn_channel.pkb.sql.postgresql +++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/149-rhn_channel.pkb.sql.postgresql @@ -1,4 +1,4 @@ --- oracle equivalent source sha1 e5b83a1474fa01683c27c4e0f1deb2eea46970c4 +-- oracle equivalent source sha1 b0c8a29f5f1f28d2308ccaf6b52a4e54c3999e7c
--update pg_setting update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_path'; @@ -21,11 +21,8 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_ select distinct c.* from rhnOrgDistChannelMap odcm, 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 + rhnChannel c + where c.parent_channel is null and c.id = odcm.channel_id and c.channel_arch_id = odcm.channel_arch_id and odcm.release = release_in @@ -66,11 +63,8 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_ select distinct c.* from rhnOrgDistChannelMap odcm, 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 + rhnChannel c + where c.parent_channel is null and c.id = odcm.channel_id and c.channel_arch_id = odcm.channel_arch_id and odcm.release = release_in
commit ea6d42861a42750b5ed15fa6f80d797d6ed65b1d Author: Tomas Lestach tlestach@redhat.com Date: Mon Oct 29 15:36:11 2012 +0100
update rhn_channel package to use rhnOrgDistChannelMap
diff --git a/schema/spacewalk/oracle/packages/rhn_channel.pkb b/schema/spacewalk/oracle/packages/rhn_channel.pkb index 8efba10..954bf4a 100644 --- a/schema/spacewalk/oracle/packages/rhn_channel.pkb +++ b/schema/spacewalk/oracle/packages/rhn_channel.pkb @@ -26,16 +26,17 @@ IS org_id_in in number ) return rhnChannel%ROWTYPE is select distinct c.* - from rhnDistChannelMap dcm, + from rhnOrgDistChannelMap odcm, 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 c.id = odcm.channel_id + and c.channel_arch_id = odcm.channel_arch_id + and odcm.release = release_in + and odcm.for_org_id = org_id_in and scac.server_arch_id = server_arch_id_in and scac.channel_arch_id = c.channel_arch_id;
diff --git a/schema/spacewalk/postgres/packages/rhn_channel.pkb b/schema/spacewalk/postgres/packages/rhn_channel.pkb index 1fb8e35..94ab657 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 f803770bbbb72afb903e84f7251a6b2779fa8351 +-- oracle equivalent source sha1 08ad46fa502e57b5e6f47b7d1c3919d20c490d09 -- -- Copyright (c) 2008--2012 Red Hat, Inc. -- @@ -295,16 +295,17 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_ org_id_in numeric ) for select distinct c.* - from rhnDistChannelMap dcm, + from rhnOrgDistChannelMap odcm, 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 c.id = odcm.channel_id + and c.channel_arch_id = odcm.channel_arch_id + and odcm.release = release_in + and odcm.for_org_id = org_id_in and scac.server_arch_id = server_arch_id_in and scac.channel_arch_id = c.channel_arch_id;
@@ -384,16 +385,17 @@ update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_ org_id_in numeric ) for select distinct c.* - from rhnDistChannelMap dcm, + from rhnOrgDistChannelMap odcm, 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 c.id = odcm.channel_id + and c.channel_arch_id = odcm.channel_arch_id + and odcm.release = release_in + and odcm.for_org_id = org_id_in and scac.server_arch_id = server_arch_id_in and scac.channel_arch_id = c.channel_arch_id;
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/149-rhn_channel.pkb.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/149-rhn_channel.pkb.sql.oracle new file mode 100644 index 0000000..e06f3e3 --- /dev/null +++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/149-rhn_channel.pkb.sql.oracle @@ -0,0 +1,1208 @@ +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 rhnOrgDistChannelMap odcm, + 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 = odcm.channel_id + and c.channel_arch_id = odcm.channel_arch_id + and odcm.release = release_in + and odcm.for_org_id = org_id_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 timestamp with local time zone; + + 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 = current_timestamp 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 = current_timestamp 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 timestamp with local time zone; + 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(current_timestamp, last_modified + interval '1' second) + where id = channel_id_in; + end; + + procedure update_channel ( channel_id_in in number, invalidate_ss in number := 0, + date_to_use in timestamp with local time zone := current_timestamp ) + is + + channel_last_modified timestamp with local time zone; + last_modified_value timestamp with local time zone; + + 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 timestamp with local time zone := current_timestamp ) + 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 timestamp with local time zone := current_timestamp ) + 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/149-rhn_channel.pkb.sql.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/149-rhn_channel.pkb.sql.postgresql new file mode 100644 index 0000000..e22cb97 --- /dev/null +++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/149-rhn_channel.pkb.sql.postgresql @@ -0,0 +1,127 @@ +-- oracle equivalent source sha1 e5b83a1474fa01683c27c4e0f1deb2eea46970c4 + +--update pg_setting +update pg_settings set setting = 'rhn_channel,' || setting where name = 'search_path'; + + create or replace function guess_server_base( + server_id_in in numeric + ) RETURNS numeric as $$ + declare + server_cursor cursor for + select s.server_arch_id, s.release, s.org_id + from rhnServer s + where s.id = server_id_in; + -- Cursor that fetches all the possible base channels for a + -- (server_arch_id, release, org_id) combination + base_channel_cursor cursor( + release_in varchar, + server_arch_id_in numeric, + org_id_in numeric + ) for + select distinct c.* + from rhnOrgDistChannelMap odcm, + 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 = odcm.channel_id + and c.channel_arch_id = odcm.channel_arch_id + and odcm.release = release_in + and odcm.for_org_id = org_id_in + and scac.server_arch_id = server_arch_id_in + and scac.channel_arch_id = c.channel_arch_id; + + 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; + end loop; + -- Server not found, or no base channel applies to it + return null; + end$$ language plpgsql; + + create or replace function base_channel_rel_archid( + release_in in varchar, + server_arch_id_in in numeric, + org_id_in in numeric default -1, + user_id_in in numeric default null + ) returns numeric as $$ + declare + denied_channel_id numeric := null; + valid_org_id numeric := org_id_in; + valid_user_id numeric := user_id_in; + channel_subscribable numeric; + -- Cursor that fetches all the possible base channels for a + -- (server_arch_id, release, org_id) combination + base_channel_cursor cursor( + release_in varchar, + server_arch_id_in numeric, + org_id_in numeric + ) for + select distinct c.* + from rhnOrgDistChannelMap odcm, + 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 = odcm.channel_id + and c.channel_arch_id = odcm.channel_arch_id + and odcm.release = release_in + and odcm.for_org_id = org_id_in + and scac.server_arch_id = server_arch_id_in + and scac.channel_arch_id = c.channel_arch_id; + + begin + if org_id_in = -1 and user_id_in is not null then + -- Get the org id from the user id + + select org_id + into valid_org_id + from web_contact + where id = user_id_in; + + if not found then + -- User doesn't exist + -- XXX Only list public stuff for now + valid_user_id := null; + valid_org_id := -1; + end if; + 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 rhn_channel.loose_user_role_check(c.id, user_id_in, 'subscribe') + into channel_subscribable; + + 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; + + if denied_channel_id is not null then + perform rhn_exception.raise_exception('no_subscribe_permissions'); + end if; + -- No base channel applies + return NULL; + 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 de6cfe75669355604578e3c3fbbbcbce328074a1 Author: Tomas Lestach tlestach@redhat.com Date: Mon Oct 29 14:44:39 2012 +0100
removing unused backend code
diff --git a/backend/server/rhnChannel.py b/backend/server/rhnChannel.py index 9eb54d0..15f1205 100644 --- a/backend/server/rhnChannel.py +++ b/backend/server/rhnChannel.py @@ -1503,101 +1503,6 @@ def subscribe_channel(server_id, channel, username, password):
raise rhnFault(71)
-def _map_install_num_chan_2_label(system_id, version, - server_arch, install_num_chan): - q = rhnSQL.prepare( - """ - select - distinct - c.id, - c.label, - c.parent_channel - from - rhnServerChannelArchCompat scac, - rhnChannelArch ca, - rhnServerArch sa, - rhnChannel c, - rhnServerChannel sc, - rhnReleaseChannelMap rcm, - rhnDistChannelMap dcm - where - rcm.product = :product - and rcm.version = :version - and rcm.channel_arch_id = ca.id - and ca.id = scac.channel_arch_id - and sa.id = scac.server_arch_id - and sa.label = :server_arch - and (rcm.channel_id = c.id or dcm.channel_id = c.id) - and sc.server_id = :server_id - and sc.channel_id = c.parent_channel - and dcm.release = :version - and dcm.channel_arch_id = ca.id - and dcm.os = :product - """) - q.execute(product = install_num_chan, version = version, - server_arch = server_arch, - server_id = system_id) - - data = q.fetchone_dict() - - if not data: - raise ChannelNotFoundError( - "Could not lookup channel for %s, " % install_num_chan + \ - "version: %s, " % version + \ - "architecture: %s, " % server_arch) - else: - log_debug(4, 'looked up channel %s' % data['label']) - return data - -def subscribe_child_channels(system_id, version, server_arch, - install_num_chan_list): - """ - Attemt to subscribe a system to the channels in install_num_chan_list - - Return successful channel labels, failed channel labels and unknown - options we couldn't look up labels for. - - There is no need to wrap this in a try, except block. - subscribe_child_channels swallows known exceptions which is what we want. - Unkown exceptions will propogate up. - """ - - channels = [] - successes = [] - failures = [] - unknowns = [] - - for install_num_chan in install_num_chan_list: - - # Look up the channel id. - try: - install_num_chan_data = _map_install_num_chan_2_label( - system_id, - version, - server_arch, - install_num_chan) - except ChannelNotFoundError, c: - unknowns.append(install_num_chan) - continue - channels.append(install_num_chan_data) - - # Try to subscribe the system. - # Hmm, for whatever reason, subscribe_channels doesn't commit, call - # _subscribe_sql directly. - # subscribe_channels(system_id, channels) - if len(channels) > 0: - for channel in channels: - try: - _subscribe_sql(system_id, channel['id'], 1) - successes.append(channel['label']) - except SubscriptionCountExceeded: - log_error("Subscription count exceeded for channel id %s" % - channel['id']) - failures.append(channel['label']) - - - return successes, failures, unknowns -
# This class is only a convenient encapsulation of a server's attributes: # server_id, org_id, release, arch, user_id. Sometimes we only pass the
commit e1d9d849485d1d379320f446cbe21db94a954f69 Author: Tomas Lestach tlestach@redhat.com Date: Mon Oct 29 13:59:23 2012 +0100
backend changes
diff --git a/backend/satellite_tools/exporter/exportLib.py b/backend/satellite_tools/exporter/exportLib.py index 56cc8e2..629f2ed 100644 --- a/backend/satellite_tools/exporter/exportLib.py +++ b/backend/satellite_tools/exporter/exportLib.py @@ -239,6 +239,7 @@ class _ChannelDumper(BaseRowDumper): from rhnDistChannelMap dcm, rhnChannelArch ca where dcm.channel_id = :channel_id and dcm.channel_arch_id = ca.id + and dcm.org_id is null """)
def set_iterator(self): diff --git a/backend/server/handlers/xmlrpc/errata.py b/backend/server/handlers/xmlrpc/errata.py index 8fa5ac5..7574831 100644 --- a/backend/server/handlers/xmlrpc/errata.py +++ b/backend/server/handlers/xmlrpc/errata.py @@ -82,6 +82,7 @@ class Errata(rhnHandler): and p.id = cp.package_id and cp.channel_id = dcm.channel_id and dcm.release = :dist + and dcm.org_id is null -- map to an errata as well and p.id = ep.package_id and ep.errata_id = e.id diff --git a/backend/server/handlers/xmlrpc/registration.py b/backend/server/handlers/xmlrpc/registration.py index afe5511..549744b 100644 --- a/backend/server/handlers/xmlrpc/registration.py +++ b/backend/server/handlers/xmlrpc/registration.py @@ -602,7 +602,7 @@ class Registration(rhnHandler): try: base = rhnChannel.get_channel_for_release_arch( version, - arch) + arch, newserv['org_id']) failed_channels.append(base['label']) # We want to swallow exceptions here as we are just generating data # for the review screen in rhn_register. diff --git a/backend/server/importlib/backendOracle.py b/backend/server/importlib/backendOracle.py index e3266b1..268de7a 100644 --- a/backend/server/importlib/backendOracle.py +++ b/backend/server/importlib/backendOracle.py @@ -348,8 +348,9 @@ class OracleBackend(Backend): 'release' : DBstring(64), 'channel_arch_id': DBint(), 'channel_id' : DBint(), + 'org_id' : DBint(), }, - pk = ['os', 'release', 'channel_arch_id', 'channel_id'], + pk = ['release', 'channel_arch_id', 'org_id'], attribute = 'dists', defaultSeverity = 4, ), diff --git a/backend/server/importlib/channelImport.py b/backend/server/importlib/channelImport.py index 4201ecc..1467a8d 100644 --- a/backend/server/importlib/channelImport.py +++ b/backend/server/importlib/channelImport.py @@ -314,6 +314,7 @@ class DistChannelMapImport(Import): "Invalid dist_channel_map channel %s" % dcm['channel']) dcm['arch'] = arch dcm['channel_id'] = channel['id'] + dcm['org_id'] = None
def submit(self): try: diff --git a/backend/server/rhnChannel.py b/backend/server/rhnChannel.py index 14b1514..9eb54d0 100644 --- a/backend/server/rhnChannel.py +++ b/backend/server/rhnChannel.py @@ -255,6 +255,7 @@ class Channel(BaseChannelObject): select os, release from rhnDistChannelMap where channel_id = :channel_id + and org_id is null """) def _get_db_dists(self, channel_id): if channel_id is None: @@ -457,8 +458,8 @@ class Channel(BaseChannelObject):
_query_add_dists = rhnSQL.Statement(""" insert into rhnDistChannelMap - (channel_id, channel_arch_id, release, os) - values (:channel_id, :channel_arch_id, :release, :os) + (channel_id, channel_arch_id, release, os, org_id) + values (:channel_id, :channel_arch_id, :release, :os, null) """) def _add_dists(self, releases, oses): self._modify_dists(self._query_add_dists, releases, oses) @@ -482,6 +483,7 @@ class Channel(BaseChannelObject): os = :os where channel_id = :channel_id and release = :release + and org_id is null """) def _update_dists(self, releases, oses): self._modify_dists(self._query_update_dists, releases, oses) @@ -490,6 +492,7 @@ class Channel(BaseChannelObject): delete from rhnDistChannelMap where channel_id = :channel_id and release = :release + and org_id is null """) def _remove_dists(self, releases): self._modify_dists(self._query_remove_dists, releases, None) @@ -810,40 +813,70 @@ def base_eus_channel_for_ver_rel_arch(version, release, server_arch, return channels
-def get_channel_for_release_arch(release, server_arch): +def get_channel_for_release_arch(release, server_arch, org_id = None): log_debug(3, release, server_arch)
server_arch = rhnLib.normalize_server_arch(str(server_arch)) log_debug(3, 'normalized arch as %s' % server_arch)
- query = """ - select distinct - ca.label arch, - c.id, - c.parent_channel, - c.org_id, - c.label, - c.name, - c.summary, - c.description, - to_char(c.last_modified, 'YYYYMMDDHH24MISS') last_modified - from rhnDistChannelMap dcm, - rhnChannel c, - rhnChannelArch ca, - rhnServerChannelArchCompat scac, - rhnServerArch sa - where scac.server_arch_id = sa.id - and sa.label = :server_arch - and scac.channel_arch_id = dcm.channel_arch_id - and dcm.release = :release - and dcm.channel_id = c.id - and dcm.channel_arch_id = c.channel_arch_id - and c.parent_channel is null - and c.org_id is null - and c.channel_arch_id = ca.id - """ + if org_id is None: + query = """ + select distinct + ca.label arch, + c.id, + c.parent_channel, + c.org_id, + c.label, + c.name, + c.summary, + c.description, + to_char(c.last_modified, 'YYYYMMDDHH24MISS') last_modified + from rhnDistChannelMap dcm, + rhnChannel c, + rhnChannelArch ca, + rhnServerChannelArchCompat scac, + rhnServerArch sa + where scac.server_arch_id = sa.id + and sa.label = :server_arch + and scac.channel_arch_id = dcm.channel_arch_id + and dcm.release = :release + and dcm.channel_id = c.id + and dcm.channel_arch_id = c.channel_arch_id + and dcm.org_id is null + and c.parent_channel is null + and c.org_id is null + and c.channel_arch_id = ca.id + """ + else: + query = """ + select distinct + ca.label arch, + c.id, + c.parent_channel, + c.org_id, + c.label, + c.name, + c.summary, + c.description, + to_char(c.last_modified, 'YYYYMMDDHH24MISS') last_modified + from rhnOrgDistChannelMap odcm, + rhnChannel c, + rhnChannelArch ca, + rhnServerChannelArchCompat scac, + rhnServerArch sa + where scac.server_arch_id = sa.id + and sa.label = :server_arch + and scac.channel_arch_id = odcm.channel_arch_id + and odcm.release = :release + and odcm.channel_id = c.id + and odcm.channel_arch_id = c.channel_arch_id + and odcm.org_id = :org_id + and c.parent_channel is null + and c.org_id is null + and c.channel_arch_id = ca.id + """ h = rhnSQL.prepare(query) - h.execute(release=str(release), server_arch=server_arch) + h.execute(release=str(release), server_arch=server_arch, org_id=org_id) row = h.fetchone_dict() if not row: # No channles for this guy @@ -924,14 +957,15 @@ def channels_for_release_arch(release, server_arch, org_id=-1, user_id=None): rhn_channel.available_chan_subscriptions(c.id, :org_id) available_subscriptions from rhnChannelPermissions cp, - rhnDistChannelMap dcm, + rhnOrgDistChannelMap odcm, rhnChannel c, rhnChannelArch ca where - c.id = dcm.channel_id - and dcm.os in ( + c.id = odcm.channel_id + and odcm.os in ( 'Powertools' ) + and odcm.for_org_id = :org_id and c.channel_arch_id = ca.id and cp.channel_id = c.id and cp.org_id = :org_id
commit 787a8c772dea395eb29a769ed983314952ab5bbe Author: Tomas Lestach tlestach@redhat.com Date: Fri Oct 26 14:29:59 2012 +0200
rewrite distchannel APIs
diff --git a/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java b/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java index 5d67f84..9b68a13 100644 --- a/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java +++ b/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java @@ -828,9 +828,9 @@ public class ChannelFactory extends HibernateFactory { * @param user user * @return list of dist channel maps */ - public static List<DistChannelMap> listAllDistChannelMapsByOrg(User user) { + public static List<DistChannelMap> listAllDistChannelMapsByOrg(Org org) { Map params = new HashMap(); - params.put("org_id", user.getOrg().getId()); + params.put("org_id", org.getId()); return singleton.listObjectsByNamedQuery("DistChannelMap.listAllByOrg", params); }
@@ -868,23 +868,24 @@ public class ChannelFactory extends HibernateFactory { }
/** - * Lookup the dist channel map for the given os, release, and channel arch. + * Lookup the dist channel map for the given organization according to + * release and channel arch. * Returns null if none is found. * - * @param os OS - * @param release Version. + * @param org organization + * @param release release * @param channelArch Channel arch. * @return DistChannelMap, null if none is found */ - public static DistChannelMap lookupDistChannelMapByOsReleaseArch(String os, - String release, ChannelArch channelArch) { + public static DistChannelMap lookupDistChannelMapByOrgReleaseArch(Org org, + String release, ChannelArch channelArch) {
Map params = new HashMap(); - params.put("os", os); + params.put("org_id", org.getId()); params.put("release", release); - params.put("channelArch", channelArch); + params.put("channel_arch_id", channelArch.getId()); return (DistChannelMap)singleton.lookupObjectByNamedQuery( - "DistChannelMap.findByOsReleaseArch", params); + "DistChannelMap.findByOrgReleaseArch", params); }
/** diff --git a/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml b/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml index cc8e541..8dd272f 100644 --- a/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml +++ b/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml @@ -46,6 +46,16 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" WHERE id = :id]]> </query>
+ <sql-query name="DistChannelMap.findByOrgReleaseArch"> + <![CDATA[ + SELECT dcm.id, dcm.org_id, dcm.os, dcm.release, dcm.channel_arch_id, dcm.channel_id + FROM rhnOrgDistChannelMap dcm + WHERE dcm.for_org_id = :org_id + AND dcm.release = :release + AND dcm.channel_arch_id = :channel_arch_id + ]]> + <return alias="dcm" class="com.redhat.rhn.domain.channel.DistChannelMap" /> + </sql-query>
<query name="DistChannelMap.findByProductNameReleaseAndChannelArch"> <![CDATA[ diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/distchannel/DistChannelHandler.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/distchannel/DistChannelHandler.java index e3fcf1e..2a3f0f6 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/distchannel/DistChannelHandler.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/distchannel/DistChannelHandler.java @@ -19,12 +19,17 @@ import com.redhat.rhn.domain.channel.Channel; import com.redhat.rhn.domain.channel.ChannelArch; import com.redhat.rhn.domain.channel.ChannelFactory; import com.redhat.rhn.domain.channel.DistChannelMap; +import com.redhat.rhn.domain.org.Org; +import com.redhat.rhn.domain.org.OrgFactory; import com.redhat.rhn.domain.role.RoleFactory; import com.redhat.rhn.domain.user.User; import com.redhat.rhn.frontend.xmlrpc.BaseHandler; import com.redhat.rhn.frontend.xmlrpc.InvalidChannelArchException; import com.redhat.rhn.frontend.xmlrpc.NoSuchChannelException; import com.redhat.rhn.frontend.xmlrpc.NoSuchDistChannelMapException; +import com.redhat.rhn.frontend.xmlrpc.NoSuchOrgException; + +import org.apache.commons.lang.StringUtils;
/** * DistChannelHandler - provides methods to access distribution channel information. @@ -35,11 +40,11 @@ import com.redhat.rhn.frontend.xmlrpc.NoSuchDistChannelMapException; public class DistChannelHandler extends BaseHandler {
/** - * Lists the default distribution channel maps defined per satellite + * Lists the default distribution channel maps * @param sessionKey The sessionKey containing the logged in user * @return List of dist channel maps * - * @xmlrpc.doc Lists the default distribution channel maps defined per satellite + * @xmlrpc.doc Lists the default distribution channel maps * @xmlrpc.param #session_key() * @xmlrpc.returntype * #array("dist channel map") @@ -47,75 +52,116 @@ public class DistChannelHandler extends BaseHandler { * #array_end() */ public Object[] listDefaultMaps(String sessionKey) { + getLoggedInUser(sessionKey); return ChannelFactory.listAllDistChannelMaps().toArray(); }
/** - * Sets (/removes if channelLabel empty) a default distribution channel map + * Lists distribution channel maps valid for the user's organization + * @param sessionKey session key + * @return List of dist channel maps + * + * @xmlrpc.doc Lists distribution channel maps valid for the user's organization + * @xmlrpc.param #session_key() + * @xmlrpc.returntype + * #array("dist channel map") + * $DistChannelMapSerializer + * #array_end() + */ + public Object[] listMapsForOrg(String sessionKey) { + User loggedInUser = getLoggedInUser(sessionKey); + return ChannelFactory.listAllDistChannelMapsByOrg(loggedInUser.getOrg()).toArray(); + } + + /** + * Lists distribution channel maps valid for an organization, + * satellite admin right needed + * @param sessionKey session key + * @return List of dist channel maps + * + * @xmlrpc.doc Lists distribution channel maps valid for an organization, + * satellite admin right needed + * @xmlrpc.param #session_key() + * @xmlrpc.returntype + * #array("dist channel map") + * $DistChannelMapSerializer + * #array_end() + */ + public Object[] listMapsForOrg(String sessionKey, Integer orgId) { + User loggedInUser = getLoggedInUser(sessionKey); + if (!loggedInUser.hasRole(RoleFactory.SAT_ADMIN)) { + throw new PermissionException(RoleFactory.SAT_ADMIN); + } + Org org = OrgFactory.lookupById(new Long(orgId)); + if (org == null) { + throw new NoSuchOrgException(orgId.toString()); + } + + return ChannelFactory.listAllDistChannelMapsByOrg(org).toArray(); + } + + /** + * Sets, overrides (/removes if channelLabel empty) a distribution channel map + * within an organization * @param sessionKey The sessionKey containing the logged in user * @param os OS * @param release Relase - * @param archLabel architecture label + * @param archName architecture label * @param channelLabel channel label * @return Returns 1 if successful, exception otherwise * - * @xmlrpc.doc Sets (/removes if channelLabel empty) a default distribution channel map + * @xmlrpc.doc Sets, overrides (/removes if channelLabel empty) + * a distribution channel map within an organization * @xmlrpc.param #session_key() * @xmlrpc.param #param("string", "os") * @xmlrpc.param #param("string", "release") - * @xmlrpc.param #param("string", "archLabel") + * @xmlrpc.param #param("string", "archName") * @xmlrpc.param #param("string", "channelLabel") * @xmlrpc.returntype #return_int_success() */ - public int setDefaultMap(String sessionKey, String os, String release, - String archLabel, String channelLabel) { + public int setMapForOrg(String sessionKey, String os, String release, + String archName, String channelLabel) { User loggedInUser = getLoggedInUser(sessionKey); - if (!loggedInUser.hasRole(RoleFactory.SAT_ADMIN)) { - throw new PermissionException(RoleFactory.SAT_ADMIN); + if (!loggedInUser.hasRole(RoleFactory.ORG_ADMIN)) { + throw new PermissionException(RoleFactory.ORG_ADMIN); } + Org org = loggedInUser.getOrg();
- ChannelArch channelArch = ChannelFactory.lookupArchByLabel(archLabel); + ChannelArch channelArch = ChannelFactory.lookupArchByName(archName); if (channelArch == null) { - throw new InvalidChannelArchException(archLabel); + throw new InvalidChannelArchException(archName); } - DistChannelMap dcm = ChannelFactory.lookupDistChannelMapByOsReleaseArch(os, - release, channelArch); - if ((dcm != null) && (dcm.getChannel().getProductName() != null)) { - throw new PermissionException("It's not possible to change " + - dcm.getChannel().getProductName().getName() + " channel maps."); + Channel channel = null; + if (!StringUtils.isEmpty(channelLabel)) { + channel = ChannelFactory.lookupByLabel(channelLabel); + if (channel == null) { + throw new NoSuchChannelException(channelLabel); + } }
- if (channelLabel.isEmpty()) { - // remove dist channel map - if (dcm != null) { - ChannelFactory.remove(dcm); - } - else { + DistChannelMap dcm = ChannelFactory.lookupDistChannelMapByOrgReleaseArch( + org, release, channelArch); + + if (channel == null) { + // remove + if (dcm == null || dcm.getOrg() == null){ throw new NoSuchDistChannelMapException(); } + ChannelFactory.remove(dcm); + return 1; + } + // channel != null + if (dcm == null || dcm.getOrg() == null) { + // create + dcm = new DistChannelMap(org, os, release, channelArch, channel); + ChannelFactory.save(dcm); } else { - Channel channel = ChannelFactory.lookupByLabel(channelLabel); - if (channel == null) { - throw new NoSuchChannelException(); - } - - if (dcm != null) { - // update channel map - dcm.setChannel(channel); - ChannelFactory.save(dcm); - } - else { - // create new channel map - dcm = new DistChannelMap(); - dcm.setOs(os); - dcm.setRelease(release); - dcm.setChannelArch(channelArch); - dcm.setChannel(channel); - ChannelFactory.save(dcm); - } + // update + dcm.setOs(os); + dcm.setChannel(channel); + ChannelFactory.save(dcm); } - return 1; } } diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/DistChannelMapSerializer.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/DistChannelMapSerializer.java index 42a7292..7345cdf 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/DistChannelMapSerializer.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/DistChannelMapSerializer.java @@ -35,6 +35,7 @@ import redstone.xmlrpc.XmlRpcSerializer; * #prop_desc("string", "release", "OS Relase") * #prop_desc("string", "arch_name", "Channel architecture") * #prop_desc("string", "channel_label", "Channel label") + * #prop_desc("string", "org_specific", "'Y' organization specific, 'N' default") * #struct_end() */ public class DistChannelMapSerializer implements XmlRpcCustomSerializer { @@ -59,6 +60,7 @@ public class DistChannelMapSerializer implements XmlRpcCustomSerializer { helper.add("release", dstChannelMap.getRelease()); helper.add("arch_name", dstChannelMap.getChannelArch().getName()); helper.add("channel_label", dstChannelMap.getChannel().getLabel()); + helper.add("org_specific", dstChannelMap.getOrg() == null ? "N" : "Y" );
helper.writeTo(output); }
commit 1e345561a8ff33cfc2732573dcff5917dd22fa43 Author: Tomas Lestach tlestach@redhat.com Date: Fri Oct 26 13:14:21 2012 +0200
fix distchannel.listDefaultMaps API
diff --git a/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml b/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml index 7a87b1d..cc8e541 100644 --- a/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml +++ b/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml @@ -30,7 +30,7 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
<query name="DistChannelMap.listAll"> <![CDATA[ - from com.redhat.rhn.domain.channel.DistChannelMap + from com.redhat.rhn.domain.channel.DistChannelMap where org_id is null ]]> </query>
diff --git a/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/DistChannelMapSerializer.java b/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/DistChannelMapSerializer.java index a6db62d..42a7292 100644 --- a/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/DistChannelMapSerializer.java +++ b/java/code/src/com/redhat/rhn/frontend/xmlrpc/serializer/DistChannelMapSerializer.java @@ -33,7 +33,7 @@ import redstone.xmlrpc.XmlRpcSerializer; * #struct("distChannelMap") * #prop_desc("string", "os", "Operationg System") * #prop_desc("string", "release", "OS Relase") - * #prop_desc("string", "arch_label", "Channel architecture") + * #prop_desc("string", "arch_name", "Channel architecture") * #prop_desc("string", "channel_label", "Channel label") * #struct_end() */
commit 19a0ae4b91c3f1dd0a53e884645320e6ae95273a Author: Tomas Lestach tlestach@redhat.com Date: Fri Oct 19 13:37:51 2012 +0200
create dist channel map logic
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 1bf7e32..dcf73b0 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 @@ -1019,4 +1019,10 @@ GROUP BY C.id, C.name </query> </mode>
+<mode name="dist_channel_map_for_org" class="com.redhat.rhn.domain.channel.DistChannelMap"> + <query params="org_id"> + SELECT * FROM rhnOrgDistChannelMap WHERE org_id = :org_id + </query> +</mode> + </datasource_modes> diff --git a/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java b/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java index 106b750..5d67f84 100644 --- a/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java +++ b/java/code/src/com/redhat/rhn/domain/channel/ChannelFactory.java @@ -824,6 +824,30 @@ public class ChannelFactory extends HibernateFactory { }
/** + * Lists all dist channel maps for an user organization + * @param user user + * @return list of dist channel maps + */ + public static List<DistChannelMap> listAllDistChannelMapsByOrg(User user) { + Map params = new HashMap(); + params.put("org_id", user.getOrg().getId()); + return singleton.listObjectsByNamedQuery("DistChannelMap.listAllByOrg", params); + } + + /** + * Lookup the dist channel map by id + * + * @param id dist channel map id + * @return DistChannelMap, null if none is found + */ + public static DistChannelMap lookupDistChannelMapById(Long id) { + Map params = new HashMap(); + params.put("id", id); + return (DistChannelMap)singleton.lookupObjectByNamedQuery( + "DistChannelMap.lookupById", params); + } + + /** * Lookup the dist channel map for the given product name, release, and channel arch. * Returns null if none is found. * diff --git a/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml b/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml index 39afde7..7a87b1d 100644 --- a/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml +++ b/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml @@ -6,7 +6,7 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" <class name="com.redhat.rhn.domain.channel.DistChannelMap" table="rhnDistChannelMap">
- <id name="id" type="long" column="id" not-null="true"> + <id name="id" type="long" column="id"> <meta attribute="scope-set">protected</meta> <generator class="sequence"> <param name="sequence">rhn_dcm_id_seq</param> @@ -34,6 +34,19 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" ]]> </query>
+ <sql-query name="DistChannelMap.listAllByOrg"> + <![CDATA[ + SELECT dcm.id, dcm.org_id, dcm.os, dcm.release, dcm.channel_arch_id, dcm.channel_id from rhnOrgDistChannelMap dcm where dcm.for_org_id = :org_id + ]]> + <return alias="dcm" class="com.redhat.rhn.domain.channel.DistChannelMap" /> + </sql-query> + + <query name="DistChannelMap.lookupById"> + <![CDATA[FROM com.redhat.rhn.domain.channel.DistChannelMap + WHERE id = :id]]> + </query> + + <query name="DistChannelMap.findByProductNameReleaseAndChannelArch"> <![CDATA[ select dcm diff --git a/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.java b/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.java index 5664c3a..db41118 100644 --- a/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.java +++ b/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.java @@ -38,6 +38,29 @@ public class DistChannelMap implements Serializable { private Channel channel;
/** + * default Constructor + */ + public DistChannelMap() { + } + + /** + * Constructor + * @param orgIn organization + * @param osIn operaing system + * @param releaseIn release + * @param chaIn channel architecture + * @param channelIn channel + */ + public DistChannelMap(Org orgIn, String osIn, String releaseIn, + ChannelArch chaIn, Channel channelIn) { + this.org = orgIn; + this.os = osIn; + this.release = releaseIn; + this.channelArch = chaIn; + this.channel = channelIn; + } + + /** * Getter for os * @return String to get */ diff --git a/java/code/src/com/redhat/rhn/frontend/action/channel/manage/DistChannelMapDeleteAction.java b/java/code/src/com/redhat/rhn/frontend/action/channel/manage/DistChannelMapDeleteAction.java new file mode 100644 index 0000000..0790bef --- /dev/null +++ b/java/code/src/com/redhat/rhn/frontend/action/channel/manage/DistChannelMapDeleteAction.java @@ -0,0 +1,63 @@ +/** + * 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.channel.manage; + +import com.redhat.rhn.domain.channel.ChannelFactory; +import com.redhat.rhn.domain.channel.DistChannelMap; +import com.redhat.rhn.domain.user.User; +import com.redhat.rhn.frontend.struts.RequestContext; +import com.redhat.rhn.frontend.struts.RhnAction; +import com.redhat.rhn.frontend.struts.RhnHelper; + +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * DistChannelMapDeleteAction + * @version $Rev$ + */ +public class DistChannelMapDeleteAction extends RhnAction { + + /** {@inheritDoc} */ + public ActionForward execute(ActionMapping mapping, + ActionForm formIn, + HttpServletRequest request, + HttpServletResponse response) { + RequestContext ctx = new RequestContext(request); + User user = ctx.getLoggedInUser(); + + Long dcmId = ctx.getRequiredParam("dcm"); + + DistChannelMap dcMapping = ChannelFactory.lookupDistChannelMapById(dcmId); + ctx.getRequest().setAttribute("dcmap", dcMapping); + + if (ctx.isSubmitted()) { + if (dcMapping != null && dcMapping.getOrg() != null) { + createSuccessMessage(request, "distchannelmap.jsp.delete.message", + dcMapping.getOs()); + ChannelFactory.remove(dcMapping); + return mapping.findForward("success"); + } + createErrorMessage(request, "distchannelmap.jsp.delete.default.message", + null); + } + return mapping.findForward(RhnHelper.DEFAULT_FORWARD); + } +} diff --git a/java/code/src/com/redhat/rhn/frontend/action/channel/manage/DistChannelMapEditAction.java b/java/code/src/com/redhat/rhn/frontend/action/channel/manage/DistChannelMapEditAction.java new file mode 100644 index 0000000..941ce7a --- /dev/null +++ b/java/code/src/com/redhat/rhn/frontend/action/channel/manage/DistChannelMapEditAction.java @@ -0,0 +1,153 @@ +/** + * 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.channel.manage; + +import com.redhat.rhn.common.hibernate.LookupException; +import com.redhat.rhn.common.validator.ValidatorResult; +import com.redhat.rhn.domain.channel.Channel; +import com.redhat.rhn.domain.channel.ChannelArch; +import com.redhat.rhn.domain.channel.ChannelFactory; +import com.redhat.rhn.domain.channel.DistChannelMap; +import com.redhat.rhn.domain.user.User; +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.struts.RhnValidationHelper; +import com.redhat.rhn.manager.channel.ChannelManager; + +import org.apache.struts.action.ActionForm; +import org.apache.struts.action.ActionForward; +import org.apache.struts.action.ActionMapping; +import org.apache.struts.action.DynaActionForm; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + + +/** + * DistChannelMapEditAction + * @version $Rev$ + */ +public class DistChannelMapEditAction extends RhnAction { + + public static final String DCM_ID = "dcm"; + public static final String OS = "os"; + public static final String RELEASE = "release"; + public static final String CHANNEL_ARCH = "architecture"; + public static final String CHANNEL_LABEL = "channel_label"; + private static final String VALIDATION_XSD = "/com/redhat/rhn/frontend/action/" + + "channel/manage/validation/distChannelMapForm.xsd"; + + /** {@inheritDoc} */ + public ActionForward execute(ActionMapping mapping, + ActionForm formIn, + HttpServletRequest request, + HttpServletResponse response) { + DynaActionForm form = (DynaActionForm) formIn; + RequestContext ctx = new RequestContext(request); + User user = ctx.getLoggedInUser(); + + // setup channel architectures + List channelArches = new ArrayList(); + List<ChannelArch> arches = ChannelManager.getChannelArchitectures(); + for (ChannelArch arch : arches) { + Map selection = new HashMap(); + selection.put("label", arch.getName()); + selection.put("value", arch.getLabel()); + channelArches.add(selection); + } + ctx.getRequest().setAttribute("channelArches", channelArches); + + // setup subscribable base channels + List channels = new ArrayList(); + List<Channel> subscribableBaseChannels = + ChannelFactory.listSubscribableBaseChannels(user); + for (Channel channel : subscribableBaseChannels) { + Map selection = new HashMap(); + selection.put("label", channel.getName()); + selection.put("value", channel.getLabel()); + channels.add(selection); + } + ctx.getRequest().setAttribute("channels", channels); + + Long dcmId = ctx.getParamAsLong(DCM_ID); + ctx.getRequest().setAttribute("dcm", dcmId); + + DistChannelMap dcm = null; + if (dcmId != null) { + dcm = ChannelFactory.lookupDistChannelMapById(dcmId); + if (dcm == null) { + throw new LookupException("There's no such a distribution channel " + + "mapping with id: " + dcmId + "."); + } + } + + if (ctx.isSubmitted()) { + ValidatorResult result = RhnValidationHelper.validate(this.getClass(), + makeValidationMap(form), null, VALIDATION_XSD); + if (!result.isEmpty()) { + getStrutsDelegate().saveMessages(request, result); + return mapping.findForward(RhnHelper.DEFAULT_FORWARD); + } + + Channel channel = ChannelFactory.lookupByLabelAndUser( + form.getString(CHANNEL_LABEL), user); + if (dcmId == null || dcm == null || dcm.getOrg() == null) { + ChannelArch cha = ChannelFactory.lookupArchByLabel( + (String) form.get(CHANNEL_ARCH)); + DistChannelMap newDcm = new DistChannelMap( + user.getOrg(), (String) form.get(OS), (String) form.get(RELEASE), + cha, channel); + ChannelFactory.save(newDcm); + createSuccessMessage(request, "distchannelmap.jsp.create.message", + newDcm.getOs()); + } + else { + dcm.setOs((String) form.get(OS)); + dcm.setChannel(channel); + ChannelFactory.save(dcm); + createSuccessMessage(request, "distchannelmap.jsp.update.message", + dcm.getOs()); + } + + return mapping.findForward("success"); + } + + if (dcmId != null && dcm != null) { + + form.set(OS, dcm.getOs()); + form.set(RELEASE, dcm.getRelease()); + form.set(CHANNEL_ARCH, dcm.getChannelArch().getLabel()); + form.set(CHANNEL_LABEL, dcm.getChannel().getLabel()); + + request.setAttribute(RELEASE, dcm.getRelease()); + request.setAttribute(CHANNEL_ARCH, dcm.getChannelArch().getLabel()); + } + + return mapping.findForward(RhnHelper.DEFAULT_FORWARD); + } + + private Map<String, String> makeValidationMap(DynaActionForm form) { + Map<String, String> map = new HashMap<String, String>(); + map.put(OS, form.getString(OS)); + map.put(RELEASE, form.getString(RELEASE)); + return map; + } +} diff --git a/java/code/src/com/redhat/rhn/frontend/action/channel/manage/DistChannelMapSetupAction.java b/java/code/src/com/redhat/rhn/frontend/action/channel/manage/DistChannelMapSetupAction.java index 08a8db5..dadc57e 100644 --- a/java/code/src/com/redhat/rhn/frontend/action/channel/manage/DistChannelMapSetupAction.java +++ b/java/code/src/com/redhat/rhn/frontend/action/channel/manage/DistChannelMapSetupAction.java @@ -55,6 +55,7 @@ public class DistChannelMapSetupAction extends RhnAction implements Listable { * {@inheritDoc} */ public DataResult getResult(RequestContext context) { - return new DataResult(ChannelFactory.listAllDistChannelMaps()); + return new DataResult( + ChannelFactory.listAllDistChannelMapsByOrg(context.getLoggedInUser().getOrg())); } } diff --git a/java/code/src/com/redhat/rhn/frontend/action/channel/manage/validation/distChannelMapForm.xsd b/java/code/src/com/redhat/rhn/frontend/action/channel/manage/validation/distChannelMapForm.xsd new file mode 100644 index 0000000..d7608e4 --- /dev/null +++ b/java/code/src/com/redhat/rhn/frontend/action/channel/manage/validation/distChannelMapForm.xsd @@ -0,0 +1,21 @@ +<?xml version="1.0"?> + +<schema targetNamespace="http://rhn.redhat.com" + xmlns="http://www.w3.org/1999/XMLSchema" + xmlns:rhn="http://rhn.redhat.com%22%3E + + <attribute name="os"> + <simpleType baseType="string"> + <minLength value="3" /> + <maxLength value="64" /> + </simpleType> + </attribute> + + <attribute name="release"> + <simpleType baseType="string"> + <minLength value="3" /> + <maxLength value="64" /> + </simpleType> + </attribute> + +</schema> 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 e278903..b2e8515 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 @@ -8859,9 +8859,72 @@ Please note that some manual configuration of these scripts may still be require <trans-unit id="repos.jsp.channel.repos"> <source>Channel Repositories</source> </trans-unit> + <trans-unit id="os"> + <source>Operating System</source> + </trans-unit> + <trans-unit id="release"> + <source>Release</source> + </trans-unit> + <trans-unit id="org.specific"> + <source>Organization Specific</source> + </trans-unit> + <trans-unit id="distchannelmap.jsp.create"> + <source>Create New Distribution Channel Map</source> + </trans-unit> <trans-unit id="distchannelmap.jsp.update"> <source>Update Distribution Channel Map</source> </trans-unit> + <trans-unit id="distchannelmap.jsp.delete"> + <source>Delete Distribution Channel Map</source> + </trans-unit> + <trans-unit id="distchannelmap.jsp.create.submit"> + <source>Create New Mapping</source> + </trans-unit> + <trans-unit id="distchannelmap.jsp.update.submit"> + <source>Update Mapping</source> + </trans-unit> + <trans-unit id="distchannelmap.jsp.delete.submit"> + <source>Delete Mapping</source> + </trans-unit> + <trans-unit id="distchannelmap.jsp.create.message"> + <source>New Distribution Channel Mapping '{0}' created successfully.</source> + </trans-unit> + <trans-unit id="distchannelmap.jsp.update.message"> + <source>Distribution Channel Mapping '{0}' updated successfully.</source> + </trans-unit> + <trans-unit id="distchannelmap.jsp.delete.message"> + <source>Distribution Channel Mapping '{0}' deleted successfully.</source> + </trans-unit> + <trans-unit id="distchannelmap.jsp.delete.default.message"> + <source>Default Distribution Channel Mappings cannot be deleted.</source> + </trans-unit> + <trans-unit id="distchannelmap.jsp.summary"> + <source>Distribution channel mappings define default base channels where servers land according to its OS and architecture by registration. Default distribution channel mappings may be overriden, but not deleted.</source> + </trans-unit> + <trans-unit id="distchannelmap.jsp.edit.summary"> + <source>Organization specific Distribution Channel Mappings may be edited here. Default Distribution Channel Mappings cannot be edited. They can only be overriden within every organization.</source> + </trans-unit> + <trans-unit id="distchannelmap.jsp.delete.summary"> + <source>Organization specific Distribution Channel Mapping will be deleted. If it is currently overriding a default channel mapping, the default mapping becomes effective.</source> + </trans-unit> + <trans-unit id="distchannelmap.jsp.delete.default.summary"> + <source>Default Distribution Channel Mappings cannot be deleted. They can only be overriden within every organization.</source> + </trans-unit> + <trans-unit id="toolbar.create.distchannelmap"> + <source>create new distribution channel mapping</source> + <context-group name="ctx"> + <context context-type="sourcefile">/rhn/channel/manage/repo/RepoList.do</context> + </context-group> + </trans-unit> + <trans-unit id="toolbar.delete.distchannelmap"> + <source>delete distribution channel mapping</source> + <context-group name="ctx"> + <context context-type="sourcefile">/rhn/channel/manage/repo/RepoList.do</context> + </context-group> + </trans-unit> + <trans-unit id="distchannelmap.jsp.empty"> + <source>No distribution channel mappings currently exist.</source> + </trans-unit>
<!-- TNC -->
diff --git a/java/code/webapp/WEB-INF/nav/sitenav-authenticated.xml b/java/code/webapp/WEB-INF/nav/sitenav-authenticated.xml index 97b59ac..295188a 100644 --- a/java/code/webapp/WEB-INF/nav/sitenav-authenticated.xml +++ b/java/code/webapp/WEB-INF/nav/sitenav-authenticated.xml @@ -173,7 +173,9 @@ <rhn-tab-url>/rhn/channels/manage/repos/RepoCreate.do</rhn-tab-url> </rhn-tab> </rhn-tab> - <rhn-tab name="Distribution Channel Mapping" acl="user_role(satellite_admin)" url="/rhn/channels/manage/DistChannelMap.do"> + <rhn-tab name="Distribution Channel Mapping" acl="user_role(org_admin)" url="/rhn/channels/manage/DistChannelMap.do"> + <rhn-tab-url>/rhn/channels/manage/DistChannelMapEdit.do</rhn-tab-url> + <rhn-tab-url>/rhn/channels/manage/DistChannelMapDelete.do</rhn-tab-url> </rhn-tab> </rhn-tab> <rhn-tab name="Audit" url="/rhn/audit/ListXccdf.do"> diff --git a/java/code/webapp/WEB-INF/pages/channel/manage/distchannelmap.jsp b/java/code/webapp/WEB-INF/pages/channel/manage/distchannelmap.jsp index 9a5735f..d1c93f8 100644 --- a/java/code/webapp/WEB-INF/pages/channel/manage/distchannelmap.jsp +++ b/java/code/webapp/WEB-INF/pages/channel/manage/distchannelmap.jsp @@ -11,14 +11,24 @@ </head> <body>
-<h1><img src="/img/rhn-icon-subscribe_replace.png"> <bean:message key="Distribution Channel Mapping"/></h1> +<rhn:toolbar base="h1" img="/img/rhn-icon-subscribe_replace.png" + creationUrl="DistChannelMapEdit.do" + creationType="distchannelmap" + imgAlt="info.alt.img"> + <bean:message key="Distribution Channel Mapping"/> +</rhn:toolbar> + +<div class="page-summary"> +<p><bean:message key="distchannelmap.jsp.summary"/></p> +</div> +
<rl:listset name="distChannelMap"> <rhn:csrf />
<input type="hidden" name="cid" value="${cid}" />
- <rl:list emptykey="repos.jsp.norepos" alphabarcolumn="os" > + <rl:list emptykey="distchannelmap.jsp.empty" alphabarcolumn="os" >
<rl:decorator name="PageSizeDecorator"/>
@@ -28,7 +38,7 @@ headerkey="Operating System" sortattr="os" > - ${current.os} + <a href="/rhn/channels/manage/DistChannelMapEdit.do?dcm=${current.id}">${current.os}</a> </rl:column> <rl:column sortable="true" bound="false" @@ -47,13 +57,25 @@ </rl:column> <rl:column sortable="true" bound="false" - styleclass="last-column" headerkey="channel.edit.jsp.label" sortattr="channel.label" > ${current.channel.label} </rl:column> - + <rl:column + bound="false" + styleclass="last-column" + headerkey="org.specific" + > + <c:choose> + <c:when test="${current.org != null}"> + <img src="/img/rhn-listicon-checked.gif"> + </c:when> + <c:otherwise> + <img src="/img/rhn-listicon-unchecked.gif"> + </c:otherwise> + </c:choose> + </rl:column> </rl:list> <!-- <div align="right"> diff --git a/java/code/webapp/WEB-INF/pages/channel/manage/distchannelmapdelete.jsp b/java/code/webapp/WEB-INF/pages/channel/manage/distchannelmapdelete.jsp new file mode 100644 index 0000000..8fa060f --- /dev/null +++ b/java/code/webapp/WEB-INF/pages/channel/manage/distchannelmapdelete.jsp @@ -0,0 +1,69 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://rhn.redhat.com/rhn" prefix="rhn" %> +<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> +<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> + +<html:html xhtml="true"> +<body> + <rhn:toolbar base="h1" img="/img/rhn-icon-subscribe_replace.png" imgAlt="info.alt.img"> + <bean:message key="distchannelmap.jsp.delete"/> + </rhn:toolbar> + <h2><bean:message key="distchannelmap.jsp.delete"/></h2> + + <div class="page-summary"> + <c:choose> + <c:when test="${empty dcmap.org}"> + <p><bean:message key="distchannelmap.jsp.delete.default.summary"/></p> + </c:when> + <c:otherwise> + <p><bean:message key="distchannelmap.jsp.delete.summary"/></p> + </c:otherwise> + </c:choose> + </div> + +<html:form method="post" action="/channels/manage/DistChannelMapDelete"> + <rhn:csrf /> + rhn:submitted/ + <table class="details"> + <tr> + <th> + <bean:message key="Operating System"/> + </th> + <td> + <c:out value="${dcmap.os}"/> + </td> + </tr> + <tr> + <th> + <bean:message key="column.release"/> + </th> + <td> + <c:out value="${dcmap.release}"/> + </td> + </tr> + <tr> + <th> + <bean:message key = "column.architecture"/> + </th> + <td> + <c:out value="${dcmap.channelArch.name}"/> + </td> + </tr> + <tr> + <th> + <bean:message key = "channel.edit.jsp.label"/> + </th> + <td> + <c:out value="${dcmap.channel.label}"/> + </td> + </tr> + </table> + + <div align="right"> + <hr /> + <html:submit disabled="${empty dcmap.org}"><bean:message key="distchannelmap.jsp.delete.submit"/></html:submit> + <html:hidden property="dcm" value="${dcmap.id}" /> +</html:form> + +</body> +</html:html> diff --git a/java/code/webapp/WEB-INF/pages/channel/manage/distchannelmapedit.jsp b/java/code/webapp/WEB-INF/pages/channel/manage/distchannelmapedit.jsp new file mode 100644 index 0000000..2ee25db --- /dev/null +++ b/java/code/webapp/WEB-INF/pages/channel/manage/distchannelmapedit.jsp @@ -0,0 +1,109 @@ +<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %> +<%@ taglib uri="http://rhn.redhat.com/rhn" prefix="rhn" %> +<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %> +<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> + +<html:html xhtml="true"> +<body> +<c:choose> + <c:when test="${empty dcm}"> + <rhn:toolbar base="h1" img="/img/rhn-icon-subscribe_replace.png" imgAlt="info.alt.img"> + <bean:message key="distchannelmap.jsp.create"/> + </rhn:toolbar> + <h2><bean:message key="distchannelmap.jsp.create"/></h2> + </c:when> + <c:otherwise> + <rhn:toolbar base="h1" img="/img/rhn-icon-subscribe_replace.png" imgAlt="info.alt.img" + deletionUrl="DistChannelMapDelete.do?dcm=${dcm}" + deletionType="distchannelmap"> + <bean:message key="distchannelmap.jsp.update"/> + </rhn:toolbar> + <h2><bean:message key="distchannelmap.jsp.update"/></h2> + </c:otherwise> +</c:choose> + +<div class="page-summary"> + <p><bean:message key="distchannelmap.jsp.edit.summary"/></p> +</div> + + +<html:form action="/channels/manage/DistChannelMapEdit"> + <rhn:csrf /> + rhn:submitted/ + <table class="details"> + <tr> + <th> + <label for="os"> + <rhn:required-field key = "Operating System"/> + </label> + </th> + <td> + <html:text property="os" styleId="os"/> + </td> + </tr> + <tr> + <th> + <label for="release"> + <rhn:required-field key = "column.release"/> + </label> + </th> + <td> + <c:choose> + <c:when test="${empty dcm}"> + <html:text property="release" styleId="release" disabled="${not empty dcm}"/> + </c:when> + <c:otherwise> + <c:out value="${release}"/> + <html:hidden property="release" value="${release}"/> + </c:otherwise> + </c:choose> + </td> + </tr> + <tr> + <th> + <rhn:required-field key = "column.architecture"/> + </th> + <td> + <c:choose> + <c:when test="${empty dcm}"> + <html:select property="architecture"> + <html:options collection="channelArches" + property="value" labelProperty="label" /> + </html:select> + </c:when> + <c:otherwise> + <c:out value="${architecture}"/> + <html:hidden property="architecture" value="${architecture}"/> + </c:otherwise> + </c:choose> + </td> + </tr> + <tr> + <th> + <rhn:required-field key = "channel.edit.jsp.label"/> + </th> + <td> + <html:select property="channel_label"> + <html:options collection="channels" + property="value" labelProperty="label" /> + </html:select> + </td> + </tr> + </table> + + <div align="right"> + <hr /> + <c:choose> + <c:when test="${empty dcm}"> + html:submit<bean:message key="distchannelmap.jsp.create.submit"/></html:submit> + </c:when> + <c:otherwise> + html:submit<bean:message key="distchannelmap.jsp.update.submit"/></html:submit> + </c:otherwise> + </c:choose> + + <html:hidden property="dcm" value="${dcm}" /> +</html:form> + +</body> +</html:html> diff --git a/java/code/webapp/WEB-INF/struts-config.xml b/java/code/webapp/WEB-INF/struts-config.xml index dd3cc10..f5be356 100644 --- a/java/code/webapp/WEB-INF/struts-config.xml +++ b/java/code/webapp/WEB-INF/struts-config.xml @@ -1213,6 +1213,14 @@ <form-property name="proxy_pass" type="java.lang.String" /> </form-bean>
+ <form-bean name="distChannelMapForm" + type="com.redhat.rhn.frontend.struts.ScrubbingDynaActionForm"> + <form-property name="os" type="java.lang.String" /> + <form-property name="release" type="java.lang.String" /> + <form-property name="architecture" type="java.lang.String" /> + <form-property name="channel_label" type="java.lang.String" /> + </form-bean> + </form-beans>
<global-exceptions> @@ -7570,7 +7578,6 @@
<action path="/channels/manage/DistChannelMap" scope="request" - parameter="all" input="/WEB-INF/pages/channel/manage/distchannelmap.jsp" type="com.redhat.rhn.frontend.action.channel.manage.DistChannelMapSetupAction" className="com.redhat.rhn.frontend.struts.RhnActionMapping"> @@ -7579,16 +7586,37 @@ path="/WEB-INF/pages/channel/manage/distchannelmap.jsp"/> </action>
- <action path="/common/DownloadFile" + <action path="/channels/manage/DistChannelMapEdit" + scope="request" + name="distChannelMapForm" + type="com.redhat.rhn.frontend.action.channel.manage.DistChannelMapEditAction" + className="com.redhat.rhn.frontend.struts.RhnActionMapping"> + <set-property property="postRequiredIfSubmitted" value="true" /> + <forward name="default" + path="/WEB-INF/pages/channel/manage/distchannelmapedit.jsp"/> + <forward name="success" + path="/channels/manage/DistChannelMap.do" redirect = "true"/> + </action> + + <action path="/channels/manage/DistChannelMapDelete" + scope="request" + name="distChannelMapForm" + type="com.redhat.rhn.frontend.action.channel.manage.DistChannelMapDeleteAction" + className="com.redhat.rhn.frontend.struts.RhnActionMapping"> + <set-property property="postRequiredIfSubmitted" value="true" /> + <forward name="default" + path="/WEB-INF/pages/channel/manage/distchannelmapdelete.jsp"/> + <forward name="success" + path="/channels/manage/DistChannelMap.do" redirect = "true"/> + </action> + + <action path="/common/DownloadFile" scope="request" type="com.redhat.rhn.frontend.action.common.DownloadFile" className="com.redhat.rhn.frontend.struts.RhnActionMapping"> <forward name="error" path="/WEB-INF/pages/common/errors/baddownloadaction.jsp"/> - </action> - - - + </action>
<action path="/admin/config/Orgs" forward="/WEB-INF/pages/admin/config/multiorg.jsp" />
commit fe52322c236ba1a7f58fab946558c6813ab03750 Author: Tomas Lestach tlestach@redhat.com Date: Fri Oct 19 13:19:13 2012 +0200
introduce rhnOrgDistChannelMap
diff --git a/schema/spacewalk/common/views/rhnOrgDistChannelMap.sql b/schema/spacewalk/common/views/rhnOrgDistChannelMap.sql new file mode 100644 index 0000000..9777f4f --- /dev/null +++ b/schema/spacewalk/common/views/rhnOrgDistChannelMap.sql @@ -0,0 +1,45 @@ +-- +-- Copyright (c) 2008 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 VIEW +rhnOrgDistChannelMap +( + id, + for_org_id, + org_id, + os, + release, + channel_arch_id, + channel_id +) +AS +SELECT CASE WHEN dcm_o.org_id IS NOT NULL THEN dcm_o.id ELSE dcm_n.id END id, + o.id as for_org_id, + dcm_o.org_id, + CASE WHEN dcm_o.org_id IS NOT NULL THEN dcm_o.os ELSE dcm_n.os END os, + CASE WHEN dcm_o.org_id IS NOT NULL THEN dcm_o.release ELSE dcm_n.release END release, + CASE WHEN dcm_o.org_id IS NOT NULL THEN dcm_o.channel_arch_id ELSE dcm_n.channel_arch_id END channel_arch_id, + CASE WHEN dcm_o.org_id IS NOT NULL THEN dcm_o.channel_id ELSE dcm_n.channel_id END channel_id +FROM web_customer o + JOIN (SELECT DISTINCT release, channel_arch_id from rhnDistChannelMap) dcm ON 1 = 1 + LEFT JOIN rhnDistChannelMap dcm_n ON dcm_n.org_id IS NULL + AND dcm_n.release = dcm.release + AND dcm_n.channel_arch_id = dcm.channel_arch_id + LEFT JOIN rhnDistChannelMap dcm_o ON dcm_o.org_id = o.id + AND dcm_o.release = dcm.release + AND dcm_o.channel_arch_id = dcm.channel_arch_id +WHERE (dcm_o.channel_id IS NOT NULL OR dcm_n.channel_id IS NOT NULL) +ORDER BY org_id, release, channel_arch_id; diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/147-rhnOrgDistChannelMap.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/147-rhnOrgDistChannelMap.sql new file mode 100644 index 0000000..9777f4f --- /dev/null +++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/147-rhnOrgDistChannelMap.sql @@ -0,0 +1,45 @@ +-- +-- Copyright (c) 2008 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 VIEW +rhnOrgDistChannelMap +( + id, + for_org_id, + org_id, + os, + release, + channel_arch_id, + channel_id +) +AS +SELECT CASE WHEN dcm_o.org_id IS NOT NULL THEN dcm_o.id ELSE dcm_n.id END id, + o.id as for_org_id, + dcm_o.org_id, + CASE WHEN dcm_o.org_id IS NOT NULL THEN dcm_o.os ELSE dcm_n.os END os, + CASE WHEN dcm_o.org_id IS NOT NULL THEN dcm_o.release ELSE dcm_n.release END release, + CASE WHEN dcm_o.org_id IS NOT NULL THEN dcm_o.channel_arch_id ELSE dcm_n.channel_arch_id END channel_arch_id, + CASE WHEN dcm_o.org_id IS NOT NULL THEN dcm_o.channel_id ELSE dcm_n.channel_id END channel_id +FROM web_customer o + JOIN (SELECT DISTINCT release, channel_arch_id from rhnDistChannelMap) dcm ON 1 = 1 + LEFT JOIN rhnDistChannelMap dcm_n ON dcm_n.org_id IS NULL + AND dcm_n.release = dcm.release + AND dcm_n.channel_arch_id = dcm.channel_arch_id + LEFT JOIN rhnDistChannelMap dcm_o ON dcm_o.org_id = o.id + AND dcm_o.release = dcm.release + AND dcm_o.channel_arch_id = dcm.channel_arch_id +WHERE (dcm_o.channel_id IS NOT NULL OR dcm_n.channel_id IS NOT NULL) +ORDER BY org_id, release, channel_arch_id;
commit 59e2fd2474a3843729ae4b58fdd6f0c2fea5ee15 Author: Tomas Lestach tlestach@redhat.com Date: Fri Oct 26 13:04:29 2012 +0200
add id and org to DistChannelMap
diff --git a/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml b/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml index da172f3..39afde7 100644 --- a/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml +++ b/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.hbm.xml @@ -6,17 +6,21 @@ PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" <class name="com.redhat.rhn.domain.channel.DistChannelMap" table="rhnDistChannelMap">
- <composite-id> - <key-property name="os" column="os" type="string" - length="64"/> - <key-property name="release" column="release" type="string" - length="64"/> + <id name="id" type="long" column="id" not-null="true"> + <meta attribute="scope-set">protected</meta> + <generator class="sequence"> + <param name="sequence">rhn_dcm_id_seq</param> + </generator> + </id>
- <key-many-to-one name="channelArch" + <property name="os" column="os" type="string" length="64"/> + <property name="release" column="release" type="string" length="64"/> + <many-to-one name="channelArch" class="com.redhat.rhn.domain.channel.ChannelArch" column="channel_arch_id"/>
- </composite-id> + <many-to-one name="org" class="com.redhat.rhn.domain.org.Org" + column="org_id" />
<many-to-one name="channel" class="com.redhat.rhn.domain.channel.Channel" diff --git a/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.java b/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.java index 1d0e226..5664c3a 100644 --- a/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.java +++ b/java/code/src/com/redhat/rhn/domain/channel/DistChannelMap.java @@ -14,6 +14,8 @@ */ package com.redhat.rhn.domain.channel;
+import com.redhat.rhn.domain.org.Org; + import org.apache.commons.lang.builder.EqualsBuilder; import org.apache.commons.lang.builder.HashCodeBuilder; import org.apache.commons.lang.builder.ToStringBuilder; @@ -28,9 +30,11 @@ public class DistChannelMap implements Serializable {
private static final long serialVersionUID = 4083273166300423729L;
+ private Long id; private String os; private String release; private ChannelArch channelArch; + private Org org; private Channel channel;
/** @@ -94,6 +98,34 @@ public class DistChannelMap implements Serializable { }
/** + * @return Returns the org. + */ + public Org getOrg() { + return org; + } + + /** + * @param orgIn The org to set. + */ + public void setOrg(Org orgIn) { + this.org = orgIn; + } + + /** + * @return Returns the id. + */ + public Long getId() { + return id; + } + + /** + * @param idIn The id to set. + */ + public void setId(Long idIn) { + this.id = idIn; + } + + /** * {@inheritDoc} */ public boolean equals(final Object other) { @@ -122,6 +154,4 @@ public class DistChannelMap implements Serializable { release).append("channelArch", channelArch).append("channel", channel).toString(); } - - }
commit 5f2f3516783cce1cee97e81dc1bc3007fa49d768 Author: Tomas Lestach tlestach@redhat.com Date: Mon Oct 22 17:13:41 2012 +0200
create rhnDistChannelMap triggers to auto fill in id
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/148-rhnOrgDistChannelMap-trigger.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/148-rhnOrgDistChannelMap-trigger.sql.oracle new file mode 100644 index 0000000..dd3e140 --- /dev/null +++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/148-rhnOrgDistChannelMap-trigger.sql.oracle @@ -0,0 +1,10 @@ +create or replace trigger rhn_dist_channel_map_mod_trig +before insert or update on rhnDistChannelMap +for each row +begin + if :new.id is null then + select rhn_dcm_id_seq.nextval into :new.id from dual; + end if; +end; +/ +show errors diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/148-rhnOrgDistChannelMap-trigger.sql.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/148-rhnOrgDistChannelMap-trigger.sql.postgresql new file mode 100644 index 0000000..fd93f7f --- /dev/null +++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/148-rhnOrgDistChannelMap-trigger.sql.postgresql @@ -0,0 +1,17 @@ +-- oracle equivalent source sha1 52c0d465e922c0e887b6728e493e593c532e6398 + +create or replace function rhn_dist_channel_map_mod_trig_fun() returns trigger as +$$ +begin + if new.id is null then + new.id := nextval('rhn_rhn_dcm_id_seq'); + end if; + return new; +end; +$$ language plpgsql; + +create trigger +rhn_dist_channel_map_mod_trig +before insert or update on rhnDistChannelMap +for each row +execute procedure rhn_dist_channel_map_mod_trig_fun();
commit d64b96ca9df8239ca2ba798954afc5137f4af575 Author: Tomas Lestach tlestach@redhat.com Date: Wed Oct 17 14:09:13 2012 +0200
add id and org_id to rhnDistChannelMap
to enable organization overrides
diff --git a/schema/spacewalk/common/tables/rhnDistChannelMap.sql b/schema/spacewalk/common/tables/rhnDistChannelMap.sql index 9588aac..6b0c3d5 100644 --- a/schema/spacewalk/common/tables/rhnDistChannelMap.sql +++ b/schema/spacewalk/common/tables/rhnDistChannelMap.sql @@ -16,6 +16,8 @@
CREATE TABLE rhnDistChannelMap ( + id NUMBER NOT NULL + CONSTRAINT rhn_dcm_id_pk PRIMARY KEY, os VARCHAR2(64) NOT NULL, release VARCHAR2(64) NOT NULL, channel_arch_id NUMBER NOT NULL @@ -24,15 +26,17 @@ CREATE TABLE rhnDistChannelMap channel_id NUMBER NOT NULL CONSTRAINT rhn_dcm_cid_fk REFERENCES rhnChannel (id) - ON DELETE CASCADE + ON DELETE CASCADE, + org_id NUMBER + CONSTRAINT rhn_dcm_oid_fk + REFERENCES web_customer (id) + ON DELETE CASCADE ) ENABLE ROW MOVEMENT ;
-CREATE INDEX rhn_dcm_os_release_caid_idx - ON rhnDistChannelMap (os, release, channel_arch_id) - TABLESPACE [[64k_tbs]]; +CREATE SEQUENCE rhn_dcm_id_seq;
ALTER TABLE rhnDistChannelMap - ADD CONSTRAINT rhn_dcm_os_release_caid_uq UNIQUE (os, release, channel_arch_id); + ADD CONSTRAINT rhn_dcm_release_caid_oid_uq UNIQUE (release, channel_arch_id, org_id);
diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/145-rhnDistChannelMap.sql.oracle b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/145-rhnDistChannelMap.sql.oracle new file mode 100644 index 0000000..31b61b8 --- /dev/null +++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/145-rhnDistChannelMap.sql.oracle @@ -0,0 +1,11 @@ +ALTER TABLE rhnDistChannelMap ADD org_id NUMBER; +ALTER TABLE rhnDistChannelMap ADD CONSTRAINT rhn_dcm_oid_fk FOREIGN KEY (org_id) REFERENCES web_customer (id) ON DELETE CASCADE; +DROP INDEX rhn_dcm_os_release_caid_idx; +ALTER TABLE rhnDistChannelMap DROP CONSTRAINT rhn_dcm_os_release_caid_uq; +ALTER TABLE rhnDistChannelMap ADD CONSTRAINT rhn_dcm_release_caid_oid_uq UNIQUE (release, channel_arch_id, org_id); + +ALTER TABLE rhnDistChannelMap ADD id NUMBER; +CREATE SEQUENCE rhn_dcm_id_seq; +UPDATE rhnDistChannelMap SET id = rhn_dcm_id_seq.nextval; +ALTER TABLE rhnDistChannelMap MODIFY id NUMBER NOT NULL; +ALTER TABLE rhnDistChannelMap ADD CONSTRAINT rhn_dcm_id_pk PRIMARY KEY (id); diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/145-rhnDistChannelMap.sql.postgresql b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/145-rhnDistChannelMap.sql.postgresql new file mode 100644 index 0000000..08fa0fa --- /dev/null +++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/145-rhnDistChannelMap.sql.postgresql @@ -0,0 +1,13 @@ +-- oracle equivalent source sha1 0f4e7323033280e62e68b36a0a3142c69addf715 + +ALTER TABLE rhnDistChannelMap ADD org_id NUMERIC; +ALTER TABLE rhnDistChannelMap ADD CONSTRAINT rhn_dcm_oid_fk FOREIGN KEY (org_id) REFERENCES web_customer (id) ON DELETE CASCADE; +DROP INDEX rhn_dcm_os_release_caid_idx; +ALTER TABLE rhnDistChannelMap DROP CONSTRAINT rhn_dcm_os_release_caid_uq; +ALTER TABLE rhnDistChannelMap ADD CONSTRAINT rhn_dcm_release_caid_oid_uq UNIQUE (release, channel_arch_id, org_id); + +ALTER TABLE rhnDistChannelMap ADD id NUMERIC; +CREATE SEQUENCE rhn_dcm_id_seq; +UPDATE rhnDistChannelMap SET id = nextval('rhn_dcm_id_seq'); +ALTER TABLE rhnDistChannelMap ALTER COLUMN id SET NOT NULL; +ALTER TABLE rhnDistChannelMap ADD CONSTRAINT rhn_dcm_id_pk PRIMARY KEY (id); diff --git a/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/146-rhnDistChannelMap-data.sql b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/146-rhnDistChannelMap-data.sql new file mode 100644 index 0000000..948a329 --- /dev/null +++ b/schema/spacewalk/upgrade/spacewalk-schema-1.7-to-spacewalk-schema-1.8/146-rhnDistChannelMap-data.sql @@ -0,0 +1 @@ +UPDATE rhnDistChannelMap dcm SET dcm.org_id = (SELECT c.org_id FROM rhnChannel c where c.id = dcm.channel_id);
spacewalk-commits@lists.fedorahosted.org