Skip to content

Commit

Permalink
[api] Add the OBS:ImageTemplate attribute
Browse files Browse the repository at this point in the history
OBS:ImageTemplates attribute marks a project as source for image templates.
You can query for projects with `Project.image_templates` scope.
  • Loading branch information
eduardoj committed Nov 23, 2016
1 parent 6c7684f commit 579d9ac
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 1 deletion.
6 changes: 6 additions & 0 deletions src/api/app/models/project.rb
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ def autocomplete(search)
scope :home, -> { where("name like 'home:%'") }
scope :not_home, -> { where.not("name like 'home:%'") }

# will return all projects with attribute 'OBS:ImageTemplates'
scope :image_templates, lambda {
joins(attribs: { attrib_type: :attrib_namespace }).
where(attrib_types: { name: 'ImageTemplates' }, attrib_namespaces: { name: 'OBS' })
}

validates :name, presence: true, length: { maximum: 200 }, uniqueness: true
validates :title, length: { maximum: 250 }
validate :valid_name
Expand Down
1 change: 1 addition & 0 deletions src/api/db/attribute_descriptions.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ def update_all_attrib_type_descriptions
"MaintenanceProject" => "Mark this project as central maintenance project, which is used to coordinate all official updates.",
"MaintenanceIdTemplate" => "Released maintenance updates get an ID on first release. This attribute can be used to modify the default scheme.",
# "ScreenShots" => "", # to be dropped?
"ImageTemplates" => "Mark this project as source for image templates.",
"OwnerRootProject" => "Mark this project as starting point for the package ownership search. Optional values: \"DisableDevel\": don't follow devel project links. \"BugownerOnly\": limit the result to bugowners (ignoring the maintainer role).",
"RequestCloned" => "Use this attribute to reference a request which will get superseded when a new submit request from this project gets created.",
"ProjectStatusPackageFailComment" => "Use this attribute to explain why this package is failing. This is displayed on the project status page for instance.",
Expand Down
17 changes: 17 additions & 0 deletions src/api/db/migrate/20161123124803_image_templates_attribute.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
class ImageTemplatesAttribute < ActiveRecord::Migration[5.0]
class AttribTypeModifiableBy < ActiveRecord::Base; end

def self.up
ans = AttribNamespace.find_by_name "OBS"
role = Role.find_by_title("Admin")

AttribTypeModifiableBy.reset_column_information

at = AttribType.create(attrib_namespace: ans, name: "ImageTemplates")
AttribTypeModifiableBy.create(role_id: role.id, attrib_type_id: at.id)
end

def self.down
AttribType.find_by_namespace_and_name("OBS", "ImageTemplates").delete()
end
end
2 changes: 2 additions & 0 deletions src/api/db/seeds.rb
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@
at.attrib_type_modifiable_bies.where(user_id: admin.id).first_or_create
at = ans.attrib_types.where(name: "ScreenShots").first_or_create
at.attrib_type_modifiable_bies.where(user_id: admin.id).first_or_create
at = ans.attrib_types.where(name: "ImageTemplates").first_or_create
at.attrib_type_modifiable_bies.where(user_id: admin.id).first_or_create
at = ans.attrib_types.where(name: "IncidentPriority").first_or_create(value_count: 1)
at.attrib_type_modifiable_bies.where(user_id: admin.id).first_or_create
at = ans.attrib_types.where(name: "EmbargoDate").first_or_create(value_count: 1)
Expand Down
2 changes: 1 addition & 1 deletion src/api/db/structure.sql
Original file line number Diff line number Diff line change
Expand Up @@ -1117,6 +1117,6 @@ CREATE TABLE `watched_projects` (
CONSTRAINT `watched_projects_ibfk_1` FOREIGN KEY (`user_id`) REFERENCES `users` (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_bin;

INSERT INTO schema_migrations (version) VALUES ('1'), ('10'), ('11'), ('12'), ('13'), ('14'), ('15'), ('16'), ('17'), ('18'), ('19'), ('2'), ('20'), ('20090701125033'), ('20090703100900'), ('20090716174522'), ('20090717114240'), ('20091017210000'), ('20091022210000'), ('20091022310000'), ('20091029100000'), ('20091030060000'), ('20091102060000'), ('20091111191005'), ('20091115101346'), ('20091117144409'), ('20091117152223'), ('20091118000000'), ('20091119000000'), ('20091119090108'), ('20091119090620'), ('20091124194151'), ('20091206194902'), ('20091209193452'), ('20091209211754'), ('20091226112028'), ('20091229115736'), ('20100102150000'), ('20100104170000'), ('20100109145739'), ('20100125100000'), ('20100202132416'), ('20100302100000'), ('20100304100000'), ('20100315100000'), ('20100316100000'), ('20100316100001'), ('20100327100000'), ('20100329191407'), ('20100423144748'), ('20100426144748'), ('20100428144748'), ('20100429144748'), ('20100506115929'), ('20100507115929'), ('20100530180617'), ('20100609100000'), ('20100609200000'), ('20100614121047'), ('20100629095208'), ('20100702082339'), ('20100705124948'), ('20100705133839'), ('20100705141045'), ('20100707061034'), ('20100805100000'), ('20100812100000'), ('20100827100000'), ('20100903100000'), ('20100927110821'), ('20100927132716'), ('20100927133955'), ('20100928081344'), ('20101110100000'), ('20110117000000'), ('20110131100000'), ('20110202100000'), ('20110202110000'), ('20110302100000'), ('20110303100000'), ('20110309100000'), ('20110318112742'), ('20110321000000'), ('20110322000000'), ('20110323000000'), ('2011033000000'), ('20110331001200'), ('20110404085232'), ('20110404085325'), ('20110404090700'), ('20110405151201'), ('20110502100000'), ('20110519000000'), ('20110527000000'), ('20110615083665'), ('20110615083666'), ('20110627001200'), ('20110703001200'), ('20110711001200'), ('20110719142500'), ('20110725105426'), ('20110728072502'), ('20111005000000'), ('20111116100002'), ('20111117162400'), ('20111122000000'), ('20111123000000'), ('20111206000000'), ('20111206151500'), ('20111207000000'), ('20111213000000'), ('20111215094300'), ('20111303000000'), ('20120110094300'), ('20120110104300'), ('20120111094300'), ('20120112094300'), ('20120112194300'), ('20120119194300'), ('20120119204300'), ('20120119204301'), ('20120120104301'), ('20120120114301'), ('20120124114301'), ('20120124114302'), ('20120124114303'), ('20120216114303'), ('20120217114303'), ('20120217114304'), ('20120220114304'), ('20120222105426'), ('20120223105426'), ('20120304205014'), ('20120312204300'), ('20120313113554'), ('20120313131909'), ('20120319104301'), ('20120319133739'), ('20120320134850'), ('20120407173644'), ('20120411112931'), ('20120411121152'), ('20120417115800'), ('20120418121859'), ('20120529150500'), ('20120903122955'), ('20120904122955'), ('20120907114304'), ('20121014124846'), ('20121015121807'), ('20121112104534'), ('20121112110642'), ('20121114093616'), ('20121120110642'), ('20121120124300'), ('20121121142111'), ('20121124032111'), ('20121130103300'), ('20121130143300'), ('20121213140751'), ('20121213144129'), ('20121216151549'), ('20121220151549'), ('20130111085930'), ('20130220160000'), ('20130301100000'), ('20130409123324'), ('20130410124738'), ('20130414061002'), ('20130603100244'), ('20130610100244'), ('20130612151549'), ('20130618083665'), ('20130621083665'), ('20130626160000'), ('20130627193722'), ('20130702083665'), ('20130702203665'), ('20130723055536'), ('20130725123636'), ('20130726144516'), ('20130802183104'), ('20130802183717'), ('20130802190951'), ('20130805073101'), ('20130807071147'), ('20130814071147'), ('20130816183104'), ('20130817082602'), ('20130819114303'), ('20130820151442'), ('20130830043205'), ('20130903114302'), ('20130904071147'), ('20130910162318'), ('20130917124132'), ('20130920090004'), ('20130930130128'), ('20131005225515'), ('20131006000000'), ('20131006162847'), ('20131020151037'), ('20131020165316'), ('20131021063641'), ('20131022114302'), ('20131023063641'), ('20131027122410'), ('20131028085325'), ('20131029112259'), ('20131105112259'), ('20131106112233'), ('20131111090310'), ('20131111193512'), ('20131111194720'), ('20131112140033'), ('20131120193512'), ('20131123113417'), ('20131124071042'), ('20131125071042'), ('20131125101042'), ('20131126074753'), ('20131126205430'), ('20131127091624'), ('20131209095749'), ('20131209103450'), ('20131210182719'), ('20131218071042'), ('20140113110551'), ('20140123063641'), ('20140123071042'), ('20140124071042'), ('20140210114542'), ('20140213101042'), ('20140218174400'), ('20140219185200'), ('20140516182719'), ('20140624101042'), ('20140627071042'), ('20140704101043'), ('20140709071042'), ('20140714112346'), ('20140717101042'), ('20140718112346'), ('20140721112346'), ('20140729101042'), ('20140801071042'), ('20140819071042'), ('20140821105426'), ('20140827105426'), ('20140903105426'), ('20140903125426'), ('20140908125426'), ('20140908135426'), ('20140916135426'), ('20140930135426'), ('20141001135426'), ('20141002130128'), ('20141002130129'), ('20141002231042'), ('20141022105426'), ('20141022205426'), ('20141107135426'), ('20141110105426'), ('20141125105426'), ('20141201135426'), ('20141202135426'), ('20141208135426'), ('20150112135426'), ('20150127135426'), ('20150129135426'), ('20150129135427'), ('20150227063641'), ('20150623063641'), ('20150625105426'), ('20150630135426'), ('20150715112346'), ('20150716112346'), ('20150716124906'), ('20150807105426'), ('20150902130939'), ('20150903084813'), ('20150916084813'), ('20151030130011'), ('20160321085300'), ('20160321104000'), ('20160321105300'), ('20160518105300'), ('20160610105300'), ('20160808135426'), ('20160819105300'), ('20160824132643'), ('20161019231042'), ('20161025231042'), ('20161117135426'), ('21'), ('22'), ('23'), ('24'), ('25'), ('26'), ('27'), ('28'), ('29'), ('3'), ('30'), ('31'), ('32'), ('33'), ('34'), ('35'), ('36'), ('37'), ('38'), ('39'), ('4'), ('40'), ('41'), ('42'), ('43'), ('44'), ('45'), ('46'), ('47'), ('48'), ('5'), ('6'), ('7'), ('8'), ('9');
INSERT INTO schema_migrations (version) VALUES ('1'), ('10'), ('11'), ('12'), ('13'), ('14'), ('15'), ('16'), ('17'), ('18'), ('19'), ('2'), ('20'), ('20090701125033'), ('20090703100900'), ('20090716174522'), ('20090717114240'), ('20091017210000'), ('20091022210000'), ('20091022310000'), ('20091029100000'), ('20091030060000'), ('20091102060000'), ('20091111191005'), ('20091115101346'), ('20091117144409'), ('20091117152223'), ('20091118000000'), ('20091119000000'), ('20091119090108'), ('20091119090620'), ('20091124194151'), ('20091206194902'), ('20091209193452'), ('20091209211754'), ('20091226112028'), ('20091229115736'), ('20100102150000'), ('20100104170000'), ('20100109145739'), ('20100125100000'), ('20100202132416'), ('20100302100000'), ('20100304100000'), ('20100315100000'), ('20100316100000'), ('20100316100001'), ('20100327100000'), ('20100329191407'), ('20100423144748'), ('20100426144748'), ('20100428144748'), ('20100429144748'), ('20100506115929'), ('20100507115929'), ('20100530180617'), ('20100609100000'), ('20100609200000'), ('20100614121047'), ('20100629095208'), ('20100702082339'), ('20100705124948'), ('20100705133839'), ('20100705141045'), ('20100707061034'), ('20100805100000'), ('20100812100000'), ('20100827100000'), ('20100903100000'), ('20100927110821'), ('20100927132716'), ('20100927133955'), ('20100928081344'), ('20101110100000'), ('20110117000000'), ('20110131100000'), ('20110202100000'), ('20110202110000'), ('20110302100000'), ('20110303100000'), ('20110309100000'), ('20110318112742'), ('20110321000000'), ('20110322000000'), ('20110323000000'), ('2011033000000'), ('20110331001200'), ('20110404085232'), ('20110404085325'), ('20110404090700'), ('20110405151201'), ('20110502100000'), ('20110519000000'), ('20110527000000'), ('20110615083665'), ('20110615083666'), ('20110627001200'), ('20110703001200'), ('20110711001200'), ('20110719142500'), ('20110725105426'), ('20110728072502'), ('20111005000000'), ('20111116100002'), ('20111117162400'), ('20111122000000'), ('20111123000000'), ('20111206000000'), ('20111206151500'), ('20111207000000'), ('20111213000000'), ('20111215094300'), ('20111303000000'), ('20120110094300'), ('20120110104300'), ('20120111094300'), ('20120112094300'), ('20120112194300'), ('20120119194300'), ('20120119204300'), ('20120119204301'), ('20120120104301'), ('20120120114301'), ('20120124114301'), ('20120124114302'), ('20120124114303'), ('20120216114303'), ('20120217114303'), ('20120217114304'), ('20120220114304'), ('20120222105426'), ('20120223105426'), ('20120304205014'), ('20120312204300'), ('20120313113554'), ('20120313131909'), ('20120319104301'), ('20120319133739'), ('20120320134850'), ('20120407173644'), ('20120411112931'), ('20120411121152'), ('20120417115800'), ('20120418121859'), ('20120529150500'), ('20120903122955'), ('20120904122955'), ('20120907114304'), ('20121014124846'), ('20121015121807'), ('20121112104534'), ('20121112110642'), ('20121114093616'), ('20121120110642'), ('20121120124300'), ('20121121142111'), ('20121124032111'), ('20121130103300'), ('20121130143300'), ('20121213140751'), ('20121213144129'), ('20121216151549'), ('20121220151549'), ('20130111085930'), ('20130220160000'), ('20130301100000'), ('20130409123324'), ('20130410124738'), ('20130414061002'), ('20130603100244'), ('20130610100244'), ('20130612151549'), ('20130618083665'), ('20130621083665'), ('20130626160000'), ('20130627193722'), ('20130702083665'), ('20130702203665'), ('20130723055536'), ('20130725123636'), ('20130726144516'), ('20130802183104'), ('20130802183717'), ('20130802190951'), ('20130805073101'), ('20130807071147'), ('20130814071147'), ('20130816183104'), ('20130817082602'), ('20130819114303'), ('20130820151442'), ('20130830043205'), ('20130903114302'), ('20130904071147'), ('20130910162318'), ('20130917124132'), ('20130920090004'), ('20130930130128'), ('20131005225515'), ('20131006000000'), ('20131006162847'), ('20131020151037'), ('20131020165316'), ('20131021063641'), ('20131022114302'), ('20131023063641'), ('20131027122410'), ('20131028085325'), ('20131029112259'), ('20131105112259'), ('20131106112233'), ('20131111090310'), ('20131111193512'), ('20131111194720'), ('20131112140033'), ('20131120193512'), ('20131123113417'), ('20131124071042'), ('20131125071042'), ('20131125101042'), ('20131126074753'), ('20131126205430'), ('20131127091624'), ('20131209095749'), ('20131209103450'), ('20131210182719'), ('20131218071042'), ('20140113110551'), ('20140123063641'), ('20140123071042'), ('20140124071042'), ('20140210114542'), ('20140213101042'), ('20140218174400'), ('20140219185200'), ('20140516182719'), ('20140624101042'), ('20140627071042'), ('20140704101043'), ('20140709071042'), ('20140714112346'), ('20140717101042'), ('20140718112346'), ('20140721112346'), ('20140729101042'), ('20140801071042'), ('20140819071042'), ('20140821105426'), ('20140827105426'), ('20140903105426'), ('20140903125426'), ('20140908125426'), ('20140908135426'), ('20140916135426'), ('20140930135426'), ('20141001135426'), ('20141002130128'), ('20141002130129'), ('20141002231042'), ('20141022105426'), ('20141022205426'), ('20141107135426'), ('20141110105426'), ('20141125105426'), ('20141201135426'), ('20141202135426'), ('20141208135426'), ('20150112135426'), ('20150127135426'), ('20150129135426'), ('20150129135427'), ('20150227063641'), ('20150623063641'), ('20150625105426'), ('20150630135426'), ('20150715112346'), ('20150716112346'), ('20150716124906'), ('20150807105426'), ('20150902130939'), ('20150903084813'), ('20150916084813'), ('20151030130011'), ('20160321085300'), ('20160321104000'), ('20160321105300'), ('20160518105300'), ('20160610105300'), ('20160808135426'), ('20160819105300'), ('20160824132643'), ('20161019231042'), ('20161025231042'), ('20161117135426'), ('20161123124803'), ('21'), ('22'), ('23'), ('24'), ('25'), ('26'), ('27'), ('28'), ('29'), ('3'), ('30'), ('31'), ('32'), ('33'), ('34'), ('35'), ('36'), ('37'), ('38'), ('39'), ('4'), ('40'), ('41'), ('42'), ('43'), ('44'), ('45'), ('46'), ('47'), ('48'), ('5'), ('6'), ('7'), ('8'), ('9');


9 changes: 9 additions & 0 deletions src/api/spec/models/project_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@
it { should allow_value("fOO:+-").for(:name) }
end

describe ".image_templates" do
let(:attribute_type) { AttribType.find_by_namespace_and_name!('OBS', 'ImageTemplates') }
let(:leap_project) { create(:project, name: 'openSUSE_Leap') }
let!(:attrib) { create(:attrib, attrib_type: attribute_type, project: leap_project) }

it { expect(Project.image_templates).to eq([leap_project]) }
end


describe "#update_repositories" do
let!(:repository_1) { create(:repository, name: 'repo_1', rebuild: "direct", project: project) }
let!(:repository_2) { create(:repository, name: 'repo_2', project: project) }
Expand Down

0 comments on commit 579d9ac

Please sign in to comment.