Base solution for your next web application

Activities of "davidharrison"

Hi @ismcagdas,

Yes we are trying to open a modal.

What type of exceptions can the ModalManager handle? a UserFriendlyException or another type?

Thanks,

David

Hi Guys,

If you are loading a view or a partial view, how do you correctly throw an error (for example if a permission check has been run to verify user is authorized to view view) and then handle the thrown error?

We've tried working with UserFriendlyException but as far as we can ascertain, there is a mismatch between the return types and error handling types. If our understanding is correct, when requesting a view, the request is expecting an html view/error view to return, but the UserFriendlyException returns a json format error?

Thanks

I've looked at that document previosuly, and it doesn't help to clarify the situation.

Reading through it and the associated links, it details an abp ajax call can be made like so:

abp.ajax({
    url: '/People/SavePerson',
    data: JSON.stringify(newPerson)
}).done(function(data) {
    abp.notify.success('Created new person with id = ' + data.personId);
});

And any errors returning from this can be handled and displayed via the abp.message.error function.

However the modal isn't called via an ajax method as show above, it's called via the action function of a datatable:

        action: function (data) {
            _manageACLModal.open({ entityid: data.record.id, entityname: data.record.name });
        }

How do you check for a returning error from this call method?

Hi @maliming

On throwing the UserFriendlyException a 500 error is being returned to the browser (and the request fails to complete)

Thanks

Hi Guys,

I've built an authorization interceptor that runs prior to method execution and checks if the executing user has the required permission for that method.

If they don't have the required permission, I would like to stop the method from executing and return an error message to the UI explaining that the user lacks the required permission.

In my first use case, I'm calling a modal (from a datatables row action) that displays a list of records, and the list fetching method is an intercepted method. Here is my current code:

JS Action calling the Controller to open the modal

        action: function (data) {
            _manageACLModal.open({ entityid: data.record.id, entityname: data.record.name });
        }

Controller Method for calling the modal and fetching the records list

        public PartialViewResult ManageACLModal(Guid EntityId, string EntityName)
        {
            ListResultDto<GetACLForEditOutput> EntityACL = null;
            ACLCheckDto aCLCheckDto = new ACLCheckDto()
            {
                Action = "Share",
                EntityId = EntityId,
                UserId = AbpSession.UserId,
                OrgId = null
            };
            
            EntityACL = _ACLsAppService.GetACLForEdit(aCLCheckDto);

            GetACLForView getACLForEditOutput = new GetACLForView()
            {
                EntityId = EntityId,
                EntityName = EntityName,
                EntityACL = EntityACL
            };

            var viewModel = new ManageACLModalViewModel(getACLForEditOutput);

            return PartialView("_ManageACLModal", viewModel);
        }

Authorization Interceptor

        public void Intercept(IInvocation invocation)
        {
            var Arguments = invocation.Arguments;
            ACLCheckDto aCLCheckDto = (ACLCheckDto)Arguments[0];
            if (_ACLManager.CheckAccess(aCLCheckDto))
            {
                invocation.Proceed();
            }
            else
            {
                throw new UserFriendlyException("Unauthorized Request!", "You are trying call a function you're not permitted to use.");
            }
        }

The interceptor is successfully called and runs its authorization check, fails the check then throws the UserFriendlyException. However the generic error message is displayed in the front end. I've looked through ABP's documentation and the forums but haven't been able to find anything that shed's light on why the custom message doesn't display.

  • Does the Controller need to do something to handle the custom error?
  • Or does the JS need to do something to handle the custom error?
  • Or does the error need to be throw at a different location? i.e. not from the interceptor? If so, how does the interceptor stop the method execution?

Thank you for your help @alirizaadiyahsi, much appreciated and really helped me out.

Hi Alirizaadiyahsi,

The project is ASP.NET Core MVC Zero Version 5.6.

There aren't any errors - a dropdown element placed in a view simply doesn't have the dropdown behaviour. Code example:

        <div class="m-dropdown m-dropdown--inline m-dropdown--arrow m-dropdown--align-right" m-dropdown-toggle="click">
            <a href="#" class="m-dropdown__toggle btn btn-sm btn-primary dropdown-toggle">
                Dropdown - Click
            </a>
            <div class="m-dropdown__wrapper">
                <span class="m-dropdown__arrow m-dropdown__arrow--left"></span>
                <div class="m-dropdown__inner">
                    <div class="m-dropdown__body">
                        <div class="m-dropdown__content">
                            <ul class="m-nav">
                                <li class="m-nav__section m-nav__section--first">
                                    <span class="m-nav__section-text">Section</span>
                                </li>
                                <li class="m-nav__item">
                                    <a href="" class="m-nav__link">
                                        <i class="m-nav__link-icon flaticon-share"></i>
                                        <span class="m-nav__link-text">Activity</span>
                                    </a>
                                </li>
                                <li class="m-nav__item">
                                    <a href="" class="m-nav__link">
                                        <i class="m-nav__link-icon flaticon-chat-1"></i>
                                        <span class="m-nav__link-text">Messages</span>
                                    </a>
                                </li>
                                <li class="m-nav__item">
                                    <a href="" class="m-nav__link">
                                        <i class="m-nav__link-icon flaticon-info"></i>
                                        <span class="m-nav__link-text">FAQ</span>
                                    </a>
                                </li>
                                <li class="m-nav__item">
                                    <a href="" class="m-nav__link">
                                        <i class="m-nav__link-icon flaticon-lifebuoy"></i>
                                        <span class="m-nav__link-text">Support</span>
                                    </a>
                                </li>
                                <li class="m-nav__separator m-nav__separator--fit">
                                </li>
                                <li class="m-nav__item">
                                    <a href="#" class="btn btn-outline-danger m-btn m-btn--pill m-btn--wide btn-sm">Logout</a>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>
            </div>
        </div>

Similar dropdown classes used in the top navigation bar (i.e. notifications uses a dropdown element) so relevant js is included/works in the top menu but not in the view body?

Hi guys,

I'm trying to use the Metronic Dropdowns as seen here: https://keenthemes.com/metronic/preview/?page=components/base/dropdown&demo=default

I've replicated the code as shown in the demo but the dropdown functionality isn't working, which will be js driven? There seems to be a js file used in the demo site, dropdown.js, that whilst present in .net zeros source files, isn't included in the views?

Do I need to include the file in a js bundle, and if so, how do I do this, or do I need to do something else to include dropdown.js?

Thanks,

David

Here is the stack trace info in question:

{System.NullReferenceException: Object reference not set to an instance of an object. at Syntaq.Falcon.Documents.DocumentsAppService.Automate(Object JSONObject) in D:\Source\Syntaq.Falcon\src\Syntaq.Falcon.Application\Documents\DocumentsAppService.cs:line 88}

The null object is the _unitOfWorkManager.Current.

Line 88 is marked below:

84: using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew))
85:                {
86:                    NewRecord = _recordRepository.Get(Guid.Parse(RecordID));
87:                    await CreateOrEditRecord(NewRecord);
88:                    await _unitOfWorkManager.Current.SaveChangesAsync();

Hi Aaron

Thanks for the clarification around async awaiting.

Here is the code we're currently trying to execute our functions from within:

using (var uow = _unitOfWorkManager.Begin(TransactionScopeOption.RequiresNew))
                {
                    NewRecord = _recordRepository.Get(Guid.Parse(RecordID));
                    await CreateOrEditRecord(NewRecord);
                    await _unitOfWorkManager.Current.SaveChangesAsync();

                    NewRecordMatter = _recordMatterRepository.Get(Guid.Parse(RecordMatterID));
                    await CreateOrEditRecordMatter(NewRecordMatter);
                    await _unitOfWorkManager.Current.SaveChangesAsync();

                    await uow.CompleteAsync();
                }

Here is one of the functions sets that get called. Each of the function sets follows the same pattern as this one.

public async Task CreateOrEditRecord(Record Record)
        {
            if (Record.Id == null || !_recordRepository.GetAll().Any(i => i.Id == Record.Id))
            {
                await CreateRecord(Record);
            }
            else
            {
                await UpdateRecord(Record);
            }
        }

        [AbpAuthorize(AppPermissions.Pages_Records_Create)]
        private async Task CreateRecord(Record Record)
        {
            await _recordRepository.InsertAsync(Record);
        }

        [AbpAuthorize(AppPermissions.Pages_Records_Edit)]
        private async Task UpdateRecord(Record Record)
        {
            var record = await _recordRepository.FirstOrDefaultAsync((Guid)Record.Id);
            ObjectMapper.Map(Record, record);
        }

The current UOW seems to get closed when returning from CreateOrEditRecord(), which disrupts the subsequent actions shown in the top code block.

Showing 31 to 40 of 48 entries