Example #1
0
 public Task <PersonEntryFixed> CreateUser(string id, string firstName, string email, string password)
 {
     return(_alfrescoHttpClient.CreatePerson(new PersonBodyCreate
     {
         Id = id,
         FirstName = firstName,
         Email = email,
         Password = password
     }));
 }
Example #2
0
        public async Task <PersonEntryFixed> CreateUser([FromBody] UserCreate body)
        {
            var userInfo = await _alfrescoHttpClient.CreatePerson(new PersonBodyCreate
            {
                Email      = body.Email,
                FirstName  = body.FirstName,
                Id         = body.Id,
                LastName   = body.LastName,
                Password   = body.Password,
                Properties = new Dictionary <string, object>
                {
                    { SpisumNames.Properties.Group, body.MainGroup },
                    { SpisumNames.Properties.UserJob, body.UserJob },
                    { SpisumNames.Properties.UserOrgAddress, body.UserOrgAddress },
                    { SpisumNames.Properties.UserOrgId, body.UserOrgId },
                    { SpisumNames.Properties.UserOrgName, body.UserOrgName },
                    { SpisumNames.Properties.UserOrgUnit, body.UserOrgUnit },
                    { SpisumNames.Properties.UserName, $"{body.FirstName} {body.LastName}".Trim() },
                    { SpisumNames.Properties.UserId, body.UserId }
                }
            });

            var signGroups = body.SignGroups ?? new List <string>();
            var groupList  = body.Groups?.ToList() ?? new List <string>();

            groupList.AddUnique(body.MainGroup);
            groupList.AddRangeUnique(signGroups);

            // user group
            await _initialUser.CheckCreateGroupAndAddPerson(userInfo.Entry.Id, $"{SpisumNames.Prefixes.UserGroup}{userInfo.Entry.Id}");

            foreach (var group in groupList)
            {
                await _alfrescoHttpClient.CreateGroupMember(group, new GroupMembershipBodyCreate { Id = userInfo.Entry.Id, MemberType = GroupMembershipBodyCreateMemberType.PERSON });
            }

            foreach (var group in signGroups)
            {
                await _initialUser.CheckCreateGroupAndAddPerson(userInfo.Entry.Id, group + SpisumNames.Postfixes.Sign);
            }

            return(userInfo);
        }
Example #3
0
        private async Task CheckCreateUser(UserARM user)
        {
            if (user.Body == null)
            {
                return;
            }

            string userId          = null;
            var    updatePropertes = false;

            try
            {
                var userProperties = user.Body.Properties?.As <JObject>()?.ToDictionary();
                if (userProperties == null)
                {
                    userProperties = new Dictionary <string, object>();
                }
                if (user.MainGroup != null)
                {
                    userProperties.Add(SpisumNames.Properties.Group, user.MainGroup);
                }

                user.Body.Properties = userProperties;

                var userInfo = await _alfrescoHttpClient.GetPerson(user.Body.Id);

                userId = userInfo?.Entry?.Id;
                var properties = userInfo.Entry?.Properties?.As <JObject>()?.ToDictionary();

                updatePropertes = needUpdateProperties(properties, userProperties);
            }
            catch
            {
            }

            if (userId == null)
            {
                try
                {
                    await _alfrescoHttpClient.CreatePerson(user.Body);
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "CreatePerson Fail");
                }
            }
            else if (updatePropertes)
            {
                try
                {
                    await _alfrescoHttpClient.UpdatePerson(user.Body.Id, new PersonBodyUpdate { Properties = user.Body.Properties });
                }
                catch (Exception ex)
                {
                    Log.Error(ex, "UpdatePerson Fail");
                }
            }

            await _initialUser.CheckCreateGroupAndAddPerson(user.Body.Id, $"{SpisumNames.Prefixes.UserGroup}{user.Body.Id}");

            await _initialUser.CheckCreateGroupAndAddPerson(user.Body.Id, user.MainGroup);

            if (user.Groups?.Count > 0)
            {
                foreach (var group in user.Groups)
                {
                    await _initialUser.CheckCreateGroupAndAddPerson(user.Body.Id, group);
                }
            }
        }