<commit_before>(function () {
	'use strict';
	angular.module('orgs')
	// =========================================================================
	//
	// Controller for the master list of orgs
	//
	// =========================================================================
	.controller('OrgsListController', function (orgs) {
		var vm      = this;
		vm.orgs = orgs;
	})
	// =========================================================================
	//
	// Controller the view of the org page
	//
	// =========================================================================
	.controller('OrgViewController', function ($scope, $state, $sce, org, Authentication, OrgsService, Notification, capabilities) {
		var vm             = this;
		vm.org             = org;
		vm.user            = Authentication.user;
		// console.log ('user org admins' , vm.user.orgAdmin);
		// console.log (' org admins' , vm.org.admins);
		// console.log (' org owner' , vm.org.owner);
		vm.isAdmin         = vm.user && !!~Authentication.user.roles.indexOf ('admin');
		vm.isGov           = vm.user && !!~Authentication.user.roles.indexOf ('gov');
		vm.isOrgAdmin      = vm.org.admins.map (function (u) { return (vm.user._id === u._id); }).reduce (function (accum, curr) {return (accum || curr);}, false);
		vm.isOrgOwner      = org.owner && (vm.user._id === org.owner._id);
		vm.canEdit         = vm.isAdmin || vm.isOrgOwner || vm.isOrgAdmin;
		vm.trust           = $sce.trustAsHtml;

		vm.description     = $sce.trustAsHtml(vm.org.description);
		//
		// what can the user do here?
		//
	})
	// =========================================================================
	//
	// create a new org
	//
	// =========================================================================
	.controller('OrgCreateController', function ($scope, $state, $sce, $window, $timeout, Upload, org, Authentication, Notification, dataService, UsersService) {
		var vm = this;
		vm.features = window.features;
		vm.org = org;
		// vm.orgaddForm = {};
		var newId;
		vm.add = function (isValid) {
			if (!isValid) {
				$scope.$broadcast('show-errors-check-validity', 'vm.orgForm');
				return false;
			}
			vm.orgForm.$setPristine ();
			vm.org.createOrUpdate ()
			.then (function (result) {
				vm.orgForm.$setPristine ();
				newId = result._id;
				Notification.success ({
					message : '<i class="glyphicon glyphicon-ok"></i> Company saved successfully!'
				})
			})
			.then (function () {
				UsersService.resetMe ();
			})
			.then (function () {
				$state.go ('orgadmin.profile', {orgId:newId});
			})
			.catch (function (res) {
				Notification.error ({
					message : res.data.message,
					title   : '<i class=\'glyphicon glyphicon-remove\'></i> Company save error!'
				});
			});
		}
		vm.delete = function () {
			$state.go('orgs.list');
		}
	})<commit_msg>fixed, again, the chicken and egg problem with user accounts updatiing<commit_after>(function () {
	'use strict';
	angular.module('orgs')
	// =========================================================================
	//
	// Controller for the master list of orgs
	//
	// =========================================================================
	.controller('OrgsListController', function (orgs) {
		var vm      = this;
		vm.orgs = orgs;
	})
	// =========================================================================
	//
	// Controller the view of the org page
	//
	// =========================================================================
	.controller('OrgViewController', function ($scope, $state, $sce, org, Authentication, OrgsService, Notification, capabilities) {
		var vm             = this;
		vm.org             = org;
		vm.user            = Authentication.user;
		// console.log ('user org admins' , vm.user.orgAdmin);
		// console.log (' org admins' , vm.org.admins);
		// console.log (' org owner' , vm.org.owner);
		vm.isAdmin         = vm.user && !!~Authentication.user.roles.indexOf ('admin');
		vm.isGov           = vm.user && !!~Authentication.user.roles.indexOf ('gov');
		vm.isOrgAdmin      = vm.org.admins.map (function (u) { return (vm.user._id === u._id); }).reduce (function (accum, curr) {return (accum || curr);}, false);
		vm.isOrgOwner      = org.owner && (vm.user._id === org.owner._id);
		vm.canEdit         = vm.isAdmin || vm.isOrgOwner || vm.isOrgAdmin;
		vm.trust           = $sce.trustAsHtml;

		vm.description     = $sce.trustAsHtml(vm.org.description);
		//
		// what can the user do here?
		//
	})
	// =========================================================================
	//
	// create a new org
	//
	// =========================================================================
	.controller('OrgCreateController', function ($scope, $state, $sce, $window, $timeout, Upload, org, Authentication, Notification, dataService, UsersService) {
		var vm = this;
		vm.features = window.features;
		vm.org = org;
		// vm.orgaddForm = {};
		vm.user = Authentication.user;
		var newId;
		vm.add = function (isValid) {
			if (!isValid) {
				$scope.$broadcast('show-errors-check-validity', 'vm.orgForm');
				return false;
			}
			vm.orgForm.$setPristine ();
			vm.org.createOrUpdate ()
			.then (function (result) {
				vm.orgForm.$setPristine ();
				newId = result._id;
				Notification.success ({
					message : '<i class="glyphicon glyphicon-ok"></i> Company saved successfully!'
				})
			})
			.then (function () {
				vm.user.orgsMember.push (newId);
				vm.user.orgsAdmin.push (newId);
				var user = new UsersService (vm.user);
				return new Promise (function (resolve, reject) {
					user.$update (function (response) {
						Authentication.user = response;
						resolve ();
					}, function (err) {
						reject (err);
					});
				});
				// UsersService.resetMe ();
			})
			.then (function () {
				$state.go ('orgadmin.profile', {orgId:newId});
			})
			.catch (function (res) {
				Notification.error ({
					message : res.data.message,
					title   : '<i class=\'glyphicon glyphicon-remove\'></i> Company save error!'
				});
			});
		}
		vm.delete = function () {
			$state.go('orgs.list');
		}
	})
{'fraction_non_alphanumeric': 0.29294755877034356, 'fraction_numerical': 0.0, 'mean_word_length': 3.198757763975155, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1690066', 'n_tokens_mistral': 2094, 'n_tokens_neox': 1777, 'n_words': 383}