source: binary-improvements/webserver/js/permissions.js@ 344

Last change on this file since 344 was 339, checked in by alloc, 6 years ago

Fixed: Permissions not properly applying anymore due to case sensitivity

File size: 1.7 KB
Line 
1var userdata = false;
2
3function InitPermissions () {
4 $.getJSON( "../userstatus")
5 .done(function(data) {
6 userdata = data;
7
8 var userdataDiv = $("#userstate");
9 if (userdata.loggedin == true) {
10 var data = userdataDiv.children ("#userstate_loggedin");
11 data.attr ("style", "display: block");
12 data.children ("#username").attr ("href", "http://steamcommunity.com/profiles/" + userdata.username);
13 data.children ("#username").html (userdata.username);
14 } else {
15 var data = userdataDiv.children ("#userstate_loggedout");
16 data.attr ("style", "display: block");
17 }
18
19 if (HasPermission ("webapi.getstats")) {
20 $("#serverstats").attr ("style", "display: block");
21 }
22
23 if (HasPermission ("web.map")) {
24 StartMapModule ();
25 }
26 if (HasPermission ("webapi.getlog")) {
27 StartLogModule ();
28 }
29 if (HasPermission ("webapi.getplayerlist")) {
30 StartPlayersModule ();
31 }
32
33 if (HasPermission ("webapi.getwebuiupdates")) {
34 StartUIUpdatesModule ();
35 } else if (HasPermission ("webapi.getstats")) {
36 StartStatsModule ();
37 }
38
39 tabs.tabbedContent ("applyPermissions");
40
41 })
42 .fail(function(jqxhr, textStatus, error) {
43 console.log("Error fetching user data");
44 })
45 .always(function () {
46 if (PermissionCount () == 0) {
47 $("#nopermissionwarning").attr ("style", "display: block");
48 }
49 })
50}
51
52function HasPermission (modulename) {
53 for (var i = 0; i < userdata.permissions.length; i++) {
54 if (userdata.permissions [i].module.toUpperCase() == modulename.toUpperCase()) {
55 return userdata.permissions [i].allowed;
56 }
57 }
58 return false;
59}
60
61function PermissionCount () {
62 var cnt = 0;
63 for (var i = 0; i < userdata.permissions.length; i++) {
64 if (userdata.permissions [i].allowed) cnt++;
65 }
66 return cnt;
67}
68
Note: See TracBrowser for help on using the repository browser.