Lasso Soft Inc. > Home

[admin_groupassignpath]

Linkadmin_groupassignpath
AuthorJason Huck
CategoryAdministration
Version8.x
Licensehttp://opensource.org/licenses/artistic-license.php
Posted21 Nov 2006
Updated21 Nov 2006
More by this author...

Description

Assigns the given path to the given group. Requires authentication as a user with permissions on Lasso's internal db's, i.e., with [auth_admin].

Sample Usage

// to assign all valid paths to the given group
iterate(admin_allowedfileroots, local('i'));
	admin_groupassignpath(
		-group='TestGroup',
		-path=#i->second
	);
/iterate;

Source Code

Click the "Download" button below to retrieve a copy of this tag, including the complete documentation and sample usage shown on this page. Place the downloaded ".inc" file in your LassoStartup folder, restart Lasso, and you can begin using this tag immediately.

define_tag(
	'groupassignpath',
	-namespace='admin_',
	-req='group',
	-req='path',
	-opt='perms',
	-priority='replace',
	-description='Assigns the given path to the given group.'
);
	// validate path
	local('pathID' = 0);
	
	iterate(admin_allowedfileroots, local('i'));
		if(#i->second == #path);
			#pathID = #i->first;
			loop_abort;
		/if;
	/iterate;
	
	!#pathID ? return(false);


	// if no permissions are specified, default to all
	local('columns') = array(
		'create',
		'read',
		'write',
		'move',
		'copy',
		'delete',
		'inspect',
		'any_extension'
	);

	!local_defined('perms') ? local('perms') = #columns;		
	

	// wrap all inlines in a single connection		
	inline( -database='lasso_internal', -sql='SELECT 1');	
		// retrieve the group ID
		local('sql' = '
			SELECT id 
			FROM security_groups 
			WHERE name = \'' + #group + '\'
		');
		
		inline( -sql=#sql);
			local('groupID') = field('id');
		/inline;
		
		// look for an existing record
		local('sql' = '
			SELECT id
			FROM security_group_file_perms
			WHERE id_group = ' + #groupID + '
				AND allow_root = ' + #pathID + '
		');
		
		protect;
			inline( -sql=#sql);
				// if one exists, update it
				if(found_count);
					local('updateperms' = string);
					
					iterate(#columns, local('i'));
						#updateperms += 'allow_' + #i + ' = \'' + (#perms >> #i ? 'Y' | 'N') + '\', ';
					/iterate;
				
					#updateperms->removetrailing(', ');
				
					local('sql' = '
						UPDATE security_group_file_perms
						SET ' + #updateperms + '
						WHERE id = ' + field('id') + '
					');
					
					inline( -sql=#sql); /inline;
					
				// otherwise, insert a new one
				else;
					local(
						'insertvalues' = string,
						'insertcolumns' = string
					);
					
					iterate(#columns, local('i'));
						#insertvalues += '\'' + (#perms >> #i ? 'Y' | 'N') + '\',\n';
						#insertcolumns += 'allow_' + #i + ',\n';
					/iterate;
				
					#insertvalues->removetrailing(',\n');
					#insertcolumns->removetrailing(',\n');
				
					local('sql' = '
						INSERT INTO security_group_file_perms (
							id_group,
							allow_root,
							' + #insertcolumns + '
						) VALUES (
							' + #groupID + ',
							' + #pathID + ',
							' + #insertvalues + '
						)
					');
					
					inline( -sql=#sql); /inline;
				/if;
			/inline;
		
			return(true);
		
			handle_error;
				return(false);
			/handle_error;
		/protect;
	/inline;		
/define_tag;

Related Tags

Comments

No comments

Please log in to comment

Subscribe to the LassoTalk mail list

LassoSoft Inc. > Home

 

 

©LassoSoft Inc 2015 | Web Development by Treefrog Inc | PrivacyLegal terms and Shipping | Contact LassoSoft