Skip to content

Commit

Permalink
Merge pull request #34 from UCL-INGI/fix_channel_unsubscription
Browse files Browse the repository at this point in the history
Allow superadmin to unsubscribe screens from a channel
  • Loading branch information
anthonygego authored Aug 2, 2022
2 parents fcb5ec6 + 415f665 commit 97c8dcb
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions ictv/pages/channel_page.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@

import ictv.flask.response as resp


logger = logging.getLogger('pages')


Expand Down Expand Up @@ -96,8 +95,10 @@ def render_page(self, channel):
return self.renderer.channeld(channel=channel, channel_type=type(channel).__name__, current_user=current_user,
bundles=ChannelBundle.select().filter(ChannelBundle.q.id != channel.id),
can_force_update=UserPermissions.administrator in current_user.highest_permission_level
or (type(channel) is PluginChannel and channel.has_contrib(current_user)),
last_update=last_update,vertical= vertical)
or (type(channel) is PluginChannel and channel.has_contrib(
current_user)),
last_update=last_update, vertical=vertical)


class SubscribeScreensPage(ICTVAuthPage):

Expand All @@ -108,25 +109,25 @@ def get(self, channel_id):
screens_of_current_user = Screen.get_visible_screens_of(current_user)
subscriptions = current_user.get_subscriptions_of_owned_screens()
last_by = {sub.screen.id:
{
'user': sub.created_by.readable_name,
'channel_name': sub.channel.name,
'plugin_channel': hasattr(sub.channel, 'plugin')
}
for sub in subscriptions if sub.channel.id == channel.id
{
'user': sub.created_by.readable_name,
'channel_name': sub.channel.name,
'plugin_channel': hasattr(sub.channel, 'plugin')
}
for sub in subscriptions if sub.channel.id == channel.id
}
screen_names = {s.id: s.name for s in screens_of_current_user}
return self.renderer.channel_subscriptions(
channel = channel,
possible_screens= screens_of_current_user,
user = current_user,
subscriptions = subscriptions,
last_by = last_by,
screen_names = screen_names
channel=channel,
possible_screens=screens_of_current_user,
user=current_user,
subscriptions=subscriptions,
last_by=last_by,
screen_names=screen_names
)

@PermissionGate.administrator
def post(self,channel_id):
def post(self, channel_id):
form = self.form
u = User.get(self.session['user']['id'])
subscribed = []
Expand All @@ -153,12 +154,12 @@ def post(self,channel_id):
try:
channel = Channel.get(channelid)
if not channel.can_subscribe(u):
raise self.forbidden(message="You're not allow to do that")
raise resp.forbidden(message="You're not allow to do that")
screen = Screen.get(screenid)
if not u in screen.owners:
raise self.forbidden(message="You're not allow to do that")
#sub true -> New subscription
#sub false -> Remove subscription
if not (u in screen.owners or u.super_admin):
raise resp.forbidden(message="You're not allow to do that")
# sub true -> New subscription
# sub false -> Remove subscription
if sub:
screen.subscribe_to(u, channel)
subscribed.append(str(channel.id))
Expand Down Expand Up @@ -201,9 +202,11 @@ def get(self, id, user_id):
user_id = int(user_id)
user = User.get(user_id)

st = "You just receive a request of subscription for channel " + chan.name + ". Could you please subscribe " + str(user.fullname) + " (" + user.email + ") to this channel."
st = "You just receive a request of subscription for channel " + chan.name + ". Could you please subscribe " + str(
user.fullname) + " (" + user.email + ") to this channel."
for admin in chan.get_admins():
web.sendmail(web.config.smtp_sendername, admin.email, 'Request for subscription to a channel', st, headers={'Content-Type': 'text/html;charset=utf-8'})
web.sendmail(web.config.smtp_sendername, admin.email, 'Request for subscription to a channel', st,
headers={'Content-Type': 'text/html;charset=utf-8'})
resp.seeother('/channels')


Expand Down

0 comments on commit 97c8dcb

Please sign in to comment.