studio-engine 0.44.1 → 0.45.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6b902bc40b9fcd804ebcd5512e291a092056246fa399a5eac8753c40ee194f0d
4
- data.tar.gz: a23566b993e7bb62201be4a428414e6e9f6ffdcc1789248ad6a255031738a2cb
3
+ metadata.gz: d2291a2d35bfd35a6f54666fd0e3590a9a59275e453cf5ff81ddd2af49717301
4
+ data.tar.gz: 5ca713c12be81b7353ebd98f281ef89017a02e6fd348e77d6468383e8d85a90d
5
5
  SHA512:
6
- metadata.gz: f7a3d8f2116ed244a3f9efaa01284f61a173f4df3ad3fdf38f42e8fe64c33601042975427888c841e69e7142b4d847af5619ec5946a08bbfe2feea8be5bd72c9
7
- data.tar.gz: 4a0a21442d7b0b313755fa28fe62101f08408410eabf7278e50b74b8753451776d4b6508686f3db8dd3b78ffafcbe2f2f37e4e4e9f24395524ddd86c332bdee5
6
+ metadata.gz: d8bc026356b0f6e2e1d0b0781719960001dc7fd5bb629b6fd3e7e59a7d3b1ac298f94dc4b88941c709956f49368675089e507ace0851a6f234321f14b5868f07
7
+ data.tar.gz: cceface91adc12a32ad02246d67a58a93306fd44dce24a12ffd8a54a4350d840f52c8e7537634cddd524d0a5372d5ab4ff216fc6c9760bd725fc4a408ef11f55
@@ -67,14 +67,18 @@ module Studio
67
67
  class << self
68
68
  # Every target the page can offer, admin first.
69
69
  #
70
- # The NAMELESS sample is always offered, even when a real member exists.
71
- # It is the only way to see what the name-free fallback header sends, and
72
- # the accounts an app actually parks tend to be real people with real names
73
- # McRitchie Studio's member is Mack McRitchie. The alternative was
74
- # stripping a real person's name to make a preview reachable, which trades
75
- # a worse app for a better test.
70
+ # TWO REAL PEOPLE: the operator admin and an ordinary member.
71
+ #
72
+ # A third, SYNTHETIC "No name on file" entry used to be appended here so
73
+ # the name-free fallback header could be previewed. Mr. McRitchie asked for
74
+ # the list to be just the two, knowing what it costs: the "header for
75
+ # someone with no name on file" field stays in the editor and still ships
76
+ # to strangers, it simply cannot be previewed from this page any more.
77
+ # Do not quietly re-add the sample to make that field previewable — if
78
+ # that needs solving, solve it somewhere this decision is not reversed by
79
+ # accident.
76
80
  def all
77
- [find_admin, find_member, sample_member].compact.uniq(&:id)
81
+ [find_admin, find_member].compact.uniq(&:id)
78
82
  end
79
83
 
80
84
  # The one to preview as. Falls back to the first available rather than
@@ -123,16 +127,41 @@ module Studio
123
127
  # `admin` may be a column, a method, or absent entirely. Only the column
124
128
  # can be queried; anything else is filtered in Ruby over a bounded slice,
125
129
  # because a preview must not table-scan a production users table.
130
+ # THE HOUSE STANDARD, preferred over whoever happens to sort first. Every
131
+ # McRitchie app seeds an "alex" admin and a "mack" member, and without a
132
+ # preference this offered whatever the id order gave: McRitchie Studio
133
+ # showed team@ instead of alex@, and turf-monster showed a test-fixture
134
+ # row (jordan@) instead of Mack.
135
+ #
136
+ # Matched on the email LOCAL PART, so an app's own-domain admin counts too
137
+ # — alex@turfmonster.media and alex@mcritchie.industries are the same
138
+ # person as alex@mcritchie.studio for this purpose.
139
+ #
140
+ # Preference only. An app that seeds neither still gets its first admin
141
+ # and first member, which is what this did before.
142
+ PREFERRED_ADMIN_LOCAL = "alex"
143
+ PREFERRED_MEMBER_LOCAL = "mack"
144
+
145
+ def local_part(record) = record.try(:email).to_s.split("@").first.to_s.downcase
146
+
147
+ def prefer(candidates, local)
148
+ candidates.detect { |user| local_part(user) == local } || candidates.first
149
+ end
150
+
126
151
  def admins(model)
127
- return model.where(admin: true).first if model.column_names.include?("admin")
152
+ if model.column_names.include?("admin")
153
+ return prefer(model.where(admin: true).limit(50).to_a, PREFERRED_ADMIN_LOCAL)
154
+ end
128
155
 
129
- model.limit(50).detect { |user| user.try(:admin?) }
156
+ prefer(model.limit(50).select { |user| user.try(:admin?) }, PREFERRED_ADMIN_LOCAL)
130
157
  end
131
158
 
132
159
  def members(model)
133
- return model.where(admin: [false, nil]).first if model.column_names.include?("admin")
160
+ if model.column_names.include?("admin")
161
+ return prefer(model.where(admin: [ false, nil ]).limit(50).to_a, PREFERRED_MEMBER_LOCAL)
162
+ end
134
163
 
135
- model.limit(50).detect { |user| !user.try(:admin?) }
164
+ prefer(model.limit(50).reject { |user| user.try(:admin?) }, PREFERRED_MEMBER_LOCAL)
136
165
  end
137
166
 
138
167
  def from_record(record, id_prefix:, label:, admin:)
@@ -1,3 +1,3 @@
1
1
  module Studio
2
- VERSION = "0.44.1"
2
+ VERSION = "0.45.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: studio-engine
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.44.1
4
+ version: 0.45.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex McRitchie