(function () { 'use strict'; var serviceId = 'rolesAdminService'; angular.module('rolesAdmin').factory(serviceId, ['user', '$location', rolesAdminService]); function rolesAdminService(user, $location) { var service = { createBlankRole: createBlankRole, setEditingRole: setEditingRole, getEditingRole: getEditingRole, setMyRoles: setMyRoles, getMyRoles: getMyRoles, setActiveRole: setActiveRole, getActiveRole: getActiveRole, fnChecker: roleFunctionChecker, parentShortCodes: parentFunctionShortCodes, childShortCodes: childFunctionShortCodes }; // The role which the user has selected to edit. var editingRole; // The user's actual active role. var activeRole; // The collection of the user's avaialbe roles. var myRoles; // These just make the code a bit neater when we have to check against shortCodes. var parentFnCodes = { users: 'manage_users', forms: 'manage_forms', activities: 'manage_activities', badges: 'manage_badges', frameworks: 'manage_frameworks', progress: 'manage_progress', apprenticeships: 'manage_apprenticeships', grading: 'manage_grading', assignments: 'manage_assignments', tasks: 'manage_tasks', showcaseInbox: 'manage_showcaseinbox', showboards: 'manage_showboards', subscriptions: 'manage_subscriptions', organisations: 'manage_organisations', employers: 'manage_employers', rules: 'manage_rules', workflows: 'manage_workflows', badgeDashboard: 'access_badges_dashboard', badgeReporting: 'access_badge_reporting', backpack: 'access_backpack', collections: 'access_collections', townSignatures: 'access_town_signatures', analytics: 'analytics', interventions: 'access_interventions', forecasting: 'forecasting', regionstowns: 'access_regionstowns', myforms: 'access_myforms', tutorials: 'access_tutorials', maybedashboard: 'access_maybedashboard', } var childFnCodes = { usersOrgsAccess: 'users_organisations_access', usersAccess: 'users_users_access', usersRolesAllocate: 'roles_allocate', formStandards: 'form_standards_access', formReflections: 'form_reflections_access', formGoals: 'form_goals_access', activitiesManage: 'activities_manage', activitiesAdd: 'activities_add', activitiesView: 'activities_view', badgesDashboard: 'access_badges_dashboard', badgeGraphics: 'badges_graphics_access', badgeBadges: 'badges_badges_access', badgeIssue: 'badges_issue_access', badgeIssuer: 'badges_issuer_access', badgesReporting: 'badges_reporting_access', accessReviewClaims: 'badges_claimsreview_access', accessCreateClaims: 'badges_claimscreate_access', frameworksCreate: 'frameworks_create_access', progressTemplates: 'progress_templates', progressWorkflows: 'progress_workflows', progressViews: 'progress_views', progressEnagement: 'progress_engagement', progressViewsMark: 'progress_views_mark', progressViewsComment: 'progress_views_comment', apprenticeshipsAccess: 'apprenticeships_manage_access', apprenticeshipsCreate: 'apprenticeships_manage_create', apprenticeshipsDelete: 'apprenticeships_manage_delete', apprenticeshipsReporting: 'apprenticeships_reporting_access', gradingManage: 'grading_manage', tasksDefine: 'tasks_define', tasksAssign: 'tasks_assign', tasksActive: 'tasks_active', showcaseInboxShowcases: 'showcaseinbox_showcases', showboardsManage: 'showboards_manage', analyticsTownSignature: 'analytics_town_signature', analyticsTownFootfall: 'analytics_town_footfall', analyticsTownDailyFootfall: 'analytics_town_dailyfootfall', analyticsTownCompareFootfall: 'analytics_town_comparefootfall', analyticsTownEconomies: 'analytics_town_economies', analyticsTownMap: 'analytics_town_map', analyticsTownData: 'analytics_town_data', analyticsManualCounts: 'analytics_manual_counts', analyticsRegionFootfall: 'analytics_region_footfall', analyticsRegionDailyFootfall: 'analytics_region_dailyfootfall', analyticsRegionMap: 'analytics_region_map', forecastingTownForecast: 'forecasting_town_forecast', forecastingTownPeerGroup: 'forecasting_town_peergroup', forecastingChangingSignature: 'forecasting_changingsignature', workflowsDefinitions: 'workflows_definitions_access', workflowsDeployments: 'workflows_deployments_access', workflowsReporting: 'workflows_reporting_access', } return service; //TODO: Rename currentRole -> editingRole or something like that. // Function to set the current role function setEditingRole(role) { editingRole = role; } // Function to get the currently stored role function getEditingRole(role) { return editingRole; } // Function to create a new blank role function createBlankRole() { return { name: '', description: '', displayName: '', roleFunctions: [], makeAvailable: true, isActive: true }; } // Active role is used to hold the user's current active role. function setActiveRole(role) { activeRole = role; } function getActiveRole() { return activeRole; } // My roles is the array of the current user's available roles. function setMyRoles(roles) { myRoles = roles; } function getMyRoles() { return myRoles; } // short code checking object which contains functions for checking what type of role function the input is. function roleFunctionChecker() { return { isUsers: function (fn) { return fn.shortCode == childFnCodes.usersAccess || fn.shortCode == childFnCodes.usersOrgsAccess; }, isForms: function (fn) { return fn.shortCode == childFnCodes.formStandards || fn.shortCode == childFnCodes.formReflections || fn.shortCode == childFnCodes.formGoals; }, isActivities: function (fn) { return fn.shortCode == childFnCodes.activitiesManage || fn.shortCode == childFnCodes.activitiesAdd || fn.shortCode == childFnCodes.activitiesView; }, isBadges: function (fn) { return fn.shortCode == childFnCodes.badgesManage || fn.shortCode == childFnCodes.badgeGraphics || fn.shortCode == childFnCodes.badgeBadges || fn.shortCode == childFnCodes.badgeIssue || fn.shortCode == childFnCodes.badgeIssuer || fn.shortCode == childFnCodes.accessReviewClaims || fn.shortCode == childFnCodes.accessCreateClaims; }, isFrameworks: function (fn) { return fn.shortCode == childFnCodes.frameworksCreate; }, isProgress: function (fn) { return fn.shortCode == childFnCodes.progressTemplates || fn.shortCode == childFnCodes.progressWorkflows || fn.shortCode == childFnCodes.progressViews || fn.shortCode == childFnCodes.progressEngagement || fn.shortCode == childFnCodes.progressViewsMark || fn.shortCode == childFnCodes.progressViewsComment; }, isApprenticeships: function (fn) { return fn.shortCode == childFnCodes.apprenticeshipsAccess || fn.shortCode == childFnCodes.apprenticeshipsCreate || fn.shortCode == childFnCodes.apprenticeshipsDelete || fn.shortCode == childFnCodes.apprenticeshipsReporting; }, isGrading: function (fn) { return fn.shortCode == childFnCodes.gradingManage; }, isTasks: function (fn) { return fn.shortCode == childFnCodes.tasksDefine || fn.shortCode == childFnCodes.tasksAssign || fn.shortCode == childFnCodes.tasksActive; }, isShowcaseInbox: function (fn) { return fn.shortCode == childFnCodes.showcaseInboxShowcases; }, isShowboards: function (fn) { return fn.shortCode == childFnCodes.showboardsManage; }, isSubscription: function (fn) { return fn.shortCode == parentFnCodes.subscriptions; }, isBadgesDashboard: function (fn) { return fn.shortCode == parentFnCodes.badgeDashboard; }, isOrganisations: function (fn) { return fn.shortCode == parentFnCodes.organisations; }, isEmployers: function (fn) { return fn.shortCode == parentFnCodes.employers; }, isRules: function (fn) { return fn.shortCode == parentFnCodes.rules; }, isWorkflows: function (fn) { return fn.shortCode == childFnCodes.workflowsDefinitions || fn.shortCode == childFnCodes.workflowsDeployments || fn.shortCode == childFnCodes.workflowsReporting; }, isBadgeReporting: function (fn) { return fn.shortCode == childFnCodes.badgesReporting; }, isBackpack: function (fn) { return fn.shortCode == parentFnCodes.backpack; }, isCollections: function (fn) { return fn.shortCode == parentFnCodes.collections; }, isTownSignatures: function (fn) { return fn.shortCode == parentFnCodes.townSignatures; }, isAnalytics: function (fn) { return fn.shortCode == childFnCodes.analyticsTownSignature || fn.shortCode == childFnCodes.analyticsTownFootfall || fn.shortCode == childFnCodes.analyticsTownDailyFootfall || fn.shortCode == childFnCodes.analyticsTownCompareFootfall || fn.shortCode == childFnCodes.analyticsTownEconomies || fn.shortCode == childFnCodes.analyticsTownMap || fn.shortCode == childFnCodes.analyticsTownData || fn.shortCode == childFnCodes.analyticsManualCounts || fn.shortCode == childFnCodes.analyticsRegionFootfall || fn.shortCode == childFnCodes.analyticsRegionDailyFootfall || fn.shortCode == childFnCodes.analyticsRegionMap; }, isInterventions: function (fn) { return fn.shortCode == parentFnCodes.interventions; }, isForecasting: function (fn) { return fn.shortCode == childFnCodes.forecastingTownForecast || fn.shortCode == childFnCodes.forecastingTownPeerGroup || fn.shortCode == childFnCodes.forecastingChangingSignature; }, isRegionsTowns: function (fn) { return fn.shortCode == parentFnCodes.regionstowns; }, isMyForms: function (fn) { return fn.shortCode == parentFnCodes.myforms; }, isTutorials: function (fn) { return fn.shortCode == parentFnCodes.tutorials; }, isMaybeDashboard: function (fn) { return fn.shortCode == parentFnCodes.maybedashboard; }, } } function parentFunctionShortCodes() { return parentFnCodes; } function childFunctionShortCodes() { return childFnCodes; } } })();