コード例 #1
0
        public void UpdateProject(UpdateProjectDto input)
        {
            Logger.Info("Updating a project for input: " + input);

            var project = _projectRepository.Get(input.Id);

            project.State = input.State;

            if (input.Name != project.Name || input.Description != project.Description || input.StartTime != project.StartTime ||
                input.DeliverTime != project.DeliverTime || input.TeamLeaderId != project.TeamLeaderId)
            {
                PermissionChecker.Authorize(PermissionNames.Pages_Projects_EditOthers);
            }

            project.Name        = input.Name;
            project.Description = input.Description;
            project.StartTime   = input.StartTime;
            project.DeliverTime = input.DeliverTime;

            if (input.TeamLeaderId.HasValue)
            {
                var user = _userRepository.Get(ObjectMapper.Map <long>(input.TeamLeaderId));

                if (input.TeamLeaderId != project.TeamLeaderId)
                {
                    string message = "A new project -- \"" + input.Name + "\" has being assigned to u.";
                    _notificationPublisher.Publish("New Project", new MessageNotificationData(message), null, NotificationSeverity.Info, new[] { user.ToUserIdentifier() });
                }

                project.TeamLeaderId = input.TeamLeaderId;
                project.TeamLeader   = user;
            }
        }
コード例 #2
0
        //public async Task<bool> CreateTagAsync(CreateTagDto input)
        //{
        //    PermissionChecker.Authorize(PermissionNames.Page_Tag_Add);

        //    var obj = await _tagRepository.FirstOrDefaultAsync(p => p.Title == input.Title && p.CreatorUserId == AbpSession.UserId);
        //    if (obj != null)
        //    {
        //        CheckErrors(IdentityResult.Failed(new IdentityError() { Code = "308", Description = L("CreateTagError") }));
        //    }
        //    //Tag tag = new Tag();
        //    //tag.Title = input.Title;
        //    var tag = Mapper.Map<Tag>(input);
        //    //var task = ObjectMapper.Map<Tag>(input);
        //    return await _tagRepository.InsertAndGetIdAsync(tag) > 0;
        //}


        public async Task <IdentityResult> CreateTagAsync(CreateTagDto input)
        {
            PermissionChecker.Authorize(PermissionNames.Page_Tag_Add);

            var obj = await _tagRepository.FirstOrDefaultAsync(p => p.Title == input.Title && p.CreatorUserId == AbpSession.UserId);

            if (obj != null)
            {
                return(IdentityResult.Failed(new IdentityError()
                {
                    Code = "308", Description = L("CreateTagError")
                }));
            }
            //Tag tag = new Tag();
            //tag.Title = input.Title;
            var tag = Mapper.Map <Tag>(input);

            //var task = ObjectMapper.Map<Tag>(input);
            if (await _tagRepository.InsertAndGetIdAsync(tag) > 0)
            {
                return(IdentityResult.Success);
            }
            return(IdentityResult.Failed(new IdentityError()
            {
                Code = "500", Description = L("CreateTagError")
            }));
        }
コード例 #3
0
        public async Task <bool> DeleteBlogAsync(DeleteBlogDto input)
        {
            PermissionChecker.Authorize(PermissionNames.Page_Blog_Delete);
            await this._blogRepository.DeleteAsync(input.Id);

            return(true);
        }
コード例 #4
0
        //由于授权一般在服务层,所以ABP直接在ApplicationService基类注入并定义了一个PermissionChecker属性 这样 在服务层 就可以直接调PermissionChecker属性进行权限检查
        //public IPermissionChecker PermissionChecker { protected get; set; }
        //创建任务
        public int CreateTask(CreateTaskInput input)
        {
            //We can use Logger, it's defined in ApplicationService class.
            Logger.Info("Creating a task for input: " + input);

            //判断用户是否有权限
            if (input.AssignedPersonId.HasValue && input.AssignedPersonId.Value != AbpSession.GetUserId())
            {
                PermissionChecker.Authorize(PermissionNames.Pages_Tasks_AssignPerson);
            }
            var task   = Mapper.Map <Task>(input);
            int result = _taskRepository.InsertAndGetId(task);

            if (result > 0)//只有创建成功才发送邮件和通知
            {
                task.CreationTime = Clock.Now;

                if (input.AssignedPersonId.HasValue)
                {
                    task.AssignedPerson = _userRepository.Load(input.AssignedPersonId.Value);
                    var message = "You hava been assigned one task into your todo list.";

                    //TODO:需要重新配置QQ邮箱密码
                    //SmtpEmailSender emailSender = new SmtpEmailSender(_smtpEmialSenderConfig);
                    //emailSender.Send("*****@*****.**", task.AssignedPerson.EmailAddress, "New Todo item", message);

                    _notificationPublisher.Publish("NewTask", new MessageNotificationData(message), null,
                                                   NotificationSeverity.Info, new[] { task.AssignedPerson.ToUserIdentifier() });
                }
            }
            return(result);
        }
コード例 #5
0
 protected virtual void CheckPermission(string permissionName)
 {
     if (!string.IsNullOrEmpty(permissionName))
     {
         PermissionChecker.Authorize(permissionName);
     }
 }
コード例 #6
0
        protected virtual async Task CreateAsync <TEntity, TPrimaryKey, TCreateInput>(IRepository <TEntity, TPrimaryKey> repository, TCreateInput input)
            where TEntity : class, IEntity <TPrimaryKey>
        {
            var entity = Map <TEntity>(input);

            PermissionChecker.Authorize(GetCreatePermissionNames <TEntity>());
            await repository.InsertAsync(entity);
        }
コード例 #7
0
        public void Auth()
        {
            if (PermissionChecker.IsGranted(""))
            {
            }

            PermissionChecker.Authorize("");
        }
コード例 #8
0
        public async Task <TagDto> GetTagByIdAsync(long tagId)
        {
            PermissionChecker.Authorize(PermissionNames.Page_Tag);
            //AbpSession.UserId
            var tag = await _tagRepository.FirstOrDefaultAsync(p => p.Id == tagId && p.CreatorUserId == AbpSession.UserId);

            return(Mapper.Map <TagDto>(tag));
        }
コード例 #9
0
        //[AbpAuthorize(PermissionNames.Page_Tag_Delete)]
        public async Task <bool> DeleteTagAsync(DeleteTagDto input)
        {
            PermissionChecker.Authorize(PermissionNames.Page_Tag_Delete);

            await _tagRepository.DeleteAsync(input.Id);

            return(true);
        }
コード例 #10
0
        protected virtual async Task <PagedResultDto <TEntityDto> > GetAllAsync <TEntity, TPrimaryKey, TEntityDto>(IRepository <TEntity, TPrimaryKey> repository, GenericPagingInput input = null)
            where TEntity : class, IEntity <TPrimaryKey>
        {
            PermissionChecker.Authorize(GetRetrievePermissionNames <TEntity>());
            var predicate = await GetLoginFilter <TEntity>(GetSysObjectName <TEntity>());

            return(await GetAll <TEntity, TPrimaryKey, GenericPagingInput, TEntityDto>(
                       repository.GetAll().Where(predicate), input));
        }
コード例 #11
0
        //public async Task<IList<TagDto>> GetAllTagsAsync()
        //{
        //    PermissionChecker.Authorize(PermissionNames.Page_Tag);
        //    var tags = await _tagRepository.GetAllListAsync(p => p.CreatorUserId == AbpSession.UserId);
        //    return Mapper.Map<IList<TagDto>>(tags);
        //}

        public async Task <ListResultDto <TagDto> > GetAllTagsAsync()
        {
            PermissionChecker.Authorize(PermissionNames.Page_Tag);
            var tags = await _tagRepository.GetAllListAsync(p => p.CreatorUserId == AbpSession.UserId);

            //return Mapper.Map<IList<TagDto>>(tags);
            //return new  ListResultDto<TagDto>(Mapper.Map<IList<TagDto>>(tags));
            return(new ListResultDto <TagDto>(ObjectMapper.Map <List <TagDto> >(tags)));
        }
コード例 #12
0
        //[AbpAuthorize(PermissionNames.Page_Tag)]
        public async Task <PagedResultDto <TagDto> > GetTagsByPageAsync(PagedAndFilteredInputDto input)
        {
            PermissionChecker.Authorize(PermissionNames.Page_Tag);
            int count = await _tagRepository.CountAsync(p => p.Title.Contains(input.Filter));

            var list = _tagRepository.GetAll().PageBy(input).ToList();

            //list.MapTo<List<TagDto>>();
            return(new PagedResultDto <TagDto>(count, Mapper.Map <List <TagDto> >(list)));
        }
コード例 #13
0
 protected virtual void CheckPermission(string permissionName)
 {
     if (!SySession.UserId.HasValue)
     {
         throw new SyMessageException(SyMessageBoxStatus.UnAuthorized);
     }
     if (!string.IsNullOrEmpty(permissionName))
     {
         PermissionChecker.Authorize(permissionName);
     }
 }
コード例 #14
0
        protected virtual async Task CheckPermissionAsync(string permissionName)
        {
            //if (string.IsNullOrWhiteSpace(permissionName))
            //    return;

            //if (!await IsGrantedAsync(permissionName))
            //    throw new UserFriendlyException(L("UnAuthorized"));

            //使用父类的权限检查可以得到一个正常的未授权响应
            if (!string.IsNullOrEmpty(permissionName))
            {
                PermissionChecker.Authorize(permissionName);
            }
        }
コード例 #15
0
        //[ResponseCache(VaryByQueryKeys =new string[] {"moduleKey" }]
        public virtual IActionResult Add(string modulekey)
        {
            //权限判定
            var permissionName = $"Module.{modulekey}.Button.Add";

            PermissionChecker.Authorize(permissionName);

            var param = new ModuleFormViewParam()
            {
                ModuleKey = modulekey
            };

            return(View(param));
        }
コード例 #16
0
        /// <summary>
        /// 检查权限,检查用户
        /// </summary>
        /// <typeparam name="TEntity"></typeparam>
        /// <param name="entity"></param>
        protected virtual void CheckDelete <TEntity>(TEntity entity)
        {
            PermissionChecker.Authorize(GetDeletePermissionNames <TEntity>());

            if (IsOwner(entity as IMayHaveOwner))
            {
                return;
            }
            if (IsCreator(entity as ICreationAudited))
            {
                return;
            }
            throw new UserFriendlyException("You do not have permission to delete this data, Please contact System administrator.");
        }
コード例 #17
0
        public async Task <PagedResultDto <BlogDto> > GetAllBlogsByPageAsync(PagedAndFilteredInputDto input)
        {
            PermissionChecker.Authorize(PermissionNames.Page_Blog);
            var            em         = AbpSession.GetUserEmail();
            int            totalCount = 0;
            List <Blog>    list       = new List <Blog>();
            List <BlogDto> listDto    = new List <BlogDto>();
            var            query      = this._blogRepository.GetAll();

            if (string.IsNullOrEmpty(input.Filter))
            {
                if (input.From.HasValue && input.To.HasValue)
                {
                    query = this._blogRepository.GetAll().Include("BlogTags").Where(p => p.CreatorUserId == AbpSession.UserId && ((p.CreationTime >= input.From && p.CreationTime <= input.To) || (p.LastModificationTime >= input.From && p.LastModificationTime <= input.To)));
                }
                else
                {
                    query = this._blogRepository.GetAll().Include("BlogTags").Where(p => p.CreatorUserId == AbpSession.UserId);
                }
            }
            else
            {
                query = this._blogRepository.GetAll().Include("BlogTags").Where(p => p.CreatorUserId == AbpSession.UserId && (p.Title.Contains(input.Filter) || p.Content.Contains(input.Filter) || p.KeyWords.Contains(input.Filter) || p.Summary.Contains(input.Filter)));
                if (input.From.HasValue && input.To.HasValue)
                {
                    query = query.Where(p => (p.CreationTime >= input.From && p.CreationTime <= input.To) || (p.LastModificationTime >= input.From && p.LastModificationTime <= input.To));
                }
            }

            totalCount = await query.CountAsync();

            list = await query.PageBy <Blog>(input).ToListAsync();

            listDto = Mapper.Map <List <BlogDto> >(list);
            foreach (var iObj in list)
            {
                if (iObj.BlogTags != null && iObj.BlogTags.Count > 0)
                {
                    var obj = listDto.FirstOrDefault(p => p.Id == iObj.Id);
                    obj.SelectTags.AddRange(iObj.BlogTags.Select(p => p.TagId));
                }
            }
            var resultList = new PagedResultDto <BlogDto>(totalCount, listDto);

            return(resultList);
        }
コード例 #18
0
        public void UpdateModule(UpdateModuleDto input)
        {
            Logger.Info("Updating a module for input: " + input);

            var module      = _moduleRepository.Get(input.Id);
            var currentUser = AsyncHelper.RunSync(this.GetCurrentUserAsync);

            module.State = input.State;

            //Check Permission for TeamLeader
            if (input.Name != module.Name || input.Description != module.Description || input.Level != module.Level || input.StartTime != module.StartTime ||
                input.DeliverTime != module.DeliverTime || input.TechStack != module.TechStack || input.MemberId != module.MemberId ||
                input.ProjectId != module.ProjectId)
            {
                PermissionChecker.Authorize(PermissionNames.Pages_Modules_EditOthers);
            }

            module.Name        = input.Name;
            module.Description = input.Description;
            module.Level       = input.Level;
            module.StartTime   = input.StartTime;
            module.DeliverTime = input.DeliverTime;
            module.TechStack   = input.TechStack;

            if (input.MemberId.HasValue)
            {
                var user = _userRepository.Get(ObjectMapper.Map <long>(input.MemberId));

                if (input.MemberId != module.MemberId)
                {
                    string message = "A new module -- \"" + input.Name + "\" has being assigned to u.";
                    _notificationPublisher.Publish("New Module", new MessageNotificationData(message), null, NotificationSeverity.Info, new[] { user.ToUserIdentifier() });
                }

                module.MemberId = input.MemberId;
                module.Member   = user;
            }

            if (input.ProjectId.HasValue)
            {
                module.ProjectId = input.ProjectId;
                var project = _projectRepository.Get(ObjectMapper.Map <int>(input.ProjectId));
                module.Project = project;
            }
        }
コード例 #19
0
        public async virtual Task <IActionResult> View(string modulekey, int data, string viewName = "View")
        {
            //权限判定
            var permissionName = $"Module.{modulekey}.Button.View";

            PermissionChecker.Authorize(permissionName);

            var moduleInfo = await ModuleManager.GetModuleInfo(modulekey);

            var formData = (await ModuleManager.GetModuleDataListAsync(moduleInfo, "Id=" + data)).First();

            var param = new ModuleFormViewParam()
            {
                ModuleKey = modulekey, Data = formData
            };

            return(View(viewName, param));
        }
コード例 #20
0
        //[AbpAuthorize(PermissionNames.Page_Tag_Update)]
        public async Task <bool> UpdateTagAsync(UpdateTagDto input)
        {
            PermissionChecker.Authorize(PermissionNames.Page_Tag_Update);

            var tag = await _tagRepository.GetAsync(input.Id);

            if (tag != null)
            {
                tag = input.MapTo(tag);//修改必须要
                await _tagRepository.UpdateAsync(tag);

                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #21
0
        public async Task <PagedResultDto <TagDto> > GetAllTagsByPageAsync(PagedAndFilteredInputDto input)
        {
            PermissionChecker.Authorize(PermissionNames.Page_Tag);
            if (string.IsNullOrEmpty(input.Filter))
            {
                int count = await _tagRepository.CountAsync(p => p.CreatorUserId == AbpSession.UserId);

                var list = _tagRepository.GetAll().Where(p => p.CreatorUserId == AbpSession.UserId).PageBy(input).ToList();
                return(new PagedResultDto <TagDto>(count, Mapper.Map <List <TagDto> >(list)));
            }
            else
            {
                int count = await _tagRepository.CountAsync(p => p.CreatorUserId == AbpSession.UserId && p.Title.Contains(input.Filter));

                var list = _tagRepository.GetAll().Where(p => p.CreatorUserId == AbpSession.UserId && p.Title.Contains(input.Filter)).PageBy(input).ToList();
                return(new PagedResultDto <TagDto>(count, Mapper.Map <List <TagDto> >(list)));
            }
        }
コード例 #22
0
        public async virtual Task <IActionResult> MultiEdit(string modulekey, string data, string keys = "")
        {
            //权限判定
            var permissionName = $"Module.{modulekey}.Button.MultiEdit";

            PermissionChecker.Authorize(permissionName);

            var moduleInfo = await ModuleManager.GetModuleInfo(modulekey);

            var formData = new Dictionary <string, object>();

            formData.Add("Ids", data);
            formData.Add("Keys", keys);
            var param = new ModuleFormViewParam()
            {
                ModuleKey = modulekey, Data = formData
            };

            return(View(param));
        }
コード例 #23
0
        public int CreateTask(CreateTaskInput input)
        {
            //We can use Logger, it's defined in ApplicationService class.
            Logger.Info("Creating a task for input: " + input);

            var currentUser = AsyncHelper.RunSync(this.GetCurrentUserAsync);

            PermissionChecker.Authorize(PermissionNames.Pages_Tasks);
            //Creating a new Task entity with given input's properties
            var task = new TaskModel
            {
                Description  = input.Description,
                Title        = input.Title,
                State        = input.State,
                CreationTime = Clock.Now
            };

            //Saving entity with standard Insert method of repositories.
            return(_taskRepository.InsertAndGetId(task));
        }
コード例 #24
0
        public int CreateTask(CreateTaskInput input)
        {
            Logger.Info("Creating a task for input:" + input);

            //获取当前用户
            var currentUser = AsyncHelper.RunSync(this.GetCurrentUserAsync);

            //判断用户是否有权限
            if (input.AssignedPersonId.HasValue && input.AssignedPersonId.Value != currentUser.Id)
            {
                PermissionChecker.Authorize(PermissionNames.Pages_Tasks_AssignPerson);
            }

            var task   = Mapper.Map <MyTask>(input);
            int result = taskRespository.InsertAndGetId(task);

            //只有创建成功才发送邮件通知
            if (result > 0)
            {
                task.CreationTime = Clock.Now;
                if (task.AssignedPersonId.HasValue)
                {
                    task.AssignedPerson = userRepository.Load(input.AssignedPersonId.Value);
                    var message = "You have been assigned one task into your todo list.";

                    notificationPublisher.Publish("NewTask", new MessageNotificationData(message), null, NotificationSeverity.Info, new[] { task.AssignedPerson.ToUserIdentifier() });
                }
            }
            return(result);
            //var task = new MyTask
            //{
            //    Title = input.Title,
            //    Description = input.Description,
            //    State = input.State,
            //    CreationTime = Clock.Now
            //};
            //return taskRespository.InsertAndGetId(task);
        }
コード例 #25
0
        public async Task <bool> CreateBlogAsync(CreateBlogDto input)
        {
            PermissionChecker.Authorize(PermissionNames.Page_Blog_Add);
            var blog = Mapper.Map <Blog>(input);

            input.SelectTags = input.SelectTags.Distinct().ToList();
            var tags = await _tagRepository.GetAllListAsync(p => input.SelectTags.Contains(p.Id));

            if (tags.Count > 0)
            {
                blog.BlogTags = new List <BlogTag>();
                var blogTags = tags.Select(p => new BlogTag()
                {
                    Tag = p
                });
                foreach (var iObj in blogTags)
                {
                    blog.BlogTags.Add(iObj);
                }
            }

            return(await _blogRepository.InsertAndGetIdAsync(blog) > 0);
        }
コード例 #26
0
        public override Task AuthorizeAsync(IEnumerable <IAbpAuthorizeAttribute> authorizeAttributes)
        {
            if (!_authConfiguration.IsEnabled)
            {
                return(Task.CompletedTask);
            }
            _httpContextAccessor.HttpContext.Request.Cookies.TryGetValue(WorkFlowTaskAbpConsts.CookiesUserId,
                                                                         out var cookiesId);
            var userid = Session.GetUserId() ?? Session.SetUserId(cookiesId);

            if (userid.IsNullOrEmpty())
            {
                throw new AbpAuthorizationException(
                          LocalizationManager.GetString(AbpConsts.LocalizationSourceName, "CurrentUserDidNotLoginToTheApplication")
                          );
            }


            foreach (var authorizeAttribute in authorizeAttributes)
            {
                PermissionChecker.Authorize(authorizeAttribute.RequireAllPermissions, authorizeAttribute.Permissions);
            }
            return(Task.CompletedTask);
        }
コード例 #27
0
        public async Task <bool> UpdateBlogAsync(UpdateBlogDto input)
        {
            PermissionChecker.Authorize(PermissionNames.Page_Blog_Update);
            if (input.Id == 0)
            {
                return(false);
            }
            input.SelectTags = input.SelectTags.Distinct().ToList();
            var blog = await _blogRepository.GetAll().Include(p => p.BlogTags).FirstOrDefaultAsync(p => p.Id == input.Id);

            if (blog != null)
            {
                if (blog.BlogTags != null && blog.BlogTags.Count > 0)
                {
                    //删除没有选择的
                    var delblogTagsList = blog.BlogTags.Where(p => !input.SelectTags.Contains(p.TagId)).ToList();
                    foreach (var iDelObj in delblogTagsList)
                    {
                        blog.BlogTags.Remove(iDelObj);
                    }

                    var blogTagsList = blog.BlogTags.Select(p => p.TagId);

                    var insertList = input.SelectTags.Where(p => !blogTagsList.Contains(p)).ToList();

                    var tags = await _tagRepository.GetAllListAsync(p => insertList.Contains(p.Id));

                    if (tags.Count > 0)
                    {
                        var blogTags = tags.Select(p => new BlogTag()
                        {
                            Tag = p
                        });
                        foreach (var iObj in blogTags)
                        {
                            blog.BlogTags.Add(iObj);
                        }
                    }
                }
                else
                {
                    var tags = await _tagRepository.GetAllListAsync(p => input.SelectTags.Contains(p.Id));

                    if (tags.Count > 0)
                    {
                        blog.BlogTags = new List <BlogTag>();
                        var blogTags = tags.Select(p => new BlogTag()
                        {
                            Tag = p
                        });
                        foreach (var iObj in blogTags)
                        {
                            blog.BlogTags.Add(iObj);
                        }
                    }
                }
                //var blogTagList= this._blogTagRepository.GetAll().Where(p=> input.SelectTags.Contains(p.TagId));
                blog = input.MapTo(blog);//修改必须要
                //await this._blogTagRepository.DeleteAsync(p => input.SelectTags.Contains(p.TagId));
                await _blogRepository.UpdateAsync(blog);

                return(true);
            }
            else
            {
                return(false);
            }
        }
コード例 #28
0
 /// <summary>
 /// 检查权限
 /// </summary>
 /// <typeparam name="TEntity"></typeparam>
 /// <param name="entity"></param>
 protected virtual void CheckCreate <TEntity>(TEntity entity)
 {
     PermissionChecker.Authorize(GetCreatePermissionNames <TEntity>());
 }