Skip to content

Commit 578dd45

Browse files
superuser sees all - #347
1 parent d2b465e commit 578dd45

File tree

8 files changed

+171
-66
lines changed

8 files changed

+171
-66
lines changed

rootio/configuration/views.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
from ..radio.models import Station, Network
2020
from ..user.models import User
2121
from ..utils import upload_to_s3, make_dir, save_uploaded_file, jquery_dt_paginator
22+
from rootio.user import ADMIN
2223

2324
configuration = Blueprint('configuration', __name__, url_prefix='/configuration')
2425

@@ -27,7 +28,10 @@
2728
@login_required
2829
def index():
2930
# get all the user's networks and their stations
30-
networks = Network.query.outerjoin(Station).join(User, Network.networkusers).filter(User.id == current_user.id).all()
31+
if current_user.role_code == ADMIN:
32+
networks = Network.query.outerjoin(Station).join(User, Network.networkusers).all()
33+
else:
34+
networks = Network.query.outerjoin(Station).join(User, Network.networkusers).filter(User.id == current_user.id).all()
3135
stations = []
3236

3337
for network in networks:
@@ -76,7 +80,7 @@ def tts():
7680
@configuration.route('/telephony/', methods=['GET', 'POST'])
7781
@login_required
7882
def telephony():
79-
stations = Station.query.join(Network).join(User, Network.networkusers).filter(User.id == current_user.id).all()
83+
stations = Station.get_stations(current_user)
8084
return render_template('configuration/stations_telephony.html', stations=stations)
8185

8286

@@ -138,7 +142,7 @@ def sip_configuration(station_id):
138142
@configuration.route('/sip_telephony', methods=['GET', 'POST'])
139143
@login_required
140144
def sip_telephony():
141-
stations = Station.query.join(Network).join(User, Network.networkusers).filter(User.id == current_user.id).all()
145+
stations = Station.get_stations(current_user)
142146
return render_template('configuration/sip_telephony.html', stations=stations)
143147

144148

@@ -161,14 +165,14 @@ def station_audio_level(station_id):
161165
@configuration.route('/station_audio_levels', methods=['GET'])
162166
@login_required
163167
def station_audio_levels():
164-
stations = Station.query.join(Network).join(User, Network.networkusers).filter(User.id == current_user.id).all()
168+
stations = Station.get_stations(current_user)
165169
return render_template('configuration/station_audio_levels.html', stations=stations, active='stations')
166170

167171

168172
@configuration.route('/ivr_menus', methods=['GET', 'POST'])
169173
@login_required
170174
def ivr_menus():
171-
stations = Station.query.join(Network).join(User, Network.networkusers).filter(User.id == current_user.id).all()
175+
stations = Station.get_stations(current_user)
172176

173177
station_data = []
174178
for station in stations:
@@ -270,7 +274,7 @@ def ivr_menu():
270274
@configuration.route('/tts_settings', methods=['GET', 'POST'])
271275
@login_required
272276
def tts_settings():
273-
stations = Station.query.join(Network).join(User, Network.networkusers).filter(User.id == current_user.id).all()
277+
stations = Station.get_stations(current_user)
274278
return render_template('configuration/tts_settings.html', stations=stations)
275279

276280

@@ -293,7 +297,7 @@ def tts_setting(station_id):
293297
@configuration.route('/synchronization_settings', methods=['GET', 'POST'])
294298
@login_required
295299
def synchronization_settings():
296-
stations = Station.query.join(Network).join(User, Network.networkusers).filter(User.id == current_user.id).all()
300+
stations = Station.get_stations(current_user)
297301
return render_template('configuration/synchronization_settings.html', stations=stations)
298302

299303

@@ -316,7 +320,7 @@ def synchronization_setting(station_id):
316320
@configuration.route('/content', methods=['GET'])
317321
@login_required
318322
def content_settings():
319-
stations = Station.query.join(Network).join(User, Network.networkusers).filter(User.id == current_user.id).all()
323+
stations = Station.get_stations(current_user)
320324
return render_template('configuration/content_settings.html', stations=stations)
321325

322326

@@ -339,7 +343,7 @@ def content_setting(station_id):
339343
@configuration.route('/voice_prompts', methods=['GET', 'POST'])
340344
@login_required
341345
def voice_prompts():
342-
stations = Station.query.join(Network).join(User, Network.networkusers).filter(User.id == current_user.id).all()
346+
stations = Station.get_stations(current_user)
343347

344348
station_data = []
345349
for station in stations:

rootio/content/views.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
from ..radio.models import ContentType, Person, Network, Station
1919
from ..user.models import User
2020
from ..utils import jquery_dt_paginator, upload_to_s3, make_dir, save_uploaded_file
21+
from rootio.user import ADMIN
2122

2223
ALLOWED_EXTENSIONS = set(['wav', 'mp3'])
2324

@@ -283,7 +284,10 @@ def track_toggle_play(track_id):
283284
@content.route('/hosts/')
284285
@login_required
285286
def list_hosts():
286-
hosts = Person.query.join(Person, Network.people).join(User, Network.networkusers).filter(
287+
if current_user.role_code == ADMIN:
288+
hosts = Person.query.join(Person, Network.people).join(User, Network.networkusers).all()
289+
else:
290+
hosts = Person.query.join(Person, Network.people).join(User, Network.networkusers).filter(
287291
User.id == current_user.id).all()
288292
return render_template('content/content_hosts.html', hosts=hosts)
289293

@@ -363,7 +367,10 @@ def host_delete(host_id):
363367
@content.route('/community_content/', methods=['GET', 'POST'])
364368
@login_required
365369
def community_content():
366-
community_contents = CommunityContent.query.join(Station).join(Network).join(User, Network.networkusers).filter(
370+
if current_user.role_code == ADMIN:
371+
community_contents = CommunityContent.query.join(Station).join(Network).join(User, Network.networkusers).all()
372+
else:
373+
community_contents = CommunityContent.query.join(Station).join(Network).join(User, Network.networkusers).filter(
367374
User.id == current_user.id).all()
368375
return render_template('content/community_content.html', community_contents=community_contents)
369376

rootio/radio/models.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,15 @@ class Station(BaseMixin, db.Model):
157157
broadcast_ip = db.Column(db.String(16))
158158
broadcast_port = db.Column(db.String(16))
159159

160+
@classmethod
161+
def get_stations(cls, current_user):
162+
from rootio.user import ADMIN
163+
from ..user.models import User
164+
165+
if current_user.role_code == ADMIN:
166+
return Station.query.join(Network).join(User, Network.networkusers).all()
167+
else:
168+
return Station.query.join(Network).join(User, Network.networkusers).filter(User.id == current_user.id).all()
160169
def init(self):
161170
# load dummy program
162171
# init state machine

rootio/radio/views.py

Lines changed: 100 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
from ..extensions import db, csrf
3232
from ..user.models import User, RootioUser
3333
from ..utils import error_dict, fk_lookup_form_data, format_log_line, events_action_display_map
34+
from rootio.user import ADMIN
3435

3536
radio = Blueprint('radio', __name__, url_prefix='/radio')
3637

@@ -39,7 +40,10 @@
3940
@login_required
4041
def index():
4142
# get all the user's networks and their stations
42-
networks = Network.query.outerjoin(Station).join(User, Network.networkusers).filter(User.id == current_user.id).all()
43+
if current_user.role_code == ADMIN:
44+
networks = Network.query.outerjoin(Station).join(User, Network.networkusers).all()
45+
else:
46+
networks = Network.query.outerjoin(Station).join(User, Network.networkusers).filter(User.id == current_user.id).all()
4347
return render_template('radio/index.html', networks=networks, userid=current_user.id, now=datetime.now)
4448

4549

@@ -83,7 +87,7 @@ def network_add():
8387
@radio.route('/station/', methods=['GET'])
8488
@login_required
8589
def list_stations():
86-
stations = Station.query.join(Network).join(User, Network.networkusers).filter(User.id == current_user.id).all()
90+
stations = Station.get_stations(current_user)
8791
# stations = Station.query.join(Network).join(User).filter(User.id == current_user.id).all()
8892
return render_template('radio/stations.html', stations=stations, active='stations')
8993

@@ -134,7 +138,10 @@ def station_add():
134138
@radio.route('/program/', methods=['GET'])
135139
@login_required
136140
def programs():
137-
programs = Program.query.join(Program, Network.programs).join(User, Network.networkusers).filter(
141+
if current_user.role_code == ADMIN:
142+
programs = Program.query.join(Program, Network.programs).join(User, Network.networkusers).filter(Program.program_type_id != 2).all()
143+
else:
144+
programs = Program.query.join(Program, Network.programs).join(User, Network.networkusers).filter(
138145
User.id == current_user.id).filter(Program.program_type_id != 2).all()
139146
return render_template('radio/programs.html', programs=programs, active='programs')
140147

@@ -146,12 +153,22 @@ def program_definition(program_id):
146153
# form = ProgramForm(obj=program, program_structure="test", next=request.args.get('next'))
147154

148155
# hosts in my network
149-
hosts = Person.query.join(Person, Network.people).join(User, Network.networkusers).filter(
156+
if current_user.role_code == ADMIN:
157+
hosts = Person.query.join(Person, Network.people).join(User, Network.networkusers).all()
158+
else:
159+
hosts = Person.query.join(Person, Network.people).join(User, Network.networkusers).filter(
150160
User.id == current_user.id).all()
151161
news = ContentTrack.query.join(ContentType).filter(ContentType.name == "News").all()
152162
ads = ContentTrack.query.join(ContentType).filter(ContentType.name == "Advertisements").all()
153163

154-
medias = ContentTrack.query.join(User, Network.networkusers)\
164+
if current_user.role_code == ADMIN:
165+
medias = ContentTrack.query.join(User, Network.networkusers)\
166+
.join(ContentTrack, ContentType)\
167+
.filter(ContentType.name == "Media")\
168+
.filter(ContentTrack.deleted != True)\
169+
.all()
170+
else:
171+
medias = ContentTrack.query.join(User, Network.networkusers)\
155172
.filter(User.id == current_user.id)\
156173
.join(ContentTrack, ContentType)\
157174
.filter(ContentType.name == "Media")\
@@ -197,34 +214,59 @@ def program_add():
197214
form = ProgramForm(request.form)
198215
program = None
199216

200-
# hosts in my network
201-
hosts = Person.query.join(Person, Network.people).join(User, Network.networkusers)\
202-
.filter(User.id == current_user.id)\
203-
.all()
204-
news = ContentTrack.query.join(User, Network.networkusers)\
205-
.filter(User.id == current_user.id)\
206-
.join(ContentTrack, ContentType)\
207-
.filter(ContentType.name == "News")\
208-
.filter(ContentTrack.deleted != True)\
209-
.all()
210-
ads = ContentTrack.query.join(User, Network.networkusers)\
211-
.filter(User.id == current_user.id)\
212-
.join(ContentTrack, ContentType)\
213-
.filter(ContentType.name == "Advertisements")\
214-
.filter(ContentTrack.deleted != True)\
215-
.all()
216-
217-
medias = ContentTrack.query.join(User, Network.networkusers)\
218-
.filter(User.id == current_user.id)\
219-
.join(ContentTrack, ContentType)\
220-
.filter(ContentType.name == "Media")\
221-
.filter(ContentTrack.deleted != True)\
222-
.all()
223-
224-
225-
podcasts = ContentPodcast.query.join(User, Network.networkusers)\
226-
.filter(User.id == current_user.id)\
227-
.all()
217+
if current_user.role_code == ADMIN:
218+
# hosts in my network
219+
hosts = Person.query.join(Person, Network.people).join(User, Network.networkusers)\
220+
.all()
221+
news = ContentTrack.query.join(User, Network.networkusers)\
222+
.join(ContentTrack, ContentType)\
223+
.filter(ContentType.name == "News")\
224+
.filter(ContentTrack.deleted != True)\
225+
.all()
226+
ads = ContentTrack.query.join(User, Network.networkusers)\
227+
.join(ContentTrack, ContentType)\
228+
.filter(ContentType.name == "Advertisements")\
229+
.filter(ContentTrack.deleted != True)\
230+
.all()
231+
232+
medias = ContentTrack.query.join(User, Network.networkusers)\
233+
.join(ContentTrack, ContentType)\
234+
.filter(ContentType.name == "Media")\
235+
.filter(ContentTrack.deleted != True)\
236+
.all()
237+
238+
239+
podcasts = ContentPodcast.query.join(User, Network.networkusers)\
240+
.all()
241+
else:
242+
# hosts in my network
243+
hosts = Person.query.join(Person, Network.people).join(User, Network.networkusers)\
244+
.filter(User.id == current_user.id)\
245+
.all()
246+
news = ContentTrack.query.join(User, Network.networkusers)\
247+
.filter(User.id == current_user.id)\
248+
.join(ContentTrack, ContentType)\
249+
.filter(ContentType.name == "News")\
250+
.filter(ContentTrack.deleted != True)\
251+
.all()
252+
ads = ContentTrack.query.join(User, Network.networkusers)\
253+
.filter(User.id == current_user.id)\
254+
.join(ContentTrack, ContentType)\
255+
.filter(ContentType.name == "Advertisements")\
256+
.filter(ContentTrack.deleted != True)\
257+
.all()
258+
259+
medias = ContentTrack.query.join(User, Network.networkusers)\
260+
.filter(User.id == current_user.id)\
261+
.join(ContentTrack, ContentType)\
262+
.filter(ContentType.name == "Media")\
263+
.filter(ContentTrack.deleted != True)\
264+
.all()
265+
266+
267+
podcasts = ContentPodcast.query.join(User, Network.networkusers)\
268+
.filter(User.id == current_user.id)\
269+
.all()
228270
community_contents = {"data": [{"type": "Ads", "category_id": "1"}, {"type": "Announcements", "category_id": "2"},
229271
{"type": "Greetings", "category_id": "3"}]}
230272

@@ -265,7 +307,10 @@ def program_delete(program_id):
265307
@radio.route('/music_program/', methods=['GET'])
266308
@login_required
267309
def list_music_programs():
268-
music_programs = Program.query.join(Program, Network.programs).join(User, Network.networkusers).filter(
310+
if current_user.role_code == ADMIN:
311+
music_programs = Program.query.join(Program, Network.programs).join(User, Network.networkusers).filter(Program.program_type_id == 2).all()
312+
else:
313+
music_programs = Program.query.join(Program, Network.programs).join(User, Network.networkusers).filter(
269314
User.id == current_user.id).filter(Program.program_type_id == 2).all()
270315
return render_template('radio/music_programs.html', music_programs=music_programs, active='programs')
271316

@@ -276,11 +321,15 @@ def music_program_add():
276321
form = ProgramForm(request.form)
277322
program = None
278323

279-
# Playlists and streams in my network
280-
playlists = ContentMusicPlaylist.query.join(Station).join(Network).join(User, Network.networkusers).filter(
281-
User.id == current_user.id).filter(ContentMusicPlaylist.deleted != True).all() # Playlist->Station->Network->user
282-
streams = ContentStream.query.join(User, Network.networkusers).filter(
283-
User.id == current_user.id).all() # created by -> user -> Network
324+
if current_user.role_code == ADMIN:
325+
playlists = ContentMusicPlaylist.query.join(Station).join(Network).join(User, Network.networkusers).filter(ContentMusicPlaylist.deleted != True).all() # Playlist->Station->Network->user
326+
streams = ContentStream.query.join(User, Network.networkusers).filter(
327+
User.id == current_user.id).all() # created by -> user -> Network
328+
else:
329+
# Playlists and streams in my network
330+
playlists = ContentMusicPlaylist.query.join(Station).join(Network).join(User, Network.networkusers).filter(ContentMusicPlaylist.deleted != True).all() # Playlist->Station->Network->user
331+
streams = ContentStream.query.join(User, Network.networkusers).filter(
332+
User.id == current_user.id).all() # created by -> user -> Network
284333

285334
if form.validate_on_submit():
286335
cleaned_data = form.data # make a copy
@@ -303,9 +352,13 @@ def music_program_add():
303352
def music_program_definition(music_program_id):
304353
music_program = Program.query.filter_by(id=music_program_id).first_or_404()
305354

306-
# TODO: Filter these by network
307-
playlists = ContentMusicPlaylist.query.join(Station).join(Network).join(User, Network.networkusers).filter(User.id == current_user.id).all() #Playlist->Station->Network->user
308-
streams = ContentStream.query.join(User, Network.networkusers).filter(User.id == current_user.id).all() # created by -> user -> Network
355+
if current_user.role_code == ADMIN:
356+
playlists = ContentMusicPlaylist.query.join(Station).join(Network).join(User, Network.networkusers).all() #Playlist->Station->Network->user
357+
streams = ContentStream.query.join(User, Network.networkusers).all() # created by -> user -> Network
358+
else:
359+
# TODO: Filter these by network
360+
playlists = ContentMusicPlaylist.query.join(Station).join(Network).join(User, Network.networkusers).filter(User.id == current_user.id).all() #Playlist->Station->Network->user
361+
streams = ContentStream.query.join(User, Network.networkusers).filter(User.id == current_user.id).all() # created by -> user -> Network
309362

310363
# render the program structure
311364
action_names = []
@@ -692,7 +745,7 @@ def station_logs(station_id):
692745
@login_required
693746
def schedule():
694747
# TODO, if user is authorized to view only one station, redirect them there
695-
stations = Station.query.join(Network).join(User, Network.networkusers).filter(User.id == current_user.id).all()
748+
stations = Station.get_stations(current_user)
696749
# stations = Station.query.order_by('name').all()
697750

698751
return render_template('radio/schedules.html',
@@ -717,7 +770,10 @@ def schedule_station(station_id):
717770

718771
form = ScheduleProgramForm()
719772

720-
all_programs = Program.query.join(Program, Network.programs).join(User, Network.networkusers).filter(
773+
if current_user.role_code == ADMIN:
774+
all_programs = Program.query.join(Program, Network.programs).join(User, Network.networkusers).all()
775+
else:
776+
all_programs = Program.query.join(Program, Network.programs).join(User, Network.networkusers).filter(
721777
User.id == current_user.id).all()
722778
# TODO: filter by language?
723779

0 commit comments

Comments
 (0)