Skip to content

Commit

Permalink
Create page for displaying past announcements
Browse files Browse the repository at this point in the history
Test plan:
-“Global Announcements” link is working in the account navigation
-page is populated with dismissed/past/current announcements

Fixes KNO-482

flag=past_announcements

Change-Id: I2b06247816254264a44bdb4b0a634503542851f4
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/237606
Reviewed-by: Rob Orton <[email protected]>
Tested-by: Service Cloud Jenkins <[email protected]>
QA-Review: Rob Orton <[email protected]>
Product-Review: Rob Orton <[email protected]>
  • Loading branch information
drakeaharper committed May 20, 2020
1 parent 7ade3ba commit faceb66
Show file tree
Hide file tree
Showing 8 changed files with 164 additions and 0 deletions.
24 changes: 24 additions & 0 deletions app/controllers/account_notifications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,30 @@ def user_index_deprecated
user_index
end

def render_past_global_announcements
add_crumb(@current_user.short_name, profile_path)
add_crumb(t("Global Announcements"))
js_env(global_notifications: html_to_string)
@show_left_side = true
@context = @current_user.profile
set_active_tab('past_global_announcements')
js_bundle :past_global_notifications
render html: '', layout: true
end

def html_to_string
@for_display = true
coll = AccountNotification.for_user_and_account(@current_user, @domain_root_account, :include_past => true)

coll_active = render_to_string(:partial => 'shared/account_notification',
:collection => coll.select { |item| item.end_at > Time.now.utc })

coll_past = render_to_string(:partial => 'shared/account_notification',
:collection => coll.select { |item| item.end_at < Time.now.utc })

{active: coll_active, past: coll_past}
end

# @API Show a global notification
# Returns a global notification for the current user
# A notification that has been closed by the user will not be returned
Expand Down
26 changes: 26 additions & 0 deletions app/jsx/bundles/past_global_notifications.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* Copyright (C) 2020 - present Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import $ from 'jquery'
import React from 'react'
import ReactDOM from 'react-dom'
import PastGlobalAnnouncements from '../past_global_announcements/PastGlobalAnnouncements'

$(() => {
ReactDOM.render(<PastGlobalAnnouncements />, $('<div/>').appendTo('#content')[0])
})
38 changes: 38 additions & 0 deletions app/jsx/past_global_announcements/PastGlobalAnnouncements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (C) 2020 - present Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import React from 'react'
import {Heading} from '@instructure/ui-heading/lib/Heading'

const PastGlobalAnnouncements = () => {
return (
<>
<Heading border="bottom" margin="medium">
Current
</Heading>
<div dangerouslySetInnerHTML={{__html: ENV.global_notifications.active}}/>

<Heading border="bottom" margin="medium">
Past
</Heading>
<div dangerouslySetInnerHTML={{__html: ENV.global_notifications.past}}/>
</>
)
}

export default PastGlobalAnnouncements
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (C) 2020 - present Instructure, Inc.
*
* This file is part of Canvas.
*
* Canvas is free software: you can redistribute it and/or modify it under
* the terms of the GNU Affero General Public License as published by the Free
* Software Foundation, version 3 of the License.
*
* Canvas is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
* A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
* details.
*
* You should have received a copy of the GNU Affero General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/

import PastGlobalAnnouncements from '../PastGlobalAnnouncements'
import {render} from '@testing-library/react'
import React from 'react'

describe('render announcements', () => {
beforeAll(() => {
window.ENV.global_notifications = {
active: '<div><p>This is an active announcement</p></div>',
past: '<div><p>This is a past announcement</p></div>'
}
})

it('checks that the document contains active announcements', () => {
const {getByText} = render(<PastGlobalAnnouncements/>)
expect(getByText('This is an active announcement')).toBeVisible()
})

it('checks that the document contains past announcements', () => {
const {getByText} = render(<PastGlobalAnnouncements/>)
expect(getByText('This is a past announcement')).toBeVisible()
})
})
15 changes: 15 additions & 0 deletions app/models/user_profile.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class UserProfile < ActiveRecord::Base
TAB_PROFILE_SETTINGS,
TAB_OBSERVEES,
TAB_QR_MOBILE_LOGIN,
TAB_PAST_GLOBAL_ANNOUNCEMENTS,
TAB_CONTENT_SHARES =
*0..10

Expand Down Expand Up @@ -88,6 +89,7 @@ def tabs_available(user = nil, opts = {})
tabs = tabs.slice(0, 2) if user&.fake_student?
insert_observer_tabs(tabs, user)
insert_qr_mobile_login_tab(tabs, user, opts)
insert_past_global_announcements(tabs, user, opts)
tabs
end
end
Expand Down Expand Up @@ -172,6 +174,19 @@ def insert_qr_mobile_login_tab(tabs, user, opts)
}
end
end

def insert_past_global_announcements(tabs, user, opts)
if user && opts[:root_account]&.feature_enabled?(:past_announcements)
tabs <<
{
id: TAB_PAST_GLOBAL_ANNOUNCEMENTS,
label: I18n.t('#tabs.past_global_announcements', 'Global Announcements'),
css_class: 'past_global_announcements',
href: :account_notifications_path,
no_args: {include_past: true}
}
end
end
end

def instructure_misc_plugin_available?
Expand Down
2 changes: 2 additions & 0 deletions app/views/shared/_account_notification.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,14 @@
<%= user_content(notification.message.gsub(/(({{)|(%7B%7B))ACCOUNT_DOMAIN((}})|(%7D%7D))/,request.host_with_port).gsub(/(({{)|(%7B%7B))CANVAS_USER_ID((}})|(%7D%7D))/,@current_user.global_id.to_s)) unless notification.message.nil? %>
</span>
</div>
<% unless @for_display %>
<div class="ic-notification__actions">
<a href="#" class="Button Button--icon-action" data-url="<%= dashboard_close_notification_path(notification.id) %>" data-remove=".ic-notification" title="<%= t :close, 'close' %>" role="button">
<i class="icon-x"></i>
<span class="screenreader-only"><%= t :close, 'close' %></span>
</a>
</div>
<% end %>
</div>
<span class="notification_account_content_text">
<%= t("This is a message for *%{name}*", name: notification.account.name, wrapper: '<b>\1</b>') %>
Expand Down
2 changes: 2 additions & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,8 @@
end
end

get 'account_notifications' => 'account_notifications#render_past_global_announcements'

scope '/profile' do
post 'toggle_disable_inbox' => 'profile#toggle_disable_inbox'
get 'profile_pictures' => 'profile#profile_pics', as: :profile_pics
Expand Down
17 changes: 17 additions & 0 deletions spec/models/user_profile_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,23 @@
end
end

describe "past_announcements flag" do
it "should show announcements tab" do
student_in_course(active_all: true)
account.enable_feature!(:past_announcements)
tabs = @student.profile.
tabs_available(@student, root_account: account)
expect(tabs.map { |t| t[:id] }).to include UserProfile::TAB_PAST_GLOBAL_ANNOUNCEMENTS
end
it "should not show announcements tab when disabled" do
student_in_course(:active_all => true)
account.disable_feature!(:past_announcements)
tabs = @student.profile.
tabs_available(@student, root_account: account)
expect(tabs.map { |t| t[:id] }).not_to include UserProfile::TAB_PAST_GLOBAL_ANNOUNCEMENTS
end
end

describe "QR mobile login" do
before :once do
user_factory(active_all: true)
Expand Down

0 comments on commit faceb66

Please sign in to comment.