How to use UserOrganizationRight method in argos

Best JavaScript code snippet using argos

GitHubSynchronizer.js

Source:GitHubSynchronizer.js Github

copy

Full Screen

1import GitHubAPI from 'github'2import config from 'config'3import Organization from 'server/models/Organization'4import Repository from 'server/models/Repository'5import User from 'server/models/User'6import UserOrganizationRight from 'server/models/UserOrganizationRight'7import UserRepositoryRight from 'server/models/UserRepositoryRight'8const OWNER_ORGANIZATION = 'Organization'9const OWNER_USER = 'User'10class GitHubSynchronizer {11 constructor(synchronization) {12 this.synchronization = synchronization13 this.github = new GitHubAPI({ debug: config.get('env') === 'development' })14 this.repositories = []15 this.organizationIds = []16 }17 async synchronizeRepositories({ page = 1 } = {}) {18 const githubRepositories = await this.github.repos.getAll({ page, per_page: 100 })19 const [20 { owners: organizations, ownerIdByRepositoryId: organizationIdByRepositoryId },21 { ownerIdByRepositoryId: userIdByRepositoryId },22 ] = await Promise.all([23 this.synchronizeOwners(githubRepositories, OWNER_ORGANIZATION),24 this.synchronizeOwners(githubRepositories, OWNER_USER),25 ])26 const repositories = await Promise.all(27 githubRepositories.data.map(async githubRepository => {28 const data = {29 githubId: githubRepository.id,30 name: githubRepository.name,31 organizationId: organizationIdByRepositoryId[githubRepository.id],32 userId: userIdByRepositoryId[githubRepository.id],33 private: githubRepository.private,34 }35 let [repository] = await Repository.query().where({ githubId: githubRepository.id })36 if (repository) {37 await repository.$query().patchAndFetch(data)38 } else {39 repository = await Repository.query().insert({40 ...data,41 baselineBranch: 'master',42 enabled: false,43 })44 }45 return repository46 })47 )48 if (this.github.hasNextPage(githubRepositories)) {49 const nextPageData = await this.synchronizeRepositories({ page: page + 1 })50 nextPageData.repositories.forEach(repository => {51 if (!repositories.find(({ id }) => id === repository.id)) {52 repositories.push(repository)53 }54 })55 nextPageData.organizations.forEach(organization => {56 if (!organizations.find(({ id }) => id === organization.id)) {57 organizations.push(organization)58 }59 })60 }61 return { repositories, organizations }62 }63 async synchronizeOwners(githubRepositories, type) {64 const githubOwners = githubRepositories.data.reduce((githubOwners, githubRepository) => {65 if (githubRepository.owner.type !== type) {66 return githubOwners67 }68 let githubOwner = githubOwners.find(({ id }) => id === githubRepository.owner.id)69 if (!githubOwner) {70 githubOwner = githubRepository.owner71 githubOwners.push(githubRepository.owner)72 }73 return githubOwners74 }, [])75 let owners76 switch (type) {77 case OWNER_ORGANIZATION:78 owners = await Promise.all(79 githubOwners.map(githubOwner => this.synchronizeOrganization(githubOwner))80 )81 break82 case OWNER_USER:83 owners = await Promise.all(84 githubOwners.map(githubOwner => this.synchronizeUser(githubOwner))85 )86 break87 default:88 throw new Error(`Unsupported type ${type}`)89 }90 return {91 owners,92 ownerIdByRepositoryId: githubRepositories.data.reduce(93 (ownerIdByRepositoryId, githubRepository) => {94 if (githubRepository.owner.type === type) {95 ownerIdByRepositoryId[githubRepository.id] = owners.find(96 owner => owner.githubId === githubRepository.owner.id97 ).id98 }99 return ownerIdByRepositoryId100 },101 {}102 ),103 }104 }105 // eslint-disable-next-line class-methods-use-this106 async synchronizeOrganization(githubOrganization) {107 const organizationData = await this.github.orgs.get({ org: githubOrganization.login })108 githubOrganization = organizationData.data109 let [organization] = await Organization.query().where({ githubId: githubOrganization.id })110 const data = {111 githubId: githubOrganization.id,112 name: githubOrganization.name,113 login: githubOrganization.login,114 }115 if (organization) {116 await organization.$query().patchAndFetch(data)117 } else {118 organization = await Organization.query().insert(data)119 }120 return organization121 }122 // eslint-disable-next-line class-methods-use-this123 async synchronizeUser(githubUser) {124 const data = { githubId: githubUser.id, login: githubUser.login }125 let user = await User.query()126 .where({ githubId: githubUser.id })127 .limit(1)128 .first()129 if (user) {130 await user.$query().patchAndFetch(data)131 } else {132 user = await User.query().insert(data)133 }134 return user135 }136 async synchronizeRepositoryRights(repositories) {137 const userRepositoryRights = await UserRepositoryRight.query().where({138 userId: this.synchronization.user.id,139 })140 await Promise.all(141 repositories.map(async repository => {142 const hasRights = userRepositoryRights.some(143 ({ repositoryId }) => repositoryId === repository.id144 )145 if (!hasRights) {146 await UserRepositoryRight.query().insert({147 userId: this.synchronization.user.id,148 repositoryId: repository.id,149 })150 }151 })152 )153 await Promise.all(154 userRepositoryRights.map(async userRepositoryRight => {155 const repositoryStillExists = repositories.find(156 ({ id }) => id === userRepositoryRight.repositoryId157 )158 if (!repositoryStillExists) {159 await userRepositoryRight.$query().delete()160 }161 })162 )163 }164 async synchronizeOrganizationRights(organizations) {165 const userOrganizationRights = await UserOrganizationRight.query().where({166 userId: this.synchronization.user.id,167 })168 await Promise.all(169 organizations.map(async organization => {170 const hasRights = userOrganizationRights.some(171 ({ organizationId }) => organizationId === organization.id172 )173 if (!hasRights) {174 await UserOrganizationRight.query().insert({175 userId: this.synchronization.user.id,176 organizationId: organization.id,177 })178 }179 })180 )181 await Promise.all(182 userOrganizationRights.map(async userOrganizationRight => {183 const organizationStillExists = organizations.find(184 ({ id }) => id === userOrganizationRight.organizationId185 )186 if (!organizationStillExists) {187 await userOrganizationRight.$query().delete()188 }189 })190 )191 }192 async synchronize() {193 this.synchronization = await this.synchronization.$query().eager('user')194 this.github.authenticate({195 type: 'oauth',196 token: this.synchronization.user.accessToken,197 })198 await this.synchronization.$relatedQuery('user')199 const { repositories, organizations } = await this.synchronizeRepositories()200 await this.synchronizeRepositoryRights(repositories)201 await this.synchronizeOrganizationRights(organizations)202 }203}...

Full Screen

Full Screen

Organization.js

Source:Organization.js Github

copy

Full Screen

1import { OWNER_TYPES } from 'constants'2import { BaseModel, mergeSchemas } from './util'3import { UserOrganizationRight } from './UserOrganizationRight'4export class Organization extends BaseModel {5 static tableName = 'organizations'6 static jsonSchema = mergeSchemas(BaseModel.jsonSchema, {7 required: ['githubId', 'login'],8 properties: {9 githubId: { type: 'number' },10 name: { type: ['string', null] },11 login: { type: 'string' },12 },13 })14 static relationMappings = {15 repositories: {16 relation: BaseModel.HasManyRelation,17 modelClass: 'Repository',18 join: {19 from: 'organizations.id',20 to: 'repositories.organizationId',21 },22 },23 relatedRepositories: {24 relation: BaseModel.ManyToManyRelation,25 modelClass: 'Repository',26 join: {27 from: 'organizations.id',28 through: {29 from: 'organization_repository_rights.organizationId',30 to: 'organization_repository_rights.repositoryId',31 },32 to: 'repositories.id',33 },34 },35 }36 type() {37 return OWNER_TYPES.organization38 }39 async $checkWritePermission(user) {40 return Organization.checkWritePermission(this, user)41 }42 static async checkWritePermission(owner, user) {43 if (!user) return false44 const userOrganizationRight = await UserOrganizationRight.query()45 .where({ userId: user.id, organizationId: owner.id })46 .first()47 return Boolean(userOrganizationRight)48 }...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1var argos = require('argos-sdk');2var userOrganizationRight = new argos.UserOrganizationRight();3userOrganizationRight.getOrganizationRights('username', 'organizationId', function(err, data) {4 if (err) {5 console.log(err);6 } else {7 console.log(data);8 }9});10var argos = require('argos-sdk');11var userOrganizationRight = new argos.UserOrganizationRight();12userOrganizationRight.getUserRights('username', 'organizationId', function(err, data) {13 if (err) {14 console.log(err);15 } else {16 console.log(data);17 }18});19var argos = require('argos-sdk');20var userOrganizationRight = new argos.UserOrganizationRight();21userOrganizationRight.getRights('organizationId', function(err, data) {22 if (err) {23 console.log(err);24 } else {25 console.log(data);26 }27});28var argos = require('argos-sdk');29var userOrganizationRight = new argos.UserOrganizationRight();30userOrganizationRight.getRights('organizationId', function(err, data) {31 if (err) {32 console.log(err);33 } else {34 console.log(data);35 }36});37var argos = require('argos-sdk');38var userOrganizationRight = new argos.UserOrganizationRight();39userOrganizationRight.getRights('organizationId', function(err, data) {40 if (err) {41 console.log(err);42 } else {43 console.log(data);44 }45});

Full Screen

Using AI Code Generation

copy

Full Screen

1var UserOrganizationRight = require('argos-sdk/src/UserOrganizationRight');2var right = new UserOrganizationRight();3var UserOrganizationRight = require('argos-sdk/src/UserOrganizationRight');4var right = new UserOrganizationRight();5var UserOrganizationRight = require('argos-sdk/src/UserOrganizationRight');6var right = new UserOrganizationRight();7var UserOrganizationRight = require('argos-sdk/src/UserOrganizationRight');8var right = new UserOrganizationRight();9var UserOrganizationRight = require('argos-sdk/src/UserOrganizationRight');10var right = new UserOrganizationRight();11var UserOrganizationRight = require('argos-sdk/src/UserOrganizationRight');12var right = new UserOrganizationRight();13var UserOrganizationRight = require('argos-sdk/src/UserOrganizationRight');14var right = new UserOrganizationRight();15var UserOrganizationRight = require('argos-sdk/src/UserOrganizationRight');16var right = new UserOrganizationRight();17var UserOrganizationRight = require('argos-sdk/src/UserOrganizationRight');18var right = new UserOrganizationRight();19var UserOrganizationRight = require('argos-sdk/src

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run argos automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful