From d2a2ccdb091e593aa37ed3750e1146c530140c2a Mon Sep 17 00:00:00 2001 From: tms Date: Mon, 18 Feb 2013 02:44:18 -0500 Subject: [PATCH] Added restricted route to kick out trespassers on user routes --- app/assets/javascripts/application.js.erb | 1 + .../routes/discourse_restricted_user_route.js.coffee | 10 ++++++++++ .../discourse/routes/preferences_email_route.js.coffee | 2 +- .../discourse/routes/preferences_route.js.coffee | 2 +- .../routes/preferences_username_route.js.coffee | 2 +- .../routes/user_private_messages_route.js.coffee | 2 +- 6 files changed, 15 insertions(+), 4 deletions(-) create mode 100644 app/assets/javascripts/discourse/routes/discourse_restricted_user_route.js.coffee diff --git a/app/assets/javascripts/application.js.erb b/app/assets/javascripts/application.js.erb index 46caccf9253..5f44e5f57f0 100644 --- a/app/assets/javascripts/application.js.erb +++ b/app/assets/javascripts/application.js.erb @@ -34,6 +34,7 @@ //= require ./discourse/views/modal/modal_body_view //= require ./discourse/models/model //= require ./discourse/routes/discourse_route +//= require ./discourse/routes/discourse_restricted_user_route //= require_tree ./discourse/controllers //= require_tree ./discourse/components diff --git a/app/assets/javascripts/discourse/routes/discourse_restricted_user_route.js.coffee b/app/assets/javascripts/discourse/routes/discourse_restricted_user_route.js.coffee new file mode 100644 index 00000000000..af51c2642c9 --- /dev/null +++ b/app/assets/javascripts/discourse/routes/discourse_restricted_user_route.js.coffee @@ -0,0 +1,10 @@ +window.Discourse.RestrictedUserRoute = Discourse.Route.extend + + enter: (router, context) -> + user = @controllerFor('user').get('content') + + @allowed = user.can_edit + + redirect: -> + @transitionTo('user.activity') unless @allowed + \ No newline at end of file diff --git a/app/assets/javascripts/discourse/routes/preferences_email_route.js.coffee b/app/assets/javascripts/discourse/routes/preferences_email_route.js.coffee index 8befc736157..3b4b3de7975 100644 --- a/app/assets/javascripts/discourse/routes/preferences_email_route.js.coffee +++ b/app/assets/javascripts/discourse/routes/preferences_email_route.js.coffee @@ -1,4 +1,4 @@ -window.Discourse.PreferencesEmailRoute = Discourse.Route.extend +window.Discourse.PreferencesEmailRoute = Discourse.RestrictedUserRoute.extend renderTemplate: -> @render into: 'user', outlet: 'userOutlet' setupController: (controller) -> diff --git a/app/assets/javascripts/discourse/routes/preferences_route.js.coffee b/app/assets/javascripts/discourse/routes/preferences_route.js.coffee index bbf14ab3b91..87f254bc6fb 100644 --- a/app/assets/javascripts/discourse/routes/preferences_route.js.coffee +++ b/app/assets/javascripts/discourse/routes/preferences_route.js.coffee @@ -1,4 +1,4 @@ -window.Discourse.PreferencesRoute = Discourse.Route.extend +window.Discourse.PreferencesRoute = Discourse.RestrictedUserRoute.extend renderTemplate: -> @render 'preferences', into: 'user', outlet: 'userOutlet', controller: 'preferences' diff --git a/app/assets/javascripts/discourse/routes/preferences_username_route.js.coffee b/app/assets/javascripts/discourse/routes/preferences_username_route.js.coffee index f440d738c4a..01109e6c582 100644 --- a/app/assets/javascripts/discourse/routes/preferences_username_route.js.coffee +++ b/app/assets/javascripts/discourse/routes/preferences_username_route.js.coffee @@ -1,4 +1,4 @@ -window.Discourse.PreferencesUsernameRoute = Discourse.Route.extend +window.Discourse.PreferencesUsernameRoute = Discourse.RestrictedUserRoute.extend renderTemplate: -> @render into: 'user', outlet: 'userOutlet' setupController: (controller) -> diff --git a/app/assets/javascripts/discourse/routes/user_private_messages_route.js.coffee b/app/assets/javascripts/discourse/routes/user_private_messages_route.js.coffee index 2ff6bafd51d..cecbf727836 100644 --- a/app/assets/javascripts/discourse/routes/user_private_messages_route.js.coffee +++ b/app/assets/javascripts/discourse/routes/user_private_messages_route.js.coffee @@ -1,4 +1,4 @@ -window.Discourse.UserPrivateMessagesRoute = Discourse.Route.extend +window.Discourse.UserPrivateMessagesRoute = Discourse.RestrictedUserRoute.extend renderTemplate: -> @render into: 'user', outlet: 'userOutlet' setupController: (controller, user) ->