diff --git a/app/models/communication/extranet/with_features.rb b/app/models/communication/extranet/with_features.rb index ecba52f6ae727863c6c58e8f0b4c5ea831eedb08..175c1fb2b8b3f1c26ab3194237d5d8fc62c873bd 100644 --- a/app/models/communication/extranet/with_features.rb +++ b/app/models/communication/extranet/with_features.rb @@ -11,7 +11,7 @@ module Communication::Extranet::WithFeatures ] end - def feature?(identifier) + def has_feature?(identifier) public_send "feature_#{identifier}" end -end \ No newline at end of file +end diff --git a/app/models/user/with_registration_context.rb b/app/models/user/with_registration_context.rb index f737c298b0674306b46ebefaedcdc1e2e9018914..476427a9de9a8f0428a12b2ec0c904510138137e 100644 --- a/app/models/user/with_registration_context.rb +++ b/app/models/user/with_registration_context.rb @@ -9,7 +9,7 @@ module User::WithRegistrationContext private def extranet_access - unless registration_context.alumni.where(email: email).any? + unless user_can_access_registration_context? if registration_context.registration_contact.present? errors.add :email, I18n.t('extranet.errors.email_not_allowed_with_contact', contact: registration_context.registration_contact) else @@ -18,5 +18,17 @@ module User::WithRegistrationContext end end + def user_can_access_registration_context? + user_is_alumni? || user_is_contact? + end + + def user_is_alumni? + registration_context.has_feature?(:alumni) && registration_context.alumni.where(email: email).any? + end + + def user_is_contact? + registration_context.has_feature?(:contacts) && registration_context.connected_persons.where(email: email).any? + end + end end diff --git a/app/views/admin/communication/extranets/_sidebar.html.erb b/app/views/admin/communication/extranets/_sidebar.html.erb index c134901cdb58fdcf2ed207cc495529331669d5fa..2f0e313de8a544ea1965fb5bac9ff7f68f35b93b 100644 --- a/app/views/admin/communication/extranets/_sidebar.html.erb +++ b/app/views/admin/communication/extranets/_sidebar.html.erb @@ -10,7 +10,7 @@ }, ] Communication::Extranet::FEATURES.each do |feature| - next unless @extranet.feature? feature + next unless @extranet.has_feature? feature property = "feature_#{feature}" constant = "COMMUNICATION_EXTRANET_#{feature.upcase}" navigation << { diff --git a/app/views/admin/communication/extranets/show.html.erb b/app/views/admin/communication/extranets/show.html.erb index 53df6e59b5784b226d653768a07ad783ee3961f2..829a978296d36554f2ce66c9e97c410a9734bdbd 100644 --- a/app/views/admin/communication/extranets/show.html.erb +++ b/app/views/admin/communication/extranets/show.html.erb @@ -13,9 +13,9 @@ <%= render 'admin/communication/extranets/sidebar' do %> <div class="row"> <% Communication::Extranet::FEATURES.each do |feature| %> - <% + <% property = "feature_#{feature}" - active = @extranet.feature? feature + active = @extranet.has_feature? feature next unless active %> <div class="col-lg-3">