Best JavaScript code snippet using devicefarmer-stf
groups.js
Source:groups.js
1load(identityServer.getProjectLocation() + "/script/util/util.js");2var organization = openidm.read("config/custom/departments");3function resolveGroupsForDepartment(departmentId) {4 var assignedGroups = [];5 if(!!departmentId && departmentId.length > 0) {6 var current = organization;7 for(var i=0;i<departmentId.length;i++) {8 if(!!current && !!current[departmentId[i]]) {9 var groups = current[departmentId[i]].groups;10 if(!!groups) {11 for(var g=0;g<groups.length;g++) {12 // Append mailing list group full DN to assignedGroups13 assignedGroups.push("CN=" + groups[g] + "," + mailGroupsBaseDN);14 }15 }16 17 if(!!current[departmentId[i]].children) {18 current = current[departmentId[i]].children;19 } else {20 current = null;21 }22 }23 } 24 }25 26 return assignedGroups;27}28function resolveGroupsForResource(resourceType, departmentIds) {29 var resolvedGroups = ad.groups['common'];30 // Resolve all groups for employees31 var employeeGroups = ad.groups['employees'];32 for(var i=0;i<employeeGroups.length;i++) {33 resolvedGroups.push(employeeGroups[i]);34 }35 // Resolve groups for all departments the user is part of36 for(var i=0;i<departmentIds.length;i++) {37 var departmentGroups = resolveGroupsForDepartment(departmentIds[i]);38 for(var j=0;j<departmentGroups.length;j++) {39 resolvedGroups.push(departmentGroups[j]);40 }41 }42 43 return resolvedGroups;44}45// Returns _all_ groups defined in config/custom/departments, used to46// determine which groups the system should care about.47function getAllMailGroups(organization) {48 var mailGroups = [];49 for(var key in organization) {50 if(organization[key].hasOwnProperty("groups")) {51 var groups = organization[key].groups;52 for(var g=0;g<groups.length;g++) {53 mailGroups.push("CN=" + groups[g] + "," + mailGroupsBaseDN);54 }55 }56 57 var recurse = getAllMailGroups(organization[key]);58 for(var rg=0;rg<recurse.length;rg++) {59 mailGroups.push(recurse[rg]);60 }61 }62 63 return mailGroups;64}65function setGroups() {66 var groupList = resolveGroupsForResource(resourceType, departmentIds);67 var managedGroups = {};68 var assignedGroups = {};69 70 // Actions71 var addGroups = [];72 var removeGroups = [];73 // For lookup purposes. Lowercase group names.74 for(var i=0;i<groupList.length;i++) {75 assignedGroups[groupList[i].toLowerCase()] = 1;76 }77 78 if(isEmployee(resourceType)) {79 // For lookup purposes. Lowercase group names.80 for(var i=0;i<mailGroups.length;i++) {81 managedGroups[mailGroups[i].toLowerCase()] = 1;82 } 83 }84 85 // For lookup purposes. Lowercase group names.86 for(var i=0;i<groupList.length;i++) {87 managedGroups[groupList[i].toLowerCase()] = 1;88 }89 90 var memberOf = [];91 try {92 var existing = target.memberOf;93 if(!!existing) { memberOf = existing; }94 } catch(e) { }95 96 if(memberOf.length > 0) {97 var existingGroups = {};98 99 // Remove groups that the user is no longer assigned to and100 // which are managed by system. Groups to touch are:101 // 102 // - managedGroups resolved from static list of common103 // groups for all AD users (custom/config/ad/groups)104 // - dynamic groups defined in custom/config/departments105 for(var i=0;i<memberOf.length;i++) {106 existingGroups[memberOf[i].toLowerCase()] = 1;107 if(managedGroups.hasOwnProperty(memberOf[i].toLowerCase())) {108 if(!assignedGroups[memberOf[i].toLowerCase()]) {109 removeGroups.push(memberOf[i]);110 }111 }112 }113 114 // Add groups the user is assigned to, isn't already a member115 // of, and which are managed by system.116 for(var i=0;i<groupList.length;i++) {117 if(!existingGroups[groupList[i].toLowerCase()]) {118 addGroups.push(groupList[i]);119 }120 } 121 } else {122 // No existing groups.123 addGroups = groupList;124 }125 if(addGroups.length > 0) {126 logger.debug(logPrefix + "Adding groups for " + formatManaged(source) + ": " + addGroups);127 target.addGroups = addGroups;128 }129 130 if(removeGroups.length > 0) {131 logger.debug(logPrefix + "Removing groups for " + formatManaged(source) + ": " + removeGroups);132 target.removeGroups = removeGroups;133 }134}135// Set target.addGroups and/or target.removeGroups list attributes.136function setGroups(resourceType, departmentIds) {137 var groupList = resolveGroupsForResource(resourceType, departmentIds);138 var mailGroups = getAllMailGroups(organization);139 var managedGroups = {};140 var assignedGroups = {};141 142 // Actions143 var addGroups = [];144 var removeGroups = [];145 // For lookup purposes. Lowercase group names.146 for(var i=0;i<groupList.length;i++) {147 assignedGroups[groupList[i].toLowerCase()] = 1;148 }149 150 // For lookup purposes. Lowercase group names.151 for(var i=0;i<mailGroups.length;i++) {152 managedGroups[mailGroups[i].toLowerCase()] = 1;153 } 154 155 // For lookup purposes. Lowercase group names.156 for(var i=0;i<groupList.length;i++) {157 managedGroups[groupList[i].toLowerCase()] = 1;158 }159 160 var memberOf = [];161 try {162 var existing = target.memberOf;163 if(!!existing) { memberOf = existing; }164 } catch(e) { }165 166 if(memberOf.length > 0) {167 var existingGroups = {};168 169 // Remove groups that the user is no longer assigned to and170 // which are managed by system. Groups to touch are:171 // 172 // - managedGroups resolved from static list of common173 // groups for all AD users (custom/config/ad/groups)174 // - dynamic groups defined in custom/config/departments175 for(var i=0;i<memberOf.length;i++) {176 existingGroups[memberOf[i].toLowerCase()] = 1;177 if(managedGroups.hasOwnProperty(memberOf[i].toLowerCase())) {178 if(!assignedGroups[memberOf[i].toLowerCase()]) {179 removeGroups.push(memberOf[i]);180 }181 }182 }183 184 // Add groups the user is assigned to, isn't already a member185 // of, and which are managed by IDM.186 for(var i=0;i<groupList.length;i++) {187 if(!existingGroups[groupList[i].toLowerCase()]) {188 addGroups.push(groupList[i]);189 }190 } 191 } else {192 // No existing groups.193 addGroups = groupList;194 }195 if(addGroups.length > 0) {196 logger.debug(logPrefix + "Adding groups for " + formatManaged(source) + ": " + addGroups);197 target.addGroups = addGroups;198 }199 200 if(removeGroups.length > 0) {201 logger.debug(logPrefix + "Removing groups for " + formatManaged(source) + ": " + removeGroups);202 target.removeGroups = removeGroups;203 }204}205function removeMailGroup(resourceType, departmentIds) {206 var groupList = resolveGroupsForResource(resourceType, departmentIds);207 var managedGroups = {};208 var removeGroups = [];209 // For lookup purposes. Lowercase group names.210 for(var i=0;i<groupList.length;i++) {211 managedGroups[groupList[i].toLowerCase()] = 1;212 }213 var memberOf = [];214 try {215 var existing = target.memberOf;216 if(!!existing) { memberOf = existing; }217 } catch(e) { }218 if(memberOf.length > 0) {219 for(var i=0;i<memberOf.length;i++) {220 if(managedGroups.hasOwnProperty(memberOf[i].toLowerCase())) {221 if (memberOf[i].toLowerCase().indexOf("OU=MailLister".toLowerCase())>-1 && hasMetEndDate(source)) {222 logger.debug("[ad-on-update] Removing memberOf[i] = {}", memberOf[i] )223 removeGroups.push(memberOf[i]);224 }225 }226 }227 }228 if(removeGroups.length > 0) {229 logger.debug(logPrefix + "Removing groups for " + formatManaged(source) + ": " + removeGroups);230 target.removeGroups = removeGroups;231 }...
GroupCollection.js
Source:GroupCollection.js
1/**2 * @private3 */4Ext.define('Ext.util.GroupCollection', {5 extend: 'Ext.util.Collection',6 7 requires: [8 'Ext.util.Group',9 // Since Collection uses sub-collections of various derived types we step up to10 // list all the requirements of Collection. The idea being that instead of a11 // "requires" of Ext.util.Collection (which cannot pull everything) you instead12 // do a "requires" of Ext.util.GroupCollection and it will.13 'Ext.util.SorterCollection',14 'Ext.util.FilterCollection'15 ],16 isGroupCollection: true,17 config: {18 itemRoot: null19 },20 observerPriority: -100,21 //-------------------------------------------------------------------------22 // Calls from the source Collection:23 onCollectionAdd: function (source, details) {24 this.addItemsToGroups(source, details.items);25 },26 onCollectionBeforeItemChange: function (source, details) {27 var me = this,28 item = details.item,29 newKey = source.getKey(item);30 // Drop the next add, remove and updatekey event31 me.onCollectionAdd =32 me.onCollectionRemove =33 me.onCollectionUpdateKey = null;34 me.syncItemGrouping(source, item, newKey, details.oldKey);35 },36 onCollectionBeginUpdate: function () {37 this.beginUpdate();38 },39 onCollectionEndUpdate: function () {40 this.endUpdate();41 },42 onCollectionItemChange: function (source, details) {43 delete this.onCollectionAdd;44 delete this.onCollectionRemove;45 delete this.onCollectionUpdateKey;46 },47 onCollectionRefresh: function (source) {48 this.removeAll();49 this.addItemsToGroups(source, source.items);50 },51 onCollectionRemove: function (source, details) {52 var me = this,53 entries = me.groupItems(source, details.items, false),54 entry, group, i, n, removeGroups;55 for (i = 0, n = entries.length; i < n; ++i) {56 group = (entry = entries[i]).group;57 if (group) {58 group.remove(entry.items);59 if (!group.length) {60 (removeGroups || (removeGroups = [])).push(group);61 }62 }63 }64 if (removeGroups) {65 me.remove(removeGroups);66 }67 },68 // If the SorterCollection instance is not changing, the Group will react to69 // changes inside the SorterCollection, but if the instance changes we need70 // to sync the Group to the new SorterCollection.71 onCollectionSort: function (source) {72 // sorting the collection effectively sorts the items in each group...73 var me = this,74 sorters = source.getSorters(),75 items = me.items,76 length = me.length,77 i, group;78 for (i = 0; i < length; ++i) {79 group = items[i];80 if (group.getSorters() !== sorters) {81 group.setSorters(sorters);82 }83 }84 },85 onCollectionUpdateKey: function (source, details) {86 this.syncItemGrouping(source, details.item, details.newKey, details.oldKey);87 },88 //-------------------------------------------------------------------------89 // Private90 addItemsToGroups: function (source, items) {91 var me = this,92 entries = me.groupItems(source, items, true),93 entry, i, n;94 for (i = 0, n = entries.length; i < n; ++i) {95 entry = entries[i];96 entry.group.add(entry.items);97 }98 },99 groupItems: function (source, items, adding) {100 var me = this,101 byGroup = {},102 entries = [],103 grouper = source.getGrouper(),104 groupKeys = me.itemGroupKeys,105 entry, group, groupKey, i, item, itemKey, n, newGroups;106 for (i = 0, n = items.length; i < n; ++i) {107 groupKey = grouper.getGroupString(item = items[i]);108 itemKey = source.getKey(item);109 if (adding) {110 (groupKeys || (me.itemGroupKeys = groupKeys = {}))[itemKey] = groupKey;111 } else if (groupKeys) {112 delete groupKeys[itemKey];113 }114 if (!(entry = byGroup[groupKey])) {115 if (!(group = me.getByKey(groupKey)) && adding) {116 (newGroups || (newGroups = [])).push(group = me.createGroup(source, groupKey));117 }118 entries.push(byGroup[groupKey] = entry = {119 group: group,120 items: []121 });122 }123 entry.items.push(item);124 }125 if (newGroups) {126 me.add(newGroups);127 }128 return entries;129 },130 syncItemGrouping: function (source, item, itemKey, oldKey) {131 var me = this,132 itemGroupKeys = me.itemGroupKeys || (me.itemGroupKeys = {}),133 grouper = source.getGrouper(),134 groupKey = grouper.getGroupString(item),135 removeGroups = 0,136 addGroups, group, oldGroup, oldGroupKey;137 if (oldKey) {138 oldGroupKey = itemGroupKeys[oldKey];139 delete itemGroupKeys[oldKey];140 } else {141 oldGroupKey = itemGroupKeys[itemKey];142 }143 itemGroupKeys[itemKey] = groupKey;144 if (!(group = me.get(groupKey))) {145 group = me.createGroup(source, groupKey);146 addGroups = [group];147 }148 if (group.get(itemKey) !== item) {149 group.add(item);150 } else {151 group.itemChanged(item);152 }153 if (groupKey !== oldGroupKey && (oldGroupKey === 0 || oldGroupKey)) {154 oldGroup = me.get(oldGroupKey);155 if (oldGroup) {156 oldGroup.remove(item);157 if (!oldGroup.length) {158 removeGroups = [oldGroup];159 }160 }161 }162 if (addGroups) {163 me.splice(0, removeGroups, addGroups);164 } else if (removeGroups) {165 me.splice(0, removeGroups);166 }167 },168 169 createGroup: function(source, key) {170 var group = new Ext.util.Group({171 groupKey: key,172 rootProperty: this.getItemRoot(),173 sorters: source.getSorters()174 });175 return group;176 },177 178 getKey: function(item) {179 return item.getGroupKey();180 },181 getGroupByRecord: function(record) {182 var items = this.items,183 len = items.length,184 item, i;185 for (i = 0; i < len; i++) {186 item = items[i];187 if (item.indexOf(record)) {188 return item;189 }190 }191 return null;192 }...
Using AI Code Generation
1var stf = require('devicefarmer-stf');2client.removeGroups(['group1', 'group2', 'group3']).then(function() {3 console.log('Groups removed successfully');4}, function(err) {5 console.log('Error removing groups: ' + err);6});
Using AI Code Generation
1var stf = require('devicefarmer-stf');2var device = client.getDevice('1234567890');3device.removeGroups(['group1', 'group2'], function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var stf = require('devicefarmer-stf');11var device = client.getDevice('1234567890');12device.removeGroups(['group1', 'group2']).then(function(data) {13 console.log(data);14}, function(err) {15 console.log(err);16});17var stf = require('devicefarmer-stf');18var device = client.getDevice('1234567890');19device.removeGroups(['group1', 'group2']).then(function(data) {20 console.log(data);21}).catch(function(err) {22 console.log(err);23});24var stf = require('devicefarmer-stf');25var device = client.getDevice('1234567890');26device.removeGroups(['group1', 'group2']).then(function(data) {27 console.log(data);28}).done();29var stf = require('devicefarmer-stf');30var device = client.getDevice('1234567890');31device.removeGroups(['group1', 'group2']).then(function(data) {32 console.log(data);33}, function(err) {34 console.log(err);35}).done();36var stf = require('devicefarmer-stf');37var device = client.getDevice('1234567890');
Using AI Code Generation
1var stf = require('devicefarmer-stf-client');2client.removeGroups('group1,group2', function(err, res) {3 if (err) {4 console.log(err);5 } else {6 console.log(res);7 }8});
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!