Skip to content

Commit f65af01

Browse files
jamiestampGDSNewt
authored andcommitted
WIP: UI for user access limiting
1 parent 9626381 commit f65af01

5 files changed

Lines changed: 40 additions & 15 deletions

File tree

app/controllers/admin/editions_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@ def permitted_edition_attributes
222222
:scheduled_publication,
223223
:lock_version,
224224
:access_limited,
225+
:access_limited_named_users,
225226
:alternative_format_provider_id,
226227
:opening_at,
227228
:closing_at,

app/models/concerns/edition/limited_access.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ module Edition::LimitedAccess
33

44
included do
55
enum :access_limited, { disabled: 0, organisations: 1, named_users: 2 }
6+
has_many :edition_user_accesses, dependent: :destroy, inverse_of: :edition
67
after_initialize :set_access_limited
78
end
89

app/models/edition.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,14 @@ def error_labels
443443
{}
444444
end
445445

446+
def access_limited_named_users=(users)
447+
user_emails = users.split(",").map(&:strip).reject(&:empty?)
448+
449+
user_emails.each do |email|
450+
edition_user_accesses.create!(email: email)
451+
end
452+
end
453+
446454
private
447455

448456
def date_for_government
Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,38 @@
11
<div class="govuk-!-margin-bottom-6">
2-
<%= render "govuk_publishing_components/components/fieldset", {
3-
legend_text: "Limit access",
4-
heading_level: 3,
5-
heading_size: "m",
6-
} do %>
7-
<%= form.hidden_field :access_limited, value: "disabled" %>
8-
9-
<%= render "govuk_publishing_components/components/checkboxes", {
2+
<%= render "govuk_publishing_components/components/radio", {
3+
heading: "Limit access",
104
name: "edition[access_limited]",
115
id: "edition_access_limited",
12-
error_items: errors_for(edition.errors, :access_limited),
136
items: [
147
{
15-
label: "Limit access to publishers from organisations associated with this document before you publish",
16-
value: "organisations",
17-
checked: edition.access_limited?,
8+
value: :disabled,
9+
text: "No – This document should be available to all publishers",
10+
bold: true,
11+
checked: edition.disabled?,
12+
},
13+
{
14+
value: :organisations,
15+
text: "Limit access to publishers from organisations associated with this document",
16+
bold: true,
17+
checked: edition.organisations?,
18+
},
19+
{
20+
value: :named_users,
21+
text: "Limit access to named publishers",
22+
bold: true,
23+
checked: edition.named_users?,
24+
conditional: (render "govuk_publishing_components/components/textarea", {
25+
label: {
26+
text: "Add publishers who will have access",
27+
bold: true,
28+
},
29+
name: "edition[access_limited_named_users]",
30+
textarea_id: "edition_access_limited_named_users",
31+
error_message: nil,
32+
value: nil,
33+
hint: "Add the emails of the publishers who will have access to this document before publishing. After publishing the document will be available to all publishers in the organisation associated with this document"
34+
}),
1835
},
1936
],
2037
} %>
21-
<% end %>
2238
</div>

db/schema.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@
358358

359359
create_table "editions", id: :integer, charset: "utf8mb4", collation: "utf8mb4_unicode_ci", force: :cascade do |t|
360360
t.integer "access_limited", default: 0, null: false
361-
t.integer "accessible_by", default: 0, null: false
362361
t.string "additional_related_mainstream_content_title"
363362
t.string "additional_related_mainstream_content_url"
364363
t.boolean "all_nation_applicability", default: true
@@ -626,7 +625,7 @@
626625
t.integer "edition_id"
627626
t.integer "image_data_id"
628627
t.datetime "updated_at", precision: nil
629-
t.string "usage"
628+
t.string "usage", null: false
630629
t.index ["edition_id"], name: "index_images_on_edition_id"
631630
t.index ["image_data_id"], name: "index_images_on_image_data_id"
632631
end

0 commit comments

Comments
 (0)