mirror of
				https://gitlab.com/comunic/comunicapiv2
				synced 2025-11-04 03:24:04 +00:00 
			
		
		
		
	Can update group settings
This commit is contained in:
		@@ -2,6 +2,7 @@ import { crypt, sha1, randomStr } from "../utils/CryptUtils";
 | 
			
		||||
import { APIClient } from "../entities/APIClient";
 | 
			
		||||
import { UserLoginTokens } from "../entities/UserLoginTokens";
 | 
			
		||||
import { DatabaseHelper } from "./DatabaseHelper";
 | 
			
		||||
import { UserHelper } from "./UserHelper";
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Account helper
 | 
			
		||||
@@ -139,4 +140,17 @@ export class AccountHelper {
 | 
			
		||||
			token2: row.token2
 | 
			
		||||
		};
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Check out whether a virtual directory is available or not
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param dir Virtual directory to check
 | 
			
		||||
	 * @param userID Target user ID
 | 
			
		||||
	 */
 | 
			
		||||
	public static async CheckUserDirectoryAvailability(dir: string, userID: number = -1) : Promise<boolean> {
 | 
			
		||||
		const foundUser = await UserHelper.FindByFolder(dir);
 | 
			
		||||
 | 
			
		||||
		return foundUser < 1 || userID == foundUser;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -3,6 +3,7 @@ import { GroupsAccessLevel, GroupVisibilityLevel, GroupInfo } from "../entities/
 | 
			
		||||
import { GroupMembershipLevels, GroupMember } from "../entities/GroupMember";
 | 
			
		||||
import { NewGroup } from "../entities/NewGroup";
 | 
			
		||||
import { time } from "../utils/DateUtils";
 | 
			
		||||
import { GroupSettings } from "../entities/GroupSettings";
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * Groups helper
 | 
			
		||||
@@ -98,6 +99,23 @@ export class GroupsHelper {
 | 
			
		||||
		return this.DbToGroupInfo(row);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Update (set) group settings
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param settings Group settings
 | 
			
		||||
	 */
 | 
			
		||||
	public static async SetSettings(settings: GroupSettings) {
 | 
			
		||||
		const dbEntry = this.GroupSettingsToDB(settings);
 | 
			
		||||
 | 
			
		||||
		await DatabaseHelper.UpdateRows({
 | 
			
		||||
			table: GROUPS_LIST_TABLE,
 | 
			
		||||
			where: {
 | 
			
		||||
				id: settings.id
 | 
			
		||||
			},
 | 
			
		||||
			set: dbEntry
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Get the visibility level of a group
 | 
			
		||||
	 * 
 | 
			
		||||
@@ -222,6 +240,36 @@ export class GroupsHelper {
 | 
			
		||||
		return this.DbToGroupMember(data);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Find a group by its virtual directory
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param dir Target directory
 | 
			
		||||
	 * @returns The ID of the target directory / -1 if none found
 | 
			
		||||
	 */
 | 
			
		||||
	public static async FindByVirtualDirectory(dir: string) : Promise<number> {
 | 
			
		||||
		const result = await DatabaseHelper.QueryRow({
 | 
			
		||||
			table: GROUPS_LIST_TABLE,
 | 
			
		||||
			where: {
 | 
			
		||||
				virtual_directory: dir
 | 
			
		||||
			},
 | 
			
		||||
			fields: ["id"]
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		return result == null ? -1 : result.id;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Check out whether a virtual directory is available or not
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param dir The directory to check
 | 
			
		||||
	 * @param groupID The ID of the group making the request 
 | 
			
		||||
	 */
 | 
			
		||||
	public static async CheckDirectoryAvailability(dir: string, groupID: number = -1) : Promise<boolean> {
 | 
			
		||||
		const currID = await this.FindByVirtualDirectory(dir);
 | 
			
		||||
 | 
			
		||||
		return currID < 1 || currID == groupID;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Count the number of members of a group
 | 
			
		||||
@@ -277,4 +325,40 @@ export class GroupsHelper {
 | 
			
		||||
			following: row.following == 1
 | 
			
		||||
		});
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Turn a GroupSettings object into a database entry object
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param settings Group settings object to transform
 | 
			
		||||
	 * @return Generated database entry
 | 
			
		||||
	 */
 | 
			
		||||
	private static GroupSettingsToDB(settings: GroupSettings) : Object {
 | 
			
		||||
		let data = {};
 | 
			
		||||
 | 
			
		||||
		if(settings.name != null)
 | 
			
		||||
			data['name'] = settings.name;
 | 
			
		||||
		
 | 
			
		||||
		if(settings.hasLogo)
 | 
			
		||||
			data["path_logo"] = settings.logo;
 | 
			
		||||
		
 | 
			
		||||
		if(settings.visiblity != null)
 | 
			
		||||
			data["visibility"] = settings.visiblity;
 | 
			
		||||
		
 | 
			
		||||
		if(settings.registrationLevel != null)
 | 
			
		||||
			data["registration_level"] = settings.registrationLevel;
 | 
			
		||||
		
 | 
			
		||||
		if(settings.postsCreationLevel != null)
 | 
			
		||||
			data["posts_level"] = settings.postsCreationLevel;
 | 
			
		||||
		
 | 
			
		||||
		if(settings.virtualDirectory != null)
 | 
			
		||||
			data["virtual_directory"] = settings.virtualDirectory;
 | 
			
		||||
		
 | 
			
		||||
		if(settings.description != null)
 | 
			
		||||
			data["description"] = settings.description;
 | 
			
		||||
		
 | 
			
		||||
		if(settings.url != null)
 | 
			
		||||
			data["url"] = settings.url;
 | 
			
		||||
		
 | 
			
		||||
		return data;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -68,6 +68,24 @@ export class UserHelper {
 | 
			
		||||
		return request.map((e) => e.ID);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Search for user by virtual directory
 | 
			
		||||
	 * 
 | 
			
		||||
	 * @param dir Target directory
 | 
			
		||||
	 * @returns The ID of the user found / -1 if none found
 | 
			
		||||
	 */
 | 
			
		||||
	public static async FindByFolder(dir: string) : Promise<number> {
 | 
			
		||||
		const result = await DatabaseHelper.QueryRow({
 | 
			
		||||
			table: TABLE_NAME,
 | 
			
		||||
			where: {
 | 
			
		||||
				sous_repertoire: dir
 | 
			
		||||
			},
 | 
			
		||||
			fields: ["ID"]
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		return result == null ? -1 : Number(result.ID);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
	private static async DbToUser(row: any) : Promise<User> {
 | 
			
		||||
		return new User({
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user