On-Call Schedule - Limit Access on "All On-Call Schedules"

kristenankeny
Tera Guru

We need to dynamically filter the tiles that show on the All On-Call Schedules tab on $oc_groups. We have tried both ACLs against cmn_rota and updating sn_on_call_now.app UI Script, but neither solution has any impact on the results for All On-Call Schedules. In case it helps, these are the script changes that were made for the sn_on_call_now.app (adding in the service for AllFilter). The filter isn't important, I'm just testing a possible solution in a personal dev before we implement the real filter we need to apply.

 

angular.module("sn.on_call.now.groups").service("GroupFilterService", ["$window", "PinnedService", "TextSearchService", "ManagedBelongService","AllFilter", function($window, PinnedService, TextSearchService, ManagedBelongService,AllFilter) {
	var groupFilterService = this;

	var _allGroups = [];
	function getAllGroups(groups) {
		if (_allGroups.length !== groups.length)
			_allGroups = groups.slice();
		return _allGroups;
	}

	groupFilterService.getFilteredGroups = function(groups, filterBy, textSearch, textSearchType, pinnedGroups) {
		var filteredGroups = [];
//filteredGroups = getAllGroups(groups);
		if (filterBy === "all")
			
			filteredGroups = AllFilter.getFilteredGroups(groups, $window.NOW.user_id || "");
		else if (filterBy === "manage_belong")
			filteredGroups = ManagedBelongService.getFilteredGroups(groups, $window.NOW.user_id || "");
		else if (filterBy === "pinned")
			filteredGroups = PinnedService.getFilteredGroups(groups, pinnedGroups);
		else
			filteredGroups = [];

		return TextSearchService.getFilteredGroups(filteredGroups, textSearch, textSearchType);
	};
}]);


///ADDING:
angular.module("sn.on_call.now.groups").service("AllFilter",[function(){
	var allFilter = this;
	var _all = [];
	var _groups = [];
	
	allFilter.getFilteredGroups = function(groups, activeUserID){
		if(!groups || groups.length < 1 || !activeUserID){
			_all = [];
			_groups = [];
		}
		else if(_groups.length !== groups.length){
			_groups = groups.concat(_groups);
			var allowedGroups = [];
			groups.filter(function(group){
				var types = group.type;
				if(types.indexOf('74af88c6c611227d0066386e74dc853d') != -1){
					allowedGroups.push(group);
				}
			});
			_all = allowedGroups;
		}
		return _all;
	};
}]);

//...many lines edited out

angular.module("sn.on_call.now.groups").controller("GroupOnCallController", ["$scope", "GroupService", "GroupFilterService", "ManagedBelongService", "PinnedService", "TextSearchService", "$window", "$location", "userPreferences", "getTemplateUrl", "i18n", "$timeout", "snConnectService", "HighlightService", "$injector", "$sce", "$interval", "KeyCode", "AllFilter" , function($scope, GroupService, GroupFilterService, ManagedBelongService, PinnedService, TextSearchService, $window, $location, userPreferences, getTemplateUrl, i18n, $timeout, snConnectService, HighlightService, $injector, $sce, $interval, KeyCode, AllFilter) {

//...many lines edited out

function _splashScreenVisibility() {
		groupOnCallCtrl.isWizardBtnPrimary = groupOnCallCtrl.pinnedGroups.length === 0;
		groupOnCallCtrl.showPinnedSplashMsg = (groupOnCallCtrl.groupFilter === "pinned" && PinnedService.getFilteredGroups(groupOnCallCtrl.groups, groupOnCallCtrl.pinnedGroups).length === 0);
		groupOnCallCtrl.showManageBelongSplashMsg = (groupOnCallCtrl.groupFilter === "manage_belong" && ManagedBelongService.getFilteredGroups(groupOnCallCtrl.groups, $window.NOW.user_id).length === 0);
		//groupOnCallCtrl.showAllSplashMsg = (groupOnCallCtrl.groupFilter === "all" && groupOnCallCtrl.groups.length === 0);
		groupOnCallCtrl.showAllSplashMsg = (groupOnCallCtrl.groupFilter === "all" && AllFilter.getFilteredGroups(groupOnCallCtrl.group, $window.NOW.user_id).length === 0);
		groupOnCallCtrl.textSearchReadOnly = groupOnCallCtrl.showPinnedSplashMsg || groupOnCallCtrl.showManageBelongSplashMsg || groupOnCallCtrl.showAllSplashMsg;
		if (groupOnCallCtrl.textSearchReadOnly)
			groupOnCallCtrl.textSearch = "";
		groupOnCallCtrl.showOnCallRotas = (groupOnCallCtrl.groups.length > 0 && !groupOnCallCtrl.showPinnedSplashMsg && !groupOnCallCtrl.showManageBelongSplashMsg && !groupOnCallCtrl.showAllSplashMsg);

		// Strip out extraneous tabindex
		$timeout(function() {
			angular.element(".sub-avatar").each(function() { angular.element(this).removeAttr("tabindex"); });
		}, 0);
	}

//...many lines edited out

}]);
1 ACCEPTED SOLUTION

kristenankeny
Tera Guru

After putting the before query business rule in our company dev instance, we found that it is being applied both in the $oc_groups and $oc_workbench and $oc pages in all areas where they can change the on-call schedule that they are looking at. 

View solution in original post

6 REPLIES 6

Hi Kristen, Can you please share the before query business rule snippet through which you were able to do this change?

Hey there, did you ever get this set up? Our before query rule is not applying.